starting a program as a deamon

first you need to add a script like below into /etc/init.d/ and “chmod 755 /etc/init.d/name”>. than to add the script to your runlevel will be on a debian system with “update-rc.d <scriptname in /etc/init.d/> defaults”. the script starts (invoke-rc.d [start|stop]) with the option start the binary and with stop, it searches for the specific pid to kill it afterwards again, maybe you need to customize it a bit.

#! /bin/sh
# /etc/init.d/blah
# Some things that run always
touch /var/lock/blah

# Carry out specific functions when asked to by the system
case “$1” in
start)
echo “Starting script blah ”
blah -option x >> /dev/null 2>&1
;;
stop)
echo “Stopping script blah”
for die in `ps aux| grep “blah -option” | grep -v grep | awk ‘{print $2}’`
do
kill ${die}
done
;;
*)
echo “Usage: /etc/init.d/blah {start|stop}”
exit 1
;;
esac

exit 0

sources:

http://www.debian-administration.org/articles/28
http://www.unix.com/unix-dummies-questions-answers/1546-how-kill-process-get-process-id.html

Advertisements

~ by frankooh on 2011-02-10T20:55:51+00:00.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: