How can this be done? I know it's pretty simple and includes appending something like &
or &>
to the actual command that starts the init script.
But, what is the best approach and how can it be ensured that the init script detaches itself, suppose the log file is /var/log/customDaemon.log ?
Here's the init script I have. I'm also not sure if the approach in the script is neat or just a nasty hack.
#!/bin/bash
#
# /etc/rc.d/init.d/customDaemon
#
# description: "The Daemon"
# processname: customDaemon
# pidfile: "/var/run/customDaemon.pid"
# Source function library.
. /etc/rc.d/init.d/functions
start() {
echo "Starting customDaemon"
/var/customDaemon &> /dev/null &
return 1
}
stop() {
echo "Stopping tweriod"
prockill customDaemon
return 2
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
restart
;;
status)
status customDaemon
;;
*)
echo "Usage: customDaemon [start|stop|restart|status]"
exit 1
;;
esac