An explanation and a solution.
The explanation. Normally the program that is invoked in your rc startup file has the ability to "daemonize" itself.
That's like nohup'ing and &'ing itself.
The solution. In your rc file add the 'nohup' and the '&' to what you are starting. Not the most sophisticated approach, but it works.
Here is an example called /etc/rc./init.d/test that starts 'mycommand'. You'd add it with 'chkconfig --add test'; 'chkconfig test on'; and could manually start it with 'service test start'.
Code:
#!/bin/bash
#
# test Send an email, start or stop 'mycommand'
#
# chkconfig: - 90 10
# description: Just send an email when runlevel changes
#
HOST=`hostname`
MAIL="/bin/mailx"
RMAIL="me@mysite.com"
case "$1" in
'start')
[ -f /var/lock/subsys/test ] \
&& echo "test appears started"
${MAIL} -s "test starting on ${HOST}" ${RMAIL} < /dev/null >/dev/null 2>&1
touch /var/lock/subsys/test
nohup /full/path/to/mycommand 2>&1 >>/home/me/mycommand/nohup.out &
;;
'stop')
[ -f /var/lock/subsys/test ] \
|| echo "test appears already stopped"
${MAIL} -s "test stopping on ${HOST}" ${RMAIL} < /dev/null >/dev/null 2>&1
/bin/rm -f /var/lock/subsys/test
killall -s9 mycommand
;;
*)
echo "Usage: $0 { start | stop }"
exit 1
;;
esac
exit 0