Page 1 of 4

Linux Daemon scripts

PostPosted: Thu Dec 10, 2009 5:43 pm
by irlaird
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 $?
}

Re: Linux Daemon scripts

PostPosted: Thu Dec 10, 2009 6:15 pm
by zip
Cool, I'll probably copy this into FAQ or something.

Re: Linux Daemon scripts

PostPosted: Fri Dec 11, 2009 7:59 pm
by Qkxy
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

Re: Linux Daemon scripts

PostPosted: Fri Jan 28, 2011 12:49 pm
by NX3
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

Re: Linux Daemon scripts

PostPosted: Tue Feb 01, 2011 6:50 pm
by jopiexjoker
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?

Re: Linux Daemon scripts

PostPosted: Tue Feb 01, 2011 7:40 pm
by Cerberus
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 :)

Re: Linux Daemon scripts

PostPosted: Thu Feb 03, 2011 2:13 am
by jtl
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

Re: Linux Daemon scripts

PostPosted: Fri Feb 04, 2011 4:07 pm
by NX3
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 ?

Re: Linux Daemon scripts

PostPosted: Fri Feb 04, 2011 6:40 pm
by jopiexjoker
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.

Re: Linux Daemon scripts

PostPosted: Sat Feb 05, 2011 6:37 pm
by jopiexjoker
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...

Re: Linux Daemon scripts

PostPosted: Tue Feb 22, 2011 2:18 am
by thekat
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

Re: Linux Daemon scripts

PostPosted: Sun Mar 06, 2011 9:40 am
by Luke
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"

Re: Linux Daemon scripts

PostPosted: Sat Mar 12, 2011 6:53 am
by MulletBoy
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,

Re: Linux Daemon scripts

PostPosted: Sat Mar 12, 2011 8:03 am
by Cerberus
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

Re: Linux Daemon scripts

PostPosted: Sat Mar 26, 2011 10:59 pm
by moltra
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.

Re: Linux Daemon scripts

PostPosted: Tue Apr 05, 2011 5:06 pm
by zip

Re: Linux Daemon scripts

PostPosted: Mon Apr 11, 2011 3:39 pm
by Ray
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.

Re: Linux Daemon scripts

PostPosted: Tue Apr 12, 2011 11:57 am
by Cerberus
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 ;)

Re: Linux Daemon scripts

PostPosted: Sat Apr 16, 2011 7:34 pm
by iglooc00l
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

Re: Linux Daemon scripts

PostPosted: Tue Jun 07, 2011 10:15 am
by kc1
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