~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to vivid/etc/init.d/minidlna

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# MiniDLNA initscript
 
4
#
 
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>
 
9
#
 
10
# Modified by: Benoît Knecht <benoit.knecht@fsfe.org>
 
11
#
 
12
### BEGIN INIT INFO
 
13
# Provides:          minidlna
 
14
# Required-Start:    $network $local_fs $remote_fs
 
15
# Required-Stop::    $network $local_fs $remote_fs
 
16
# Should-Start:      $all
 
17
# Should-Stop:       $all
 
18
# Default-Start:     2 3 4 5
 
19
# Default-Stop:      0 1 6
 
20
# Short-Description: Start minidlna at boot time
 
21
# Description:       Manage the minidlna daemon, a DLNA/UPnP-AV media server.
 
22
### END INIT INFO
 
23
 
 
24
unset USER
 
25
 
 
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"
 
29
NAME=minidlna
 
30
DAEMON=/usr/bin/minidlnad
 
31
PIDDIR=/run/$NAME
 
32
PIDFILE=$PIDDIR/$NAME.pid
 
33
SCRIPTNAME=/etc/init.d/$NAME
 
34
DEFAULT=/etc/default/$NAME
 
35
 
 
36
# Exit if the package is not installed
 
37
[ -x $DAEMON ] || exit 0
 
38
 
 
39
# Read configuration variable file if it is present
 
40
[ -r $DEFAULT ] && . $DEFAULT
 
41
 
 
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
 
45
 
 
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."
 
50
        exit 0
 
51
fi
 
52
 
 
53
# Set the default configuration file
 
54
if [ -z $CONFIGFILE ]; then
 
55
        CONFIGFILE=/etc/minidlna.conf
 
56
fi
 
57
 
 
58
# Set the default log file
 
59
if [ -z $LOGFILE ]; then
 
60
        LOGFILE=/var/log/minidlna.log
 
61
fi
 
62
 
 
63
# Run as `minidlna' if USER is not specified or is `root'
 
64
if [ -z $USER ]; then
 
65
        USER=minidlna
 
66
fi
 
67
 
 
68
# If no group is specified, use USER
 
69
if [ -z $GROUP ]; then
 
70
        GROUP=$USER
 
71
fi
 
72
 
 
73
DAEMON_ARGS="-f $CONFIGFILE -P $PIDFILE $DAEMON_OPTS"
 
74
 
 
75
#
 
76
# Function that starts the daemon/service
 
77
#
 
78
do_start()
 
79
{
 
80
        # Return
 
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
 
87
        fi
 
88
        chown $USER:$GROUP $PIDDIR || return 2
 
89
 
 
90
        start-stop-daemon --start --quiet --pidfile $PIDFILE \
 
91
                --chuid $USER:$GROUP --exec $DAEMON --test > /dev/null \
 
92
                || return 1
 
93
        start-stop-daemon --start --quiet --pidfile $PIDFILE \
 
94
                --chuid $USER:$GROUP --exec $DAEMON -- \
 
95
                $DAEMON_ARGS \
 
96
                || return 2
 
97
}
 
98
 
 
99
#
 
100
# Function that stops the daemon/service
 
101
#
 
102
do_stop()
 
103
{
 
104
        # Return
 
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
 
110
        RETVAL="$?"
 
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.
 
117
        rm -rf $PIDDIR
 
118
        return "$RETVAL"
 
119
}
 
120
 
 
121
#
 
122
# Function that signals log rotation to the daemon/service
 
123
#
 
124
do_rotate()
 
125
{
 
126
        start-stop-daemon --stop --quiet --signal USR1 --pidfile $PIDFILE --exec $DAEMON
 
127
}
 
128
 
 
129
case "$1" in
 
130
  start)
 
131
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
 
132
    do_start
 
133
    case "$?" in
 
134
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
135
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
136
        esac
 
137
  ;;
 
138
  stop)
 
139
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
 
140
        do_stop
 
141
        case "$?" in
 
142
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
143
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
144
        esac
 
145
        ;;
 
146
  status)
 
147
       status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
 
148
       ;;
 
149
  restart|force-reload)
 
150
        log_daemon_msg "Restarting $DESC" "$NAME"
 
151
        do_stop
 
152
        case "$?" in
 
153
          0|1)
 
154
                if [ "$1" = "force-reload" ]; then
 
155
                        # Rescan the collection
 
156
                        DAEMON_ARGS="$DAEMON_ARGS -R"
 
157
                fi
 
158
                do_start
 
159
                case "$?" in
 
160
                        0) log_end_msg 0 ;;
 
161
                        1) log_end_msg 1 ;; # Old process is still running
 
162
                        *) log_end_msg 1 ;; # Failed to start
 
163
                esac
 
164
                ;;
 
165
          *)
 
166
                # Failed to stop
 
167
                log_end_msg 1
 
168
                ;;
 
169
        esac
 
170
        ;;
 
171
  rotate)
 
172
        log_daemon_msg "Reopening log file $LOGFILE"
 
173
        do_rotate
 
174
        log_end_msg $?
 
175
        ;;
 
176
  *)
 
177
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload|rotate}" >&2
 
178
        exit 3
 
179
        ;;
 
180
esac
 
181
 
 
182
: