Re: Linux Daemon scripts
Hi, I already added as a StartUp Application, but if it's not root doesn't work...
:S
Cantello wrote:What exactly should I add in order to run kairoh's webUI together with serviio at system start on my Ununtu system? Currently I have the serviio daemon started via the scripts presented here but I have no clue on how to integrate the webUI. The wrapper is not supposed to be compatible with serviio as a service, which i what I'm using now so this probably won't work.
Any hints?
Thanks,
Helge.
Cerberus wrote:http://wiki.serviio.org/doku.php?id=howto:linux:install:ubuntu
#!/bin/bash
#
# serviio
#
# chkconfig: 235 99 10
#
# description: Serviio is a DNLA media server\
#    By Roger Beck - 2012
# processname: serviio.sh
#
### BEGIN INIT INFO
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Description: Start or stop the Serviio server
### END INIT INFO
version="0.6.2"
bin_path="/usr/local/serviio-$version/bin"
ui_bin="serviio-webui.sh"
start=$bin_path/serviio.sh
stop=$bin_path/stop
lockfile=/var/lock/subsys/serviio
name='Serviio'
start() {
        $start & >/dev/null 2>&1 </dev/null
        echo "Starting Serviio $version DNLA server"
        RETVAL=$?
        if [ "$RETVAL" = "0" ]; then
                touch $lockfile >/dev/null 2>&1
        fi
        if [ -e $bin_path/$ui_bin ] ; then
                echo "Starting Web-UI on port 8123"
                $bin_path/$ui_bin &
        fi
}
stop() {
        #$stop
        RETVAL=$?
        serv_kill=`ps aux | grep serviio.sh | grep -v grep | awk '{print $2}'`
        java_kill=`ps aux | grep java | grep -v grep | awk '{print $2}'`
        if [ "$serv_kill" = "" ]; then
                echo "Serviio is not running"
                RETVAL=1
        else
                kill $serv_kill
                RETVAL=0
        fi
        if [ "$java_kill" = "" ]; then
                echo "Java is not running"
                RETVAL=1
        else
                kill -9 $java_kill
                RETVAL=0
        fi
        # check is the WebUI wrapper is running
        ui_pid=`ps aux | grep $ui_bin | grep -v grep | awk '{print $2}'`
        if [ "$ui_pid" = "" ]; then
                echo "Serviio WebUI is not running"
        else
                kill $ui_pid
        fi
}
status() {
        serv_pid=`ps aux | grep serviio.sh | grep -v grep | awk '{print $2}'`
        java_pid=`ps aux | grep java | grep -v grep | awk '{print $2}'`
        if [ "$serv_pid" != "" ]; then
                echo "$name (pid $serv_pid) is running"
                RETVAL=0
        else
                echo "$name is stopped"
                RETVAL=1
        fi
        # check is the WebUI wrapper is running
        ui_pid=`ps aux | grep serviio-webui | grep -v grep | awk '{print $2}'`
        if [ "$ui_pid" = "" ]; then
                echo "Serviio WebUI is not running"
        else
                echo "WebUI (pid $ui_pid) is running"
        fi
}
restart() {
        stop
        start
        RETVAL=$?
}
case "$1" in
        start|stop|restart|status)
                $1
                ;;
        *)
                echo $"Usage: $0 {start|stop|status|restart}"
                exit 1
