5
# Based on the mediatomb debian package.
6
# Original authors: Tor Krill <tor@excito.com>
7
# Leonhard Wimmer <leo@mediatomb.cc>
8
# Andres Mejia <mcitadel@gmail.com>
10
# Modified by: Benoît Knecht <benoit.knecht@fsfe.org>
14
# Required-Start: $network $local_fs $remote_fs
15
# Required-Stop:: $network $local_fs $remote_fs
18
# Default-Start: 2 3 4 5
20
# Short-Description: Start minidlna at boot time
21
# Description: Manage the minidlna daemon, a DLNA/UPnP-AV media server.
26
# PATH should only include /usr/* if it runs after the mountnfs.sh script
27
PATH=/sbin:/usr/sbin:/bin:/usr/bin
28
DESC="DLNA/UPnP-AV media server"
30
DAEMON=/usr/bin/minidlnad
32
PIDFILE=$PIDDIR/$NAME.pid
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
# Define LSB log_* functions.
43
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
44
. /lib/lsb/init-functions
46
# Do not start the daemon if NO_START is enabled in DEFAULT
47
if [ "$START_DAEMON" != "yes" ] && [ "$1" != "stop" ]; then
48
log_warning_msg "$NAME: Not starting $DESC."
49
log_warning_msg "$NAME: Disabled in $DEFAULT."
53
# Set the default configuration file
54
if [ -z $CONFIGFILE ]; then
55
CONFIGFILE=/etc/minidlna.conf
58
# Set the default log file
59
if [ -z $LOGFILE ]; then
60
LOGFILE=/var/log/minidlna.log
63
# Run as `minidlna' if USER is not specified or is `root'
68
# If no group is specified, use USER
69
if [ -z $GROUP ]; then
73
DAEMON_ARGS="-f $CONFIGFILE -P $PIDFILE $DAEMON_OPTS"
76
# Function that starts the daemon/service
81
# 0 if daemon has been started
82
# 1 if daemon was already running
83
# 2 if daemon could not be started
84
touch $LOGFILE && chown $USER:$GROUP $LOGFILE || return 2
85
if [ ! -d $PIDDIR ]; then
86
mkdir $PIDDIR || return 2
88
chown $USER:$GROUP $PIDDIR || return 2
90
start-stop-daemon --start --quiet --pidfile $PIDFILE \
91
--chuid $USER:$GROUP --exec $DAEMON --test > /dev/null \
93
start-stop-daemon --start --quiet --pidfile $PIDFILE \
94
--chuid $USER:$GROUP --exec $DAEMON -- \
100
# Function that stops the daemon/service
105
# 0 if daemon has been stopped
106
# 1 if daemon was already stopped
107
# 2 if daemon could not be stopped
108
# other if a failure occurred
109
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --exec $DAEMON
111
[ "$RETVAL" = 2 ] && return 2
112
# Wait for children to finish too if this is a daemon that forks
113
# and if the daemon is only ever run from this initscript.
114
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
115
[ "$?" = 2 ] && return 2
116
# Many daemons don't delete their pidfiles when they exit.
122
# Function that signals log rotation to the daemon/service
126
start-stop-daemon --stop --quiet --signal USR1 --pidfile $PIDFILE --exec $DAEMON
131
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
134
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
135
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
139
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
142
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
143
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
147
status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
149
restart|force-reload)
150
log_daemon_msg "Restarting $DESC" "$NAME"
154
if [ "$1" = "force-reload" ]; then
155
# Rescan the collection
156
DAEMON_ARGS="$DAEMON_ARGS -R"
161
1) log_end_msg 1 ;; # Old process is still running
162
*) log_end_msg 1 ;; # Failed to start
172
log_daemon_msg "Reopening log file $LOGFILE"
177
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload|rotate}" >&2