[rygel/rygel-0.16] examples: Add startup scripts for various daemons
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel/rygel-0.16] examples: Add startup scripts for various daemons
- Date: Fri, 31 Aug 2012 05:51:24 +0000 (UTC)
commit ced287d463eaebdec2c433a2cd319e7289017f21
Author: Jens Georg <mail jensge org>
Date: Wed Aug 8 00:35:18 2012 +0200
examples: Add startup scripts for various daemons
examples/service/README.Ubuntu | 57 +++++++++++
examples/service/systemd/rygel.service | 12 +++
examples/service/sysv/rygel | 159 ++++++++++++++++++++++++++++++++
examples/service/upstart/rygel.conf | 17 ++++
examples/service/wrap-dbus | 41 ++++++++
5 files changed, 286 insertions(+), 0 deletions(-)
---
diff --git a/examples/service/README.Ubuntu b/examples/service/README.Ubuntu
new file mode 100644
index 0000000..d47156f
--- /dev/null
+++ b/examples/service/README.Ubuntu
@@ -0,0 +1,57 @@
+Running Rygel as a system service with Ubuntu
+=============================================
+
+This guide has been tested with Ubuntu 12.04 LTS.
+
+Dependencies
+~~~~~~~~~~~~
+
+Install Rygel and most of the GStreamer plug-ins:
+
+ sudo apt-get install rygel gstreamer0.10-plugins-good \
+ gstreamer0.10-plugins-bad gstreamer0.10-plugins-ugly \
+ gstreamer0.10-ffmpeg
+
+You might want to skip gstreamer0.10-plugins-multiverse if you're using rygel
+< 0.15.1, otherwise you'll run into troubles with transcoding.
+
+Configuration
+~~~~~~~~~~~~~
+
+After that, you might want to create a dedicated user for the server:
+ sudo adduser --home /home/rygel --disabled-password --disabled-login \
+ --gecos 'Rygel media server' rygel
+
+Then switch to that user, create ~/.config and copy /etc/rygel.conf there.
+Modify it to fit your needs by disabling plugins and transcoders you don't need,
+setting the device name and paths.
+
+Then copy upstart/rygel.conf to /etc/init and call "sudo start rygel" to start
+the service. It should get started at every boot from now on.
+
+Generating Thumbnails
+~~~~~~~~~~~~~~~~~~~~~
+
+Rygel reuses thumbnails that were generated by external software such as
+nautilus. However, it can also request creation of thumbnails by itself.
+
+To enable this feature, you have to install tumbler:
+
+ sudo apt-get install tumbler
+
+Since tumbler is a D-Bus service, rygel has to have access to a D-Bus session
+bus. To accomplish this you need to copy the included D-Bus wrapper script
+"wrap-dbus" somewhere and modify the upstart script to call a wrapped rygel:
+
+ exec /usr/local/bin/wrap-dbus rygel
+
+wrap-dbus makes sure that a session bus is running and will re-use an existing
+bus it spawned itself.
+
+After (re-) starting rygel, it should start requesting thumbnail generation
+for files that don't have thumbnails. If you don't see them in your client
+right away, you might have to refresh the view.
+
+Note: For Rygel versions below 0.15.1, you have to create ~/.thumbnails/normal
+as well, otherwise Rygel thinks there are no thumbnails available as it is not
+aware that tumbler will generate this directory.
diff --git a/examples/service/systemd/rygel.service b/examples/service/systemd/rygel.service
new file mode 100644
index 0000000..56012f9
--- /dev/null
+++ b/examples/service/systemd/rygel.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Rygel DLNA server
+After=syslog.target
+
+[Service]
+User=rygel
+Group=rygel
+ExecStart=/usr/bin/rygel
+# ExecStart=/usr/bin/wrap-dbus /usr/bin/rygel
+
+[Install]
+WantedBy=multi-user.target
diff --git a/examples/service/sysv/rygel b/examples/service/sysv/rygel
new file mode 100755
index 0000000..3d02033
--- /dev/null
+++ b/examples/service/sysv/rygel
@@ -0,0 +1,159 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides: rygel
+# Required-Start: $localfs
+# Required-Stop: $localfs
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Rygel UPnP-AV server
+# Description: Start Rygel UPnP server at boot
+### END INIT INFO
+
+# Author: Jens Georg <mail jensge org>
+
+# Do NOT "set -e"
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="Description of the service"
+NAME=rygel
+DAEMON=/usr/bin/$NAME
+DAEMON_ARGS=""
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
+# and status_of_proc is working.
+. /lib/lsb/init-functions
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+ # Return
+ # 0 if daemon has been started
+ # 1 if daemon was already running
+ # 2 if daemon could not be started
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
+ || return 1
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --no-close --chuid rygel:rygel -b -m --exec $DAEMON -- \
+ $DAEMON_ARGS >/var/log/rygel.log 2>&1\
+ || return 2
+# Version with private D-Bus
+# start-stop-daemon --start --quiet --pidfile $PIDFILE --no-close --chuid rygel:rygel -b -m \
+# --exec /usr/bin/wrap-dbus -- $DAEMON $DAEMON_ARGS >>/var/log/rygel.log 2>&1 \
+# || return 2
+ # Add code here, if necessary, that waits for the process to be ready
+ # to handle requests from services started subsequently which depend
+ # on this one. As a last resort, sleep for some time.
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+ # Return
+ # 0 if daemon has been stopped
+ # 1 if daemon was already stopped
+ # 2 if daemon could not be stopped
+ # other if a failure occurred
+ start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
+ RETVAL="$?"
+ [ "$RETVAL" = 2 ] && return 2
+ # Wait for children to finish too if this is a daemon that forks
+ # and if the daemon is only ever run from this initscript.
+ # If the above conditions are not satisfied then add some other code
+ # that waits for the process to drop all resources that could be
+ # needed by services started subsequently. A last resort is to
+ # sleep for some time.
+ start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
+ [ "$?" = 2 ] && return 2
+ # Many daemons don't delete their pidfiles when they exit.
+ rm -f $PIDFILE
+ return "$RETVAL"
+}
+
+#
+# Function that sends a SIGHUP to the daemon/service
+#
+do_reload() {
+ #
+ # If the daemon can reload its configuration without
+ # restarting (for example, when it is sent a SIGHUP),
+ # then implement that here.
+ #
+ start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
+ return 0
+}
+
+case "$1" in
+ start)
+ [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+ do_start
+ case "$?" in
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+ stop)
+ [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+ status)
+ status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
+ ;;
+ #reload|force-reload)
+ #
+ # If do_reload() is not implemented then leave this commented out
+ # and leave 'force-reload' as an alias for 'restart'.
+ #
+ #log_daemon_msg "Reloading $DESC" "$NAME"
+ #do_reload
+ #log_end_msg $?
+ #;;
+ restart|force-reload)
+ #
+ # If the "reload" option is implemented then remove the
+ # 'force-reload' alias
+ #
+ log_daemon_msg "Restarting $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1)
+ do_start
+ case "$?" in
+ 0) log_end_msg 0 ;;
+ 1) log_end_msg 1 ;; # Old process is still running
+ *) log_end_msg 1 ;; # Failed to start
+ esac
+ ;;
+ *)
+ # Failed to stop
+ log_end_msg 1
+ ;;
+ esac
+ ;;
+ *)
+ #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+ exit 3
+ ;;
+esac
+
+:
diff --git a/examples/service/upstart/rygel.conf b/examples/service/upstart/rygel.conf
new file mode 100644
index 0000000..9fff52e
--- /dev/null
+++ b/examples/service/upstart/rygel.conf
@@ -0,0 +1,17 @@
+description "Rygel UPnP-AV/DLNA server"
+
+start on (local-filesystems and net-device-up IFACE!=lo)
+stop on runlevel [!2345]
+
+respawn
+respawn limit 10 5
+umask 022
+
+console log
+setuid rygel
+setgid rygel
+
+env HOME="/home/rygel"
+
+#exec /usr/bin/wrap-dbus /usr/bin/rygel
+exec /usr/bin/rygel
diff --git a/examples/service/wrap-dbus b/examples/service/wrap-dbus
new file mode 100755
index 0000000..6cd80f8
--- /dev/null
+++ b/examples/service/wrap-dbus
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+# wrap-dbus is a script for a semi-private session bus on headless logins
+# Copyright (C) 2012 Jens Georg <mail jensge org>
+#
+# This file is part of Rygel.
+#
+# Rygel is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Rygel is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+[ -z $1 ] && exit 127
+
+command=$(shift 1)
+
+pid=$(grep DBUS_SESSION_BUS_PID $HOME/.dbusrc | cut -f2 -d= | sed -e 's,;,,')
+cmdline="/proc/$pid/cmdline"
+if [ -e $cmdline ]
+then
+ if grep -q "dbus-daemon" $cmdline; then
+ . $HOME/.dbusrc
+ exec $command $*
+ fi
+fi
+
+dbus=($(dbus-daemon --fork --session --print-address 1 --print-pid 1))
+echo DBUS_SESSION_BUS_ADDRESS="'${dbus[0]}'" > $HOME/.dbusrc
+echo export DBUS_SESSION_BUS_ADDRESS >> $HOME/.dbusrc
+echo DBUS_SESSION_BUS_PID=${dbus[1]} >> $HOME/.dbusrc
+. $HOME/.dbusrc
+exec $command $*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]