Typically you would put the daemon somewhere like /sbin. Then you have a script to launch it in /etc/rc.d/init.d. In the launcher script you will source the functions file and that way you just make a function call to launch your daemon. You can find templates for a launcher script with most distros, it might be called skeleton. Here is what a typical launcher script might look like, you will probably need to tweek it some.
NOTE: The functions
status daemon and
killproc are loaded from the /etc/rc.d/init.d/functions script.
Code:
#!/bin/bash
#
# Init file for mydaemon
#
#
# Run-Level Start Stop
# vvvv vv vv
# chkconfig: 2345 99 25
#
# description: My daemon
#
# processname: mydaemon
# config: /etc/mydaemon.conf
# pidfile: /var/run/mydaemon.pid
# source function library
. /etc/rc.d/init.d/functions
# you may keep some variables in an external file
# for easy access so pull in sysconfig settings
[ -f /etc/sysconfig/mydaemon ] && . /etc/sysconfig/mydaemon
# Some more variables to make the script readable
MYDAEMON=/sbin/mydaemon
PID_FILE=/var/run/mydaemon.pid
RETVAL=0
prog="mydaemon"
start()
{
echo -n $"Starting $prog:"
daemon $MYDAEMON && success || failure
RETVAL=$?
[ "$RETVAL" = 0 ] && touch /var/lock/subsys/mydaemon
echo
}
stop()
{
echo -n $"Stopping $prog:"
killproc $MYDAEMON -TERM
RETVAL=$?
[ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/mydaemon
echo
}
reload()
{
echo -n $"Reloading $prog:"
killproc $MYDAEMON -HUP
RETVAL=$?
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
reload
;;
status)
status $MYDAEMON
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
RETVAL=1
esac
exit $RETVAL
To make the launcher script run each time you boot do this:
chkconfig add mydaemon
HTH