3

I'm trying to turn Serviio into a service on Debian, to enable it to start at boot and to be controlled with the service command line utility.

I have a dedicated user, serviio, to run the daemon. I temporarily gave this user a shell and logged in to start the daemon as this user and confirm it works as it should, so it isn't an issue related to that.

This is the script I am using, in /etc/init.d/serviio. This script is from the serviio forums and everyone is reporting success with it for years now as recently as this month.

#!/bin/bash
#
#########################################################
#- Daemon script for Serviio media server
#- By Ian Laird; converted for Debian by Jacob Lundbergand edited by Jopie
#- /etc/init.d/serviio
#########################################################
#
### BEGIN INIT INFO
# Provides:          serviio
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Start/stop serviio media server
# Description:       The Serviio media server makes your media available to
#                    all kinds of networked devices.
### END INIT INFO


. /lib/lsb/init-functions

if [ -f /etc/default/serviio ]; then
        . /etc/default/serviio
fi


DAEMON_STOP=" -stop"
NAME="$(basename $0)"
PIDFILE="/tmp/serviiod.pid"
TIMEOUT=10

if [ -f /etc/default/serviio ]; then
        . /etc/default/serviio
fi

[ -x "$DAEMON" ] || exit 0


running() {
        if [ "x$1" == "x" ]; then
                echo 0
                return 1
        fi

        PS=$(ps h -p $(echo $1 | sed -r 's/[\t \n]+/ -p /') | wc -l)
        echo $PS

        if [ $PS -gt 0 ]; then
                return 0
        else
                return 1
        fi
}


start() {
        log_daemon_msg "Starting Serviio media server daemon" "$NAME"
        start-stop-daemon --start -q -b -p "$PIDFILE" -m -c "${SERVICE_ACCOUNT}" -x "${DAEMON}" start
        log_end_msg $?
}

stop() {
        log_daemon_msg "Stopping Serviio media server daemon" "$NAME"
        if [ -r "$PIDFILE" ]; then
                PIDS=$(pstree -p $(<"$PIDFILE") | awk -F'[\(\)]' '/^[A-Za-z0-9]/ { print $2" "$4; }')
                if running "$PIDS" > /dev/null; then
                        "${DAEMON}" "${DAEMON_STOP}"
                        for PID in $PIDS; do
                                if running $PID > /dev/null; then
                                        kill -TERM $PID
                                fi
                        done
                fi
                COUNTDOWN=$TIMEOUT
                while let COUNTDOWN--; do
                        if ! running "$PIDS" > /dev/null; then
                                break
                        fi
                        if [ $COUNTDOWN -eq 0 ]; then
                                for PID in $PIDS; do
                                        if running $PID > /dev/null; then
                                                kill -KILL $PID
                                        fi
                                done
                        else
                                echo -n .
                                sleep 1
                        fi
                done
        fi

        if running "$PIDS" > /dev/null; then
                log_end_msg 1
        else
                rm -f "$PIDFILE"
                log_end_msg $?
        fi
}

status() {
        echo -n "$NAME should be"
        if [ -r "$PIDFILE" ]; then
                echo -n " up with primary PID $(<"$PIDFILE")"
                PIDS=$(pstree -p $(<"$PIDFILE") | awk -F'[\(\)]' '/^[A-Za-z0-9]/ { print $2" "$4; }')
                RUNNING=$(running "$PIDS")
                if [[ $RUNNING && $RUNNING -gt 0 ]]; then
                        echo -n " and $RUNNING processes are running."
                else
                        echo -n " but it is not running."
                fi
        else
                echo -n " stopped."
        fi
        echo
}


case "${1:-}" in
        start)
                start
        ;;
        stop)
                stop
        ;;
        restart)
                stop
                start
        ;;
        status)
                status
        ;;
        *)
                log_success_msg "Usage: /etc/init.d/$NAME {start|stop|restart|status}"
                exit 1
        ;;
esac

exit 0

I also have in /etc/default/serviio

NAME="Serviio Media Server"
DAEMON="/opt/Serviio/bin/serviio.sh"    ## Update this to point at serviio_root/bin/serviio.sh
SERVICE_ACCOUNT="serviio" ## DON'T RUN UNDER ROOT!

I added the service to the system using the appropriate service commands.

However, whenever I try to start the service...systemd report it as starting successfully, but the daemon does not actually run. No error messages are report.

Running the script manually from /etc/init.d/serviio start also does not work.

How can I troubleshoot and fix this issue?

  • When you say "no error messages are report", are you looking in the serviio logs? Or the systemd logs? – Xiong Chiamiov Mar 18 '16 at 05:47
  • @XiongChiamiov both. Serviio isn't being called by the init.d script for some reason, and when it runs it runs fine. The init.d script doesn't seem to be aware that the script it is calling is failing, so isn't generating any messages to systemd. – Len Stepson Mar 18 '16 at 06:15
  • Try to add set -x somewhere to the top of the init script, and then try to start the service. This should give you some extended logging when you do; you can see the output with journalctl -u <init script name> -f. – Wouter Verhelst Aug 20 '18 at 09:44

0 Answers0