esac
exit $RETVAL
soundcheck wrote:If you guys can live with above we could/should add it to the Wiki. The "serviio" user generation and startup part is IMO missing anyhow.
#! /bin/sh
 #
 # /etc/init.d/serviio
 #
 #
 ### BEGIN INIT INFO
 # Provides: serviio
 # Required-Start: $network
 # Required-Stop: $network
 # Default-Start: 3 5
 # Default-Stop: 0 1 2 6
 # Description: Start the serviio DLNA server in headless mode
 ### END INIT INFO
 SERVIIO_HOME="/etc/serviio"
 SERVIIO_DAEMON="serviio.sh"
 SERVIIO_BIN="$SERVIIO_HOME/bin/$SERVIIO_DAEMON"
 SERVIIO_USER="root"
 # Source function library.
 . /lib/lsb/init-functions
 RETVAL=0
 check() {
         # Check that we're a privileged user
         [ $(id -u) = 0 ] || exit 4
         # Check if SERVIIO_HOME exists
         test -d "$SERVIIO_HOME" || exit 5
         # Check if SERVIIO_BIN is executable
         test -x "$SERVIIO_BIN" || exit 5
 }
 start() {
         check
         echo -n "Starting Serviio DLNA server: "
         /usr/bin/sudo -u $SERVIIO_USER -H $SERVIIO_BIN -headless &
         RETVAL=$?
         if [ $RETVAL -eq 0 ]; then
             touch /var/lock/serviio
             log_end_msg 0
         else
             log_end_msg 1
         fi
         echo
         return $RETVAL
 }
 stop() {
         check
         echo -n "Shutting down Serviio DLNA daemon: "
         killproc "$SERVIIO_BIN"
         RETVAL=$?
         [ $RETVAL -eq 0 ] && rm -f /var/lock/serviio
         echo
         return $RETVAL
 }
 restart() {
         stop
         start
 }
 case "$1" in
 start)
         start
         ;;
 stop)
         stop
         ;;
 force-reload)
         restart
         ;;
 restart)
         restart
         ;;
 condrestart)
         if [ -f /var/lock/serviio ]; then
             restart
         fi
         ;;
 status)
         status serviio.sh
         ;;
 *)
         echo $"Usage: $0 {start|stop|status|restart|condrestart|force-reload}"
         RETVAL=2
 esac
 exit $RETVAL
#!/bin/bash
#
#########################################################
#- Daemon Script Configuration for Serviio Media Server
#- By Ian Laird; converted for Debian by Jacob Lundberg
#- Updated and Merged for Ubuntu 14.04 by Matthew Bate
#########################################################
#
#########################################################
#
### 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/rcS ]; then
        . /etc/default/rcS
fi
NAME="Serviio Media Server"
DAEMON="/opt/Serviio/bin/serviio.sh"      ## Update this to point at pc5dczc_root/bin/serviio.sh
DAEMON_STOP=" -stop"
SERVICE_ACCOUNT="root"            ## DON'T RUN UNDER ROOT!
TIMEOUT=3
# We have this because start-stop-daemon needs one and wont start without it.  Although it provides wrong PID ID of Java Client.
PIDFILE="/var/run/serviiod.pid"         
if [ -f /etc/default/serviio ]; then
        . /etc/default/serviio
fi
[ -x "$DAEMON" ] || exit 0
#########################################################
#
#  Status function check not only the PID file but if it has gone missing it will look for the Java Client manually.
#
#########################################################
status() {
    if [ $1 = "PID" ]; then
   if [ ! -f $TPIDFILE ]; then
       PID=$(ps -ef | grep "org.serviio.MediaServer" | grep -v grep | awk "{ print \$2 }")
       echo $PID
   else 
       PID=$(cat $TPIDFILE)
          echo $PID
   fi
    else 
        PID=$(ps -ef | grep "org.serviio.MediaServer" | grep -v grep | awk "{ print \$2 }")
        if [[ -z $PID ]]; then
            if [ $1 = "status" ]; then log_daemon_msg "Serviio is currently offline."; else echo "0"; fi # Offline
        else
          if [ $1 = "status" ]; then log_daemon_msg "Serviio is currently online."; else echo "1"; fi # Online
        fi   
    fi
}
start() {
    RUNNING=$(status "0")
    if [ $RUNNING = "0" ]; then
   log_daemon_msg "Starting Serviio Media Server..."
   start-stop-daemon --start -q -b -p "$PIDFILE" -m -c "${SERVICE_ACCOUNT}" -x "${DAEMON}"
   log_end_msg $?
    else
   log_daemon_msg "Serviio Media Server is already running."
   log_end_msg 1
    fi
}
stop() {
    RUNNING=$(status "0")
    if [ ${#RUNNING} = "1" ]; then
   log_daemon_msg "Shutting Down Serviio Media Server..."
   ${DAEMON} ${DAEMON_STOP}
   log_end_msg $?
    else 
   log_daemon_msg "Serviio Media Server is already shutdown."
   log_end_msg 1
    fi
}
force_stop() {
    RUNNING=$(status "0")
    if [ ${#RUNNING} = "1" ]; then
   log_daemon_msg "Shutting Down Serviio Media Server..."
   RUNNING=$(status "PID")
   kill -TERM $RUNNING
   log_end_msg $?
    else 
   log_daemon_msg "Serviio Media Server is already shutdown."
   log_end_msg 1
    fi
}
case "${1:-}" in
        start)
                start
        ;;
        stop)
                stop
        ;;
        restart)
                stop
                start
        ;;
        status)
                status $1
        ;;
   force-stop)
      force_stop
   ;;
        *)
                log_success_msg "Usage: /etc/init.d/$NAME {start|stop|force-stop|restart|status}"
                exit 1
        ;;
