1

Trying to register a service in /etc/init.d, but cannot get it to run with service myservice start and at boot-up

Executable file:

#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
    set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi
### BEGIN INIT INFO
# Provides:          skeleton
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Example initscript
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.  This example start a
#                    single forking daemon capable of writing a pid
#                    file.  To get other behavoirs, implemend
#                    do_start(), do_stop() or other functions to
#                    override the defaults in /lib/init/init-d-script.
### END INIT INFO

# Author: Foo Bar <foobar@baz.org>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.

DESC="bel radio recording"
DAEMON=/usr/bin/streamripper

case "$1" in
start)  log_daemon_msg "Starting bel radio recording" "streamripper"
        sudo -u ubuntu /usr/bin/streamripper http://184.154.58.146:29378/ch18_56.mp3 --quiet -s -a -d ~ &

        ;;
stop)   log_daemon_msg "Stopping bel radio recording" "streamripper"
        pkill streamripper
        RETVAL=0

        log_end_msg $RETVAL
        ;;
restart) log_daemon_msg "Restarting bel radio recording" "streamripper"
        $0 stop
        $0 start
        ;;
*)

esac
exit 0

Trying to register this with

sudo update-rc.d recordbyradio defaults

and the command returns silently no matter how many times I run it

then

sudo service recordbyradio start 

also returns silently and doesn't start anything.

/etc/init.d/recordbyradio start

works fine however

Ubuntu version (running in EC2):

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.4 LTS
Release:        16.04
Codename:       xenial
axk
  • 111

2 Answers2

0

I don't see in your post: update-rc.d recordbyradio enable

Maybe the service isn't enabled and that's why it's not working.

Hatem Jaber
  • 326
  • 4
  • 12
0

The update-rc.d command should create symlinks for you:

  • /etc/rc0.d/K00recordbyradio
  • /etc/rc1.d/K00recordbyradio
  • /etc/rc2.d/S99recordbyradio
  • /etc/rc3.d/S99recordbyradio
  • /etc/rc4.d/S99recordbyradio
  • /etc/rc5.d/S99recordbyradio
  • /etc/rc6.d/K00recordbyradio

all of these should point to your script.

Your script also needs to be executable, so chmod +x /etc/init.d/recordbyradio.