Content-type: text/html; charset=UTF-8
This is a simple example on how init-d-script can be used to start and stop a daemon with PID file support:
#!/bin/sh /lib/init/init-d-script ### BEGIN INIT INFO # Provides: atd # Required-Start: $syslog $time $remote_fs # Required-Stop: $syslog $time $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: run at jobs # Description: Debian init script to start the daemon # running at jobs. ### END INIT INFO DAEMON=/usr/sbin/atd
The following variables affect behaviour of an init script:
The variables RELOAD_ARGS START_ARGS and STOP_ARGS are additional arguments, passed to start-stop-daemon8 during reload, start and stop actions, to override the default options.
Additionally, it is possible to change the behaviour of the resulting shell script by overriding some of the internal functions. To do so, define function with an _override suffix. So, for example, to override the Fn do_status function, one should define a Fn do_status_override function. The exception to this rule is the Fn do_reload function, whose override should be defined as-is, without the above-mentioned suffix.
Here is a control flow chart that explains what functions are called and when:
/etc/init.d/script start
do_start
do_start_prepare # no-op
do_start_cmd # start-stop-daemon is called here
do_start_cleanup # no-op
/etc/init.d/script stop
do_stop
do_stop_prepare # no-op
do_stop_cmd # start-stop-daemon is called here
do_stop_cleanup # no-op
/etc/init.d/script status
do_status
/etc/init.d/script reload
do_reload
do_usage
exit 3
/etc/init.d/script force-reload
do_force_reload
do_reload # if overridden
do_restart
do_restart_prepare
do_stop_cmd
do_start_cmd
do_restart_cleanup
/etc/init.d/script restart
do_force_restart
/etc/init.d/script try-restart
if do_status; then
do_restart
do_restart_prepare
do_stop_cmd # start-stop-daemon is called here
do_start_cmd # start-stop-daemon is called here
do_restart_cleanup
/etc/init.d/script <arg>
do_unknown <arg>
exit 3
/etc/init.d/script
do_usage
As can be seen, by default, the script does not support the reload action; it should be implemented by the script writer by defining a Fn do_reload function.
If Fn do_reload is not defined but Fn do_reload_cmd is, the latter will be called on reload after Fn do_reload_prepare and before Fn do_reload_cleanup .