I'm pretty new to writing systemd compatible init scripts. I've tried the following example:
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: test
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Test.
# Description: Test.
### END INIT INFO
#
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
case "$1" in
stop)
log_failure_msg "Stop!"
exit 1
;;
start)
log_failure_msg "Start!"
exit 1
;;
restart)
log_failure_msg "Restart!"
exit 1
;;
status)
log_failure_msg "Status!"
exit 1
;;
*)
echo "Usage: $SELF start|stop|restart|status"
exit 1
;;
esac
# Some success paths end up returning non-zero, so exit 0 explicitly. See bug #739846.
exit 0
So far, so good. Now, I install the init script like so:
update-rc.d test defaults
update-rc.d test enable
Again, so far, so good. I've setup this init script specifically to fail (I had to do so during my testing to confirm the issue I was having.)
If I run /etc/init.d/test start, it fails as expected, and I can see the error message in my log.
If, however, I run /etc/init.d/test stop, I get nothing in my log, and the script returns successfully.
It seems like systemd is doing some kind of black magic behind the scenes and is hijacking stop somehow, but I can't figure out how, and I've been Googling around forever without success. Can anyone help me to understand why passing stop to my init script doesn't execute the corresponding code in my case block?
As a side note, the status option also doesn't work (systemd just outputs its own status info.)
I'm attempting to run this on Ubuntu 16.04. Thank you!