esac
exit 0
#!upstart
# script will run only after network is up and my /media/nas mounted
start on (started networking and mounted MOUNTPOINT=/media/nas)
#optional stuff
description "Serviio Server Upstart Script"
# configuration variables
#user that will run the Serviio service
env USER=ale
#the folder that contains all my movies
env FOLDER=/media/nas/videos
#a file in the folder above
env FPID=.serviio.pid
#path to the serviio start script
env BIN=/path/to/your_serviio/bin/serviio.sh
# pre-start stanza
pre-start script
  # main process will not be run if /some/file does not exist
 # if the file defined above does not exist (folder not mounted) it will exit
  test -f $FOLDER/$FPID || { stop ; exit 0; }
end script
# normal script
script
   # Set up correct LANG // you might not need this
   if [ -r /etc/default/locale ]; then
       . /etc/default/locale
       export LANG LANGUAGE LC_MESSAGES LC_ALL LC_CTYPE
   fi
   
   #start the service
   exec start-stop-daemon --start --make-pidfile --pidfile /var/run/serviio.pid -c $USER --exec $BIN
end script
#!/bin/bash
# this is the file to check
FPID=/media/nas/videos/.serviio.pid
if [ ! -f $FPID ]
then
    echo "File not found: "$FPID
    service serviio stop
    echo "The system tried to stop Serviio service to keep the database unrefreshed at "$(date)" because "$FPID" was not available. You will need to restart the service manually, but first make sure that "$FPID" is available again." | mail -s "Serviio service stopped" you@yourmail.com
fi
#! /bin/sh
#
# chkconfig 35 85 15
# description: Start the serviio DLNA server in headless mode
### BEGIN INIT INFO
# Provides: serviio
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Description: Start the serviio DLNA server in headless mode
### END INIT INFO
SERVIIO_HOME="/opt/serviio"
SERVIIO_DAEMON="serviio.sh"
SERVIIO_BIN="$SERVIIO_HOME/bin/$SERVIIO_DAEMON"
SERVIIO_USER="serviio"
# Source function library.
. /etc/rc.d/init.d/functions
RETVAL=0
check() {
        # Check that we're a privileged user
        [ $(id -u) = 0 ] || exit 4
        # Check if SERVIIO_HOME exists
        test -d "$SERVIIO_HOME" || exit 5
        # Check if SERVIIO_BIN is executable
        test -x "$SERVIIO_BIN" || exit 5
}
start() {
        check
        echo -n "Starting Serviio DLNA server: "
   /bin/su --session-command="$SERVIIO_BIN -headless" $SERVIIO_USER &
        RETVAL=$?
        if [ $RETVAL -eq 0 ]; then
            touch /var/lock/subsys/serviio.sh
            echo_success
        else
            echo_failure
        fi
        echo
        return $RETVAL
}
stop() {
    check
    echo -n "Shutting down Serviio DLNA daemon: "
    # Retrieve JAVA Serviio process ID
    PIDDAEMON=`pgrep -f "/bin/su --session-command=$SERVIIO_BIN -headless"`
    [ -z "$PIDDAEMON" ] || PIDJAVA=`ps -o pid= --ppid $PIDDAEMON`
    # Kill the daemon
    kill "$PIDDAEMON"
    RETVAL=$?
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/serviio.sh
    echo
    # Kill the JAVA Serviio process if exists
    [ -z "$PIDJAVA" ] || kill -9 $PIDJAVA
    return $RETVAL
}
restart() {
        stop
        start
}
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
force-reload)
        restart
        ;;
restart)
        restart
        ;;
condrestart)
        if [ -f /var/lock/subsys/serviio.sh ]; then
            restart
        fi
        ;;
status)
        status serviio.sh
        ;;
*)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|force-reload}"
        RETVAL=2
esac
exit $RETVAL
Return to Third-party tools integration
Users browsing this forum: No registered users and 7 guests