5
# Original Author: Tor Krill <tor@excito.com>.
6
# Modified by: Leonhard Wimmer <leo@mediatomb.cc>
7
# Modified again by Andres Mejia <mcitadel@gmail.com> to
8
# base it off of /etc/init.d/skeleton
14
# Required-Start: $local_fs $network $remote_fs
15
# Required-Stop: $local_fs $network $remote_fs
18
# Default-Start: 2 3 4 5
20
# Short-Description: upnp media server
21
# Description: Debian init script for the upnp media server
26
# PATH should only include /usr/* if it runs after the mountnfs.sh script
27
PATH=/usr/sbin:/usr/bin:/sbin:/bin
28
DESC="upnp media server"
31
PIDFILE=/var/run/$NAME.pid
32
LOGFILE=/var/log/$NAME.log
33
SCRIPTNAME=/etc/init.d/$NAME
34
DEFAULT=/etc/default/$NAME
36
# Exit if the package is not installed
37
[ -x "$DAEMON" ] || exit 0
39
# Read configuration variable file if it is present
40
[ -r $DEFAULT ] && . $DEFAULT
42
# Load the VERBOSE setting and other rcS variables
43
[ -f /etc/default/rcS ] && . /etc/default/rcS
45
# Define LSB log_* functions.
46
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
47
. /lib/lsb/init-functions
49
# Start the daemon if NO_START is disabled in DEFAULT
50
if [ "$NO_START" = "yes" ] && [ "$1" != "stop" ]; then
51
log_warning_msg "$NAME: Not starting $DESC."
52
log_warning_msg "$NAME: Disabled in $DEFAULT."
56
# Run as root if USER not specified
61
# Check for an invalid user or one without a home directory
63
if [ "${USERHOME#/}" = "${USERHOME}" ]; then
64
log_failure_msg "$NAME: The user '$USER' specified in $DEFAULT is invalid."
68
# Check if group is not specified and assign a proper group
69
if [ -z $GROUP ]; then
73
if [ "$INTERFACE" != "" ] ; then
74
INTERFACE_ARG="-e $INTERFACE"
79
DAEMON_ARGS="-c /etc/mediatomb/config.xml -d -u $USER -g $GROUP -P $PIDFILE -l $LOGFILE $INTERFACE_ARG $OPTIONS"
82
# Function that starts the daemon/service.
86
# 0 if daemon has been started
87
# 1 if daemon was already running
88
# 2 if daemon could not be started
90
chown $USER:$GROUP $PIDFILE
92
chown $USER:$GROUP $LOGFILE
93
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
96
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
102
# Function that stops the daemon/service.
106
# 0 if daemon has been stopped
107
# 1 if daemon was already stopped
108
# 2 if daemon could not be stopped
109
# other if a failure occurred
110
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
112
[ "$RETVAL" = 2 ] && return 2
118
# Function that sends a SIGHUP to the daemon/service.
121
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
127
if [ -n "$INTERFACE" ]; then
128
# try to add the multicast route
129
if [ "$VERBOSE" != no ]; then
131
log_action_begin_msg \
132
"$NAME: Trying to add the multicast route"
133
$ROUTE_ADD $INTERFACE \
134
&& log_action_end_msg 0
137
log_warning_msg "Failed to add multicast route. skipping."
140
$ROUTE_ADD $INTERFACE >/dev/null 2>&1 || true
143
log_daemon_msg "Starting $DESC" "$NAME"
147
1) log_warning_msg "$DESC" "'$NAME'" "was already started" ;;
152
log_daemon_msg "Stopping $DESC" "$NAME"
157
if [ -n "$INTERFACE" ]; then
158
# try to add the multicast route
159
if [ "$VERBOSE" != no ]; then
161
log_action_begin_msg \
162
"$NAME: Trying to delete the multicast route"
163
$ROUTE_DEL $INTERFACE \
164
&& log_action_end_msg 0
168
"Failed to delete multicast route. skipping."
171
$ROUTE_DEL $INTERFACE >/dev/null 2>&1 || true
175
1) log_warning_msg "$DESC" "'$NAME'" "was already stopped" ;;
180
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
183
log_daemon_msg "Reloading $DESC" "$NAME"
189
# If the "reload" option is implemented, move the "force-reload"
190
# option to the "reload" entry above. If not, "force-reload" is
191
# just the same as "restart".
193
log_daemon_msg "Restarting $DESC" "$NAME"
201
1) log_end_msg 1 ;; # Old process is still running
202
*) log_end_msg 1 ;; # Failed to start
212
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
213
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2