Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Debian - Add Service
sudo vi /etc/init.d/cjp
sudo chmod +x /etc/init.d/cjp
#if you want it to run at startup
sudo update-rc.d cjp defaults
#to remove
sudo update-rc.d -f cjp remove
#start and stop at will
sudo service cjp start
suod service cjp stop
example:
#!/bin/sh
### BEGIN INIT INFO
# Provides: CJP
# Required-Start: $time $network $remote_fs $syslog $all $redis-server
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Magnatize Highmem initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
# Carry out specific functions when asked to by the system
case "$1" in
start)
date >> /home/chris/out.txt
echo "Starting script cjp" >> /home/chris/out.txt
/usr/local/bin/resque-web --app-dir /home/chris/tmp/ --redis 10.240.185.245 2>&1 >> /home/chris/out.txt
/usr/local/bin/rake --rakefile /home/chris/tweetstream/examples/Rakefile crunch_it 2>&1 & >> /home/chris/out.txt
/usr/local/bin/rake --rakefile /home/chris/tweetstream/examples/Rakefile resque:work QUEUE=tweets_to_scrape 2>&1 & >> /home/chris/out.txt
;;
stop)
echo "Stopping script cjp" >> /home/chris/out.txt
/usr/local/bin/resque-web --app-dir /home/chris/tmp --kill
kill `ps ax | grep crunch_it | grep -v 'grep' | cut -f 2 -d ' ' -s` 2>&1 >> /home/chris/out.txt
kill `ps ax | grep tweets_to_scrape | grep -v 'grep' | cut -f 2 -d ' ' -s` 2>&1 >> /home/chris/out.txt
;;
*)
echo "Usage: /etc/init.d/blah {start|stop}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment