FAQ  •  Register  •  Login

Linux Daemon scripts

<<

irlaird

Serviio newbie

Posts: 5

Joined: Thu Dec 10, 2009 5:21 pm

Post Thu Dec 10, 2009 5:43 pm

Linux Daemon scripts

Serviio Daemon Start/Stop script/Conf for Linux
Im sure someone has already done this but i didnt see it on the forums so i thought i would help out the next guy.

NOTE:
Make sure you update DAEMON="/bin/serviio" to point to the serviio.sh start script. I made sym link to it but it requires more modifications. :D


File: /etc/conf.d/serviiod
  Code:
#########################################################
#- Daemon Script Configuration for Serviio Media Server
#- By Ian Laird
#- /etc/conf.d/serviiod
#########################################################

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



File: /etc/init.d/serviiod
  Code:
#!/sbin/runscript

#########################################################
#- Daemon script for Serviio media server
#- By Ian Laird
#- /etc/init.d/serviiod
#########################################################

PIDFILE="/var/run/serviiod.pid"
DAEMON_STOP=" -stop"

[ -x $DAEMON ] || exit 0

start() {
        ebegin "Starting $NAME"
        start-stop-daemon --start -q -b -p $PIDFILE -m -c ${SERVICE_ACCOUNT} -x ${DAEMON}
        eend $?
}

stop() {
        ebegin "Stopping $NAME"
        ${DAEMON} -stop
        start-stop-daemon --stop -p $PIDFILE
        eend $?
}
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Thu Dec 10, 2009 6:15 pm

Re: Linux Daemon scripts

Cool, I'll probably copy this into FAQ or something.
<<

Qkxy

Serviio newbie

Posts: 10

Joined: Sun Nov 29, 2009 12:57 pm

Post Fri Dec 11, 2009 7:59 pm

Re: Linux Daemon scripts

Hi!
I made this script for serviio 0.2 on OpenSuSE 11.2:

/etc/init.d/serviio
  Code:
#! /bin/sh
# Copyright (c) 2009 Zoltan Kukk
#
# Author: zoltan.kukk@gmail.com
#
# /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_BIN=/usr/bin/serviio
test -x $SERVIIO_BIN || { echo "$SERVIIO_BIN not installed";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }

# Load the rc.status script for this service.
. /etc/rc.status

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status

# First reset status of this service
rc_reset

case "$1" in
    start)
   echo -n "Starting Serviio DLNA server"
   ## Start daemon with startproc(8). If this fails
   ## the echo return value is set appropriate.

   startproc -f -u nobody -g video -l /var/log/serviio.log $SERVIIO_BIN -headless
   # Remember status and be verbose
   rc_status -v
   ;;
    start-gui)
        echo -n "Starting Serviio DLNA server"
        ## Start daemon with startproc(8). If this fails
        ## the echo return value is set appropriate.

        startproc -f -u nobody -g video -l /var/log/serviio.log $SERVIIO_BIN
        # Remember status and be verbose
        rc_status -v
        ;;
    stop)
   echo -n "Shutting down Serviio DLNA daemon"
   ## Stop daemon with killproc(8) and if this fails
   ## set echo the echo return value.

   startproc -f -u nobody -g video -l /var/log/serviio.log $SERVIIO_BIN -stop

   # Remember status and be verbose
   rc_status -v
   ;;
    try-restart)
        ## Stop the service and if this succeeds (i.e. the
        ## service was running before), start it again.
        $0 status >/dev/null &&  $0 restart

        # Remember status and be quiet
        rc_status
        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start

        # Remember status and be quiet
        rc_status
        ;;
    force-reload|reload)
   ## Signal the daemon to reload its config. Most daemons
   ## do this on signal 1 (SIGHUP).

   echo -n "Reload Serviio DLNA server"
        rc_failed 3
        rc_status -v
        ;;
    status)
   echo -n "Checking for service serviio "
        ## Check status with checkproc(8), if process is running
        ## checkproc will return with exit status 0.

        # Status has a slightly different for the status command:
        # 0 - service running
        # 1 - service dead, but /var/run/  pid  file exists
        # 2 - service dead, but /var/lock/ lock file exists
        # 3 - service not running

        # NOTE: checkproc returns LSB compliant status values.
        checkproc $SERVIIO_BIN
        # NOTE: rc_status knows that we called this init script with
        # "status" option and adapts its messages accordingly.
        rc_status -v
   ;;
    probe)
   ## Optional: Probe for the necessity of a reload,
   ## give out the argument which is required for a reload.

   ;;
    *)
   echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
   exit 1
   ;;
esac
rc_exit


Set Serviio owner (My video files owned by video group):
chown -R nobody:video /path_to_serviio_root

Symlinks:
ln -s /path_to_serviio_root/bin/serviio.sh /usr/bin/serviio
ln -s /etc/init.d/serviio /sbin/rcserviio

Set up running on default runlevel:
/sbin/insserv /etc/init.d/serviio
Samsung LE40B650T2W - SQ04 - 2009/09/30_002005
OpenSuSE 11.2
Serviio 0.3
<<

NX3

DLNA master

Posts: 578

Joined: Fri Jan 28, 2011 12:39 pm

Post Fri Jan 28, 2011 12:49 pm

Re: Linux Daemon scripts

For anyone on Ubuntu 10.10 you won't find /etc/conf.d/ on your system. However to get Serviio to start automatically is really easy as under the administration menu you'll find 'Startup Applications'. Select that and then just add the scripts files, you can browse to where ever you saved them. Next time you reboot Serviio just starts :-D
<<

jopiexjoker

Serviio newbie

Posts: 9

Joined: Sun Jan 30, 2011 11:11 am

Post Tue Feb 01, 2011 6:50 pm

Re: Linux Daemon scripts

NX3 wrote:For anyone on Ubuntu 10.10 you won't find /etc/conf.d/ on your system. However to get Serviio to start automatically is really easy as under the administration menu you'll find 'Startup Applications'. Select that and then just add the scripts files, you can browse to where ever you saved them. Next time you reboot Serviio just starts :-D


It starts before log in?
<<

Cerberus

User avatar

DLNA master

Posts: 4114

Joined: Sun Jan 02, 2011 5:20 pm

Location: Reading, UK

Post Tue Feb 01, 2011 7:40 pm

Re: Linux Daemon scripts

Qkxy wrote:Hi!
I made this script for serviio 0.2 on OpenSuSE 11.2:

/etc/init.d/serviio
  Code:
#! /bin/sh
# Copyright (c) 2009 Zoltan Kukk
#
# Author: zoltan.kukk@gmail.com
#
# /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_BIN=/usr/bin/serviio
test -x $SERVIIO_BIN || { echo "$SERVIIO_BIN not installed";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }

# Load the rc.status script for this service.
. /etc/rc.status

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status

# First reset status of this service
rc_reset

case "$1" in
    start)
   echo -n "Starting Serviio DLNA server"
   ## Start daemon with startproc(8). If this fails
   ## the echo return value is set appropriate.

   startproc -f -u nobody -g video -l /var/log/serviio.log $SERVIIO_BIN -headless
   # Remember status and be verbose
   rc_status -v
   ;;
    start-gui)
        echo -n "Starting Serviio DLNA server"
        ## Start daemon with startproc(8). If this fails
        ## the echo return value is set appropriate.

        startproc -f -u nobody -g video -l /var/log/serviio.log $SERVIIO_BIN
        # Remember status and be verbose
        rc_status -v
        ;;
    stop)
   echo -n "Shutting down Serviio DLNA daemon"
   ## Stop daemon with killproc(8) and if this fails
   ## set echo the echo return value.

   startproc -f -u nobody -g video -l /var/log/serviio.log $SERVIIO_BIN -stop

   # Remember status and be verbose
   rc_status -v
   ;;
    try-restart)
        ## Stop the service and if this succeeds (i.e. the
        ## service was running before), start it again.
        $0 status >/dev/null &&  $0 restart

        # Remember status and be quiet
        rc_status
        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start

        # Remember status and be quiet
        rc_status
        ;;
    force-reload|reload)
   ## Signal the daemon to reload its config. Most daemons
   ## do this on signal 1 (SIGHUP).

   echo -n "Reload Serviio DLNA server"
        rc_failed 3
        rc_status -v
        ;;
    status)
   echo -n "Checking for service serviio "
        ## Check status with checkproc(8), if process is running
        ## checkproc will return with exit status 0.

        # Status has a slightly different for the status command:
        # 0 - service running
        # 1 - service dead, but /var/run/  pid  file exists
        # 2 - service dead, but /var/lock/ lock file exists
        # 3 - service not running

        # NOTE: checkproc returns LSB compliant status values.
        checkproc $SERVIIO_BIN
        # NOTE: rc_status knows that we called this init script with
        # "status" option and adapts its messages accordingly.
        rc_status -v
   ;;
    probe)
   ## Optional: Probe for the necessity of a reload,
   ## give out the argument which is required for a reload.

   ;;
    *)
   echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
   exit 1
   ;;
esac
rc_exit


Set Serviio owner (My video files owned by video group):
chown -R nobody:video /path_to_serviio_root

Symlinks:
ln -s /path_to_serviio_root/bin/serviio.sh /usr/bin/serviio
ln -s /etc/init.d/serviio /sbin/rcserviio

Set up running on default runlevel:
/sbin/insserv /etc/init.d/serviio



i so love you for this post u have save me about 4 hours worth of work as im building a serviio linux build and this will help alot :)
Phil Bennett
Beta Tester Group
Wiki | FAQ

Samsung LE40C750 LCD | Samsung BD-C5900 | Sony PS3 | Windows 7 |
HowTo: Provide supported formats of a device HowTo: Record a new ticket on Bitbucket
HowTo: Provide details of a video file that doesn't play HowTo: Turn on detailed logging
<<

jtl

Serviio newbie

Posts: 11

Joined: Tue Dec 21, 2010 6:01 pm

Post Thu Feb 03, 2011 2:13 am

Re: Linux Daemon scripts

Debian Squeeze wants a little different init script. Also, -halt does not work for me (it behaves just like without the argument, i.e. if the server is already running, it will stay running, and if it is already stopped, it will be started up). I've updated Ian Laird's script to handle these two issues.

Copy Ian's config file (above) into /etc/default (Debian's path for such things). Update the user and path values. Then you can use this:

  Code:
#!/bin/sh
#
#########################################################
#- Daemon script for Serviio media server
#- By Ian Laird; converted for Debian by Jacob Lundberg
#- /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/rcS ]; then
        . /etc/default/rcS
fi


DAEMON_STOP=" -stop"
NAME="$(basename $0)"
PIDFILE="/var/run/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}"
        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


Finally, to install the init script so it is automatic, run this as root:
  Code:
update-rc.d serviio defaults
<<

NX3

DLNA master

Posts: 578

Joined: Fri Jan 28, 2011 12:39 pm

Post Fri Feb 04, 2011 4:07 pm

Re: Linux Daemon scripts

jopiexjoker wrote:
NX3 wrote:For anyone on Ubuntu 10.10 you won't find /etc/conf.d/ on your system. However to get Serviio to start automatically is really easy as under the administration menu you'll find 'Startup Applications'. Select that and then just add the scripts files, you can browse to where ever you saved them. Next time you reboot Serviio just starts :-D


It starts before log in?


No it doesn't but I'm an Ubuntu newbie, 10.10 doesn't have a /etc/conf.d/ so I was stuck and the best solution for now. If anyone could post how to get it working without that file and pre-login ?
<<

jopiexjoker

Serviio newbie

Posts: 9

Joined: Sun Jan 30, 2011 11:11 am

Post Fri Feb 04, 2011 6:40 pm

Re: Linux Daemon scripts

NX3 wrote:
jopiexjoker wrote:
NX3 wrote:For anyone on Ubuntu 10.10 you won't find /etc/conf.d/ on your system. However to get Serviio to start automatically is really easy as under the administration menu you'll find 'Startup Applications'. Select that and then just add the scripts files, you can browse to where ever you saved them. Next time you reboot Serviio just starts :-D


It starts before log in?


No it doesn't but I'm an Ubuntu newbie, 10.10 doesn't have a /etc/conf.d/ so I was stuck and the best solution for now. If anyone could post how to get it working without that file and pre-login ?


I hope the debian script in the reply above yours does the trick, because ubuntu is a debianbased distribution. I'll try it out soon.
<<

jopiexjoker

Serviio newbie

Posts: 9

Joined: Sun Jan 30, 2011 11:11 am

Post Sat Feb 05, 2011 6:37 pm

Re: Linux Daemon scripts

For all you ubuntu lovers, like myself... I've combined above scripts and got it to work in ubuntu 10.10.

Make the configfile /etc/default/serviio
  Code:
#########################################################
#- Daemon Script Configuration for Serviio Media Server
#- By Ian Laird
#- /etc/default/serviio
#########################################################

NAME="Serviio Media Server"
DAEMON="/usr/share/serviio/bin/serviio.sh"    ## Update this to point at serviio_root/bin/serviio.sh
SERVICE_ACCOUNT="username"                       ## change to an appropriate username, DON'T RUN UNDER ROOT!


Then make the script /etc/init.d/serviio like this:
  Code:
#!/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/rcS ]; then
        . /etc/default/rcS
fi


DAEMON_STOP=" -stop"
NAME="$(basename $0)"
PIDFILE="/var/run/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}"
        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


Make it executable:
$sudo chmod 755 /etc/init.d/serviio

then run:
$sudo update-rc.d serviio defaults

all credits go to Ian and Jtl. I merely combined it to work under ubuntu.

edit: changed #!/bin/sh to #!/bin/bash, because i got an error on stopping the daemon...
<<

thekat

Serviio newbie

Posts: 1

Joined: Sun Feb 20, 2011 1:24 pm

Post Tue Feb 22, 2011 2:18 am

Re: Linux Daemon scripts

Thanks for the scripts.. !!

I found Serviio on the Ubuntu forums while searching on how to fix another player..
0.5 is a great improvement ..

tk
<<

Luke

Serviio newbie

Posts: 1

Joined: Sun Mar 06, 2011 8:55 am

Post Sun Mar 06, 2011 9:40 am

Re: Linux Daemon scripts

Qkxy wrote:Hi!
I made this script for serviio 0.2 on OpenSuSE 11.2:

/etc/init.d/serviio
  Code:
#! /bin/sh
# Copyright (c) 2009 Zoltan Kukk
#
# Author: zoltan.kukk@gmail.com
#
# /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_BIN=/usr/bin/serviio
test -x $SERVIIO_BIN || { echo "$SERVIIO_BIN not installed";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }

# Load the rc.status script for this service.
. /etc/rc.status

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status

# First reset status of this service
rc_reset

case "$1" in
    start)
   echo -n "Starting Serviio DLNA server"
   ## Start daemon with startproc(8). If this fails
   ## the echo return value is set appropriate.

   startproc -f -u nobody -g video -l /var/log/serviio.log $SERVIIO_BIN -headless
   # Remember status and be verbose
   rc_status -v
   ;;
    start-gui)
        echo -n "Starting Serviio DLNA server"
        ## Start daemon with startproc(8). If this fails
        ## the echo return value is set appropriate.

        startproc -f -u nobody -g video -l /var/log/serviio.log $SERVIIO_BIN
        # Remember status and be verbose
        rc_status -v
        ;;
    stop)
   echo -n "Shutting down Serviio DLNA daemon"
   ## Stop daemon with killproc(8) and if this fails
   ## set echo the echo return value.

   startproc -f -u nobody -g video -l /var/log/serviio.log $SERVIIO_BIN -stop

   # Remember status and be verbose
   rc_status -v
   ;;
    try-restart)
        ## Stop the service and if this succeeds (i.e. the
        ## service was running before), start it again.
        $0 status >/dev/null &&  $0 restart

        # Remember status and be quiet
        rc_status
        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start

        # Remember status and be quiet
        rc_status
        ;;
    force-reload|reload)
   ## Signal the daemon to reload its config. Most daemons
   ## do this on signal 1 (SIGHUP).

   echo -n "Reload Serviio DLNA server"
        rc_failed 3
        rc_status -v
        ;;
    status)
   echo -n "Checking for service serviio "
        ## Check status with checkproc(8), if process is running
        ## checkproc will return with exit status 0.

        # Status has a slightly different for the status command:
        # 0 - service running
        # 1 - service dead, but /var/run/  pid  file exists
        # 2 - service dead, but /var/lock/ lock file exists
        # 3 - service not running

        # NOTE: checkproc returns LSB compliant status values.
        checkproc $SERVIIO_BIN
        # NOTE: rc_status knows that we called this init script with
        # "status" option and adapts its messages accordingly.
        rc_status -v
   ;;
    probe)
   ## Optional: Probe for the necessity of a reload,
   ## give out the argument which is required for a reload.

   ;;
    *)
   echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
   exit 1
   ;;
esac
rc_exit


Set Serviio owner (My video files owned by video group):
chown -R nobody:video /path_to_serviio_root

Symlinks:
ln -s /path_to_serviio_root/bin/serviio.sh /usr/bin/serviio
ln -s /etc/init.d/serviio /sbin/rcserviio

Set up running on default runlevel:
/sbin/insserv /etc/init.d/serviio



With this script, serviio is starting with US-ASCII setting. I have added these lines after rc_reset to set it back to UTF8 (otherwise, serviio doesn't loading non-Ascii filenames, which is a real problem for me):

  Code:
    # First reset status of this service
    rc_reset
   
    # Set up correct LANG
   test -f /etc/sysconfig/language && . /etc/sysconfig/language
   export LC_ALL="$RC_LC_ALL"
   export LC_CTYPE="$RC_LC_CTYPE"
   export LANG="$RC_LANG"
<<

MulletBoy

Serviio newbie

Posts: 14

Joined: Tue Nov 23, 2010 7:49 am

Post Sat Mar 12, 2011 6:53 am

Re: Linux Daemon scripts

hi,

iv been using serviio for a while on a windows box but today changed that to a ubuntu 10.04 lucid lynx box

i am an experianced windows user but first time linux

i have downloaded serviio, and extracted it, its currently sitting on my desktop....

can someone please help me put it in the right stop and setup these scripts.... iv tried going to the locations listed in the above posts ... but i get permission denied errors when i try to create files in those directoiwa

like ect/default for example is owner "root"

from my reading i think i need to use sudo commands to do all this.... but i have no idea how to make those commands...

any help would be greatly appreciated,
<<

Cerberus

User avatar

DLNA master

Posts: 4114

Joined: Sun Jan 02, 2011 5:20 pm

Location: Reading, UK

Post Sat Mar 12, 2011 8:03 am

Re: Linux Daemon scripts

MulletBoy wrote:hi,

iv been using serviio for a while on a windows box but today changed that to a ubuntu 10.04 lucid lynx box

i am an experianced windows user but first time linux

i have downloaded serviio, and extracted it, its currently sitting on my desktop....

can someone please help me put it in the right stop and setup these scripts.... iv tried going to the locations listed in the above posts ... but i get permission denied errors when i try to create files in those directoiwa

like ect/default for example is owner "root"

from my reading i think i need to use sudo commands to do all this.... but i have no idea how to make those commands...

any help would be greatly appreciated,


Ubuntu Tutorial: viewtopic.php?f=5&t=1605&start=10
Phil Bennett
Beta Tester Group
Wiki | FAQ

Samsung LE40C750 LCD | Samsung BD-C5900 | Sony PS3 | Windows 7 |
HowTo: Provide supported formats of a device HowTo: Record a new ticket on Bitbucket
HowTo: Provide details of a video file that doesn't play HowTo: Turn on detailed logging
<<

moltra

DLNA master

Posts: 1871

Joined: Thu Mar 24, 2011 11:00 pm

Location: Ohio USA

Post Sat Mar 26, 2011 10:59 pm

Re: Linux Daemon scripts

jopiexjoker wrote:For all you ubuntu lovers, like myself... I've combined above scripts and got it to work in ubuntu 10.10.

Make the configfile /etc/default/serviio
  Code:
#########################################################
#- Daemon Script Configuration for Serviio Media Server
#- By Ian Laird
#- /etc/default/serviio
#########################################################

NAME="Serviio Media Server"
DAEMON="/usr/share/serviio/bin/serviio.sh"    ## Update this to point at serviio_root/bin/serviio.sh
SERVICE_ACCOUNT="username"                       ## change to an appropriate username, DON'T RUN UNDER ROOT!


Then make the script /etc/init.d/serviio like this:
  Code:
#!/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/rcS ]; then
        . /etc/default/rcS
fi


DAEMON_STOP=" -stop"
NAME="$(basename $0)"
PIDFILE="/var/run/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}"
        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


Make it executable:
$sudo chmod 755 /etc/init.d/serviio

then run:
$sudo update-rc.d serviio defaults

all credits go to Ian and Jtl. I merely combined it to work under ubuntu.

edit: changed #!/bin/sh to #!/bin/bash, because i got an error on stopping the daemon...



when I try to run the /etc/init.d/serviio under the normal run level I get.

* Starting Serviio media server daemon Serviio Media Server [ OK ]
mark@server:~$ start-stop-daemon: Unable to open pidfile '/var/run/serviiod.pid' for writing: Permission denied (Permission denied)


If I run it with sudo it works fine. I know a little about linux and learning more each day, since I started this ubuntu server.

when it run this way, I cannot use the windows serviio console client to see the server anymore. I could when I ran the /bin/serviio-sh file.
Mark
Beta Tester Group
http://www.serviidb.com Online media resource repository

Netgear EVA2000 | Samsung BD-D5300 | XBOX 360 | Windows 7 | Mint Debian 12 | Raxz Maxx
HowTo: Provide supported formats of a device HowTo: Record a new ticket on Bitbucket
HowTo: Provide details of a video file that doesn't play HowTo: Turn on detailed logging
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Tue Apr 05, 2011 5:06 pm

Re: Linux Daemon scripts

<<

Ray

Serviio newbie

Posts: 6

Joined: Sun Jan 30, 2011 7:52 am

Post Mon Apr 11, 2011 3:39 pm

Re: Linux Daemon scripts

Did anyone find a solution for Ubuntu 10.10 above

"when I try to run the /etc/init.d/serviio under the normal run level I get.
* Starting Serviio media server daemon Serviio Media Server [ OK ]
mark@server:~$ start-stop-daemon: Unable to open pidfile '/var/run/serviiod.pid' for writing: Permission denied (Permission denied)"

I don't want to run with root privileges, so i ended up doing the following:
chmod +w /etc/init.d/serviio

But this still leaves an error on stopping the daemon. (Can't delete the file).

Is there a neater solution?

Thx.
<<

Cerberus

User avatar

DLNA master

Posts: 4114

Joined: Sun Jan 02, 2011 5:20 pm

Location: Reading, UK

Post Tue Apr 12, 2011 11:57 am

Re: Linux Daemon scripts

Ray wrote:Did anyone find a solution for Ubuntu 10.10 above

"when I try to run the /etc/init.d/serviio under the normal run level I get.
* Starting Serviio media server daemon Serviio Media Server [ OK ]
mark@server:~$ start-stop-daemon: Unable to open pidfile '/var/run/serviiod.pid' for writing: Permission denied (Permission denied)"

I don't want to run with root privileges, so i ended up doing the following:
chmod +w /etc/init.d/serviio

But this still leaves an error on stopping the daemon. (Can't delete the file).

Is there a neater solution?

Thx.


try there dev site ;)
Phil Bennett
Beta Tester Group
Wiki | FAQ

Samsung LE40C750 LCD | Samsung BD-C5900 | Sony PS3 | Windows 7 |
HowTo: Provide supported formats of a device HowTo: Record a new ticket on Bitbucket
HowTo: Provide details of a video file that doesn't play HowTo: Turn on detailed logging
<<

iglooc00l

Serviio newbie

Posts: 1

Joined: Sat Apr 16, 2011 7:26 pm

Post Sat Apr 16, 2011 7:34 pm

Re: Linux Daemon scripts

1) Use sudo to create a pid file with the name "serviiod.pid" in the /var/run directory.
2) Give the user account you're running the script as (specified earlier) the ability to modify the pid file (chown it).
3) issue sudo /etc/init.d/serviio start

Should see no errors..

Ig
<<

kc1

Streaming enthusiast

Posts: 28

Joined: Mon Jun 06, 2011 12:21 pm

Post Tue Jun 07, 2011 10:15 am

Re: Linux Daemon scripts

jtl wrote:Debian Squeeze wants a little different init script. Also, -halt does not work for me (it behaves just like without the argument, i.e. if the server is already running, it will stay running, and if it is already stopped, it will be started up). I've updated Ian Laird's script to handle these two issues.

Copy Ian's config file (above) into /etc/default (Debian's path for such things). Update the user and path values. Then you can use this...

Hi I'm trying to figure out how to have Serviio start automatically on my ReadyNAS NXV.

I think the version of linux it's running is Debian (cat /etc/issue.net returns GNU/Linux 4.0, and uname -r returns 2.6.37.5.RNx86_32.1.1). Would that mean I could do it the same as for your "Debian Squeeze" example?

Thanks
Trying to get Serviio working with Samsung D7000 and ReadyNas NVX without a PC in between
Next

Return to Third-party tools integration

Who is online

Users browsing this forum: No registered users and 5 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.