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
echo “Starting script blah ”
blah -option x >> /dev/null 2>&1
echo “Stopping script blah”
for die in `ps aux| grep “blah -option” | grep -v grep | awk ‘{print $2}’`
kill ${die}
echo “Usage: /etc/init.d/blah {start|stop}”
exit 1

exit 0



~ 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: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: