When extensions contain daemons, it is helpful to provide an init script to allow the user to start and stop it. /usr/local/etc/init.d/ is the standard location for extension startup script on TC. We have the start-stop-daemon in base to make it easy to start and stop processes. Below is an example of an init script to start and stop rpc.mountd:
#!/bin/sh
# Starts and stops rpc.mountd
#
case "$1" in
start)
start-stop-daemon --start --exec /usr/local/sbin/portmap -u `id -u`
start-stop-daemon --start --exec /usr/local/sbin/rpc.mountd
;;
stop)
start-stop-daemon --stop --exec /usr/local/sbin/rpc.mountd
;;
restart)
$0 stop
$0 start
;;
status)
if pidof -o %PPID rpc.mountd > /dev/null; then
echo "Running"
exit 0
else
echo "Not running"
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
Notice that as rpc.mountd depends on portmap already running, portmap is started by the start-stop-daemon in the rpc.mountd script. The start-stop-daemon does not force start a process, it simply echoes "portmap already running" if it has already been started. There are other ways to check for a pid and such, but start-stop-daemon makes it easy for most daemons. Also, the rpc.mountd script does not stop portmap when the stop function is used since portmap may be needed by other processes.
It is my personal preference not to start processes in the /usr/local/tce.installed startup script as I don't believe that is where daemons should be started. But a call to the init.d script can be put in the tce.installed script if the extension maker feels it is absolutely necessary to have that daemon running at all times unless the user feels the need to stop it. Since init.d scripts can start dependent processes, and most distros use that approach, there really should not be a need to start a daemon in the tce.installed script in my opinion. But the support for it is there if needed with the order of execution of startup scripts.
There is no push to remake extensions that use another method to fit this method, this approach can be seamlessly worked in as extensions are updated.
As always, any ideas or suggestions are welcome.
A pid approach would be like below:
#!/bin/sh
# Starts and stops rpc.mountd
#
case "$1" in
start)
if ! pidof portmap >/dev/null; then
/usr/local/sbin/portmap -u `id -u`
echo "Starting portmap..."
else
echo "Portmap already running.."
fi
fi
if ! pidof rpc.mountd >/dev/null; then
/usr/local/sbin/rpc.mountd
echo "Starting rpc.mountd.."
else
echo "Rpc.mountd already running.."
fi
;;
stop)
if pidof rpc.mountd >/dev/null; then
killall -9 rpc.mountd >/dev/null
echo "Rpc.mountd stopped.."
else
echo "Rpc.mountd not running.."
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac