I have this init.d
script (/etc/init.d/ctrlme
):
#!/lib/init/init-d-script
### BEGIN INIT INFO
# Provides: ctrlme
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: ctrlme
# Description: ctrlme
### END INIT INFO
# sudo cp -v /home/gigikent/bin/init.d-services/ctrlme /etc/init.d/; sudo chown root: /etc/init.d/ctrlme
#
# https://www.pks.mpg.de/~mueller/docs/suse10.1/suselinux-manual_en/manual/sec.boot.init.html
#
NAME=ctrlme
PIDFILE=/run/ctrlme.pid
DAEMON=/bin/bash -c '/home/gigikent/x.sh ctrlme'
DESC=ctrlme
# . /lib/lsb/init-functions
#
# case "$1" in
# start)
# /home/gigikent/x.sh ctrlme
# ;;
# stop|restart|force-reload)
# exit 0
# ;;
# *) echo "Usage: $0 {start|stop|restart|force-reload}" >&2; exit 1 ;;
# esac
which when started fails with:
Jun 16 18:57:13 gigikent.go.ro ctrlme[28454]: /lib/init/init-d-script: 20: /etc/init.d/ctrlme: -c: not found
Jun 16 18:57:13 gigikent.go.ro systemd[1]: ctrlme.service: Succeeded.
-- Subject: Unit succeeded
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit ctrlme.service has successfully entered the 'dead' state.
Running /bin/bash -c '/home/gigikent/x.sh ctrlme'
command works as expected.
Why this happens and how should I solve the problem?
System info:
Ubuntu 19.04
DAEMON="/bin/bash -c '/home/adr/x.sh ctrlme'"
– Jun 16 '19 at 16:37x.sh
script is running fine when executed directly. When using DAEMON="..." I getbasename: extra operand ‘'/home/adr/x.sh’
. – Adrian Jun 16 '19 at 17:55executed directly
you are using a bash shell:/bin/bash -c '/home/adr/x.sh ctrlme'
but the shell-bang (Please use shellcheck to confirm) is invalid, or (at least) doesn't set the shell to bash. – Jun 16 '19 at 18:12sudo grep -nr '#!/lib/init/init-d-script' /etc/init.d
yields/etc/init.d/whoopsie:1:#!/lib/init/init-d-script
– Adrian Jun 16 '19 at 18:14init-d-script
is not a shell. I invite you to learn the basics. – Jun 16 '19 at 22:22/home/adr/x.sh ctrlme
– Jun 16 '19 at 22:25/home/adr/x.sh ctrlme
works as expected; be aware thatx.sh
starts with#!/bin/bash
. I again mention that running/bin/bash -c '/home/adr/x.sh ctrlme'
also works as expected. I agree#!/lib/init/init-d-script
(used by/etc/init.d/ctrlme
) is odd but on the other hand seems to function well. – Adrian Jun 17 '19 at 11:11man init-d-script
, yes the script can be used as an interpreter. “init-d-script - interpreter for short and simple init.d scripts. … This is a simple example on how init-d-script can be used to start and stop a daemon with PID file support:#!/lib/init/init-d-script
…” – ctrl-alt-delor Jun 17 '19 at 23:06