~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

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

  • 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
# MediaTomb initscript
 
4
#
 
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
 
9
#
 
10
#
 
11
 
 
12
### BEGIN INIT INFO
 
13
# Provides:          mediatomb
 
14
# Required-Start:    $local_fs $network $remote_fs
 
15
# Required-Stop:     $local_fs $network $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: upnp media server
 
21
# Description:       Debian init script for the upnp media server
 
22
### END INIT INFO
 
23
 
 
24
# Do NOT "set -e"
 
25
 
 
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"
 
29
NAME=mediatomb
 
30
DAEMON=/usr/bin/$NAME
 
31
PIDFILE=/var/run/$NAME.pid
 
32
LOGFILE=/var/log/$NAME.log
 
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
# Load the VERBOSE setting and other rcS variables
 
43
[ -f /etc/default/rcS ] && . /etc/default/rcS
 
44
 
 
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
 
48
 
 
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."
 
53
        exit 0
 
54
fi
 
55
 
 
56
# Run as root if USER not specified
 
57
if [ ! $USER ]; then
 
58
        USER=root
 
59
fi
 
60
 
 
61
# Check for an invalid user or one without a home directory
 
62
eval USERHOME=~$USER
 
63
if [ "${USERHOME#/}" = "${USERHOME}" ]; then
 
64
        log_failure_msg "$NAME: The user '$USER' specified in $DEFAULT is invalid."
 
65
        exit 1
 
66
fi
 
67
 
 
68
# Check if group is not specified and assign a proper group
 
69
if [ -z $GROUP ]; then
 
70
    GROUP="$USER"
 
71
fi
 
72
 
 
73
if [ "$INTERFACE" != "" ] ; then
 
74
    INTERFACE_ARG="-e $INTERFACE"
 
75
else
 
76
    INTERFACE_ARG=""
 
77
fi
 
78
 
 
79
DAEMON_ARGS="-c /etc/mediatomb/config.xml -d -u $USER -g $GROUP -P $PIDFILE -l $LOGFILE $INTERFACE_ARG $OPTIONS"
 
80
 
 
81
#
 
82
#       Function that starts the daemon/service.
 
83
#
 
84
do_start() {
 
85
        # Return
 
86
        #   0 if daemon has been started
 
87
        #   1 if daemon was already running
 
88
        #   2 if daemon could not be started
 
89
        touch $PIDFILE
 
90
        chown $USER:$GROUP $PIDFILE
 
91
        touch $LOGFILE
 
92
        chown $USER:$GROUP $LOGFILE
 
93
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
 
94
                --test > /dev/null \
 
95
                || return 1
 
96
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
 
97
                $DAEMON_ARGS \
 
98
                || return 2
 
99
}
 
100
 
 
101
#
 
102
#       Function that stops the daemon/service.
 
103
#
 
104
do_stop() {
 
105
        # Return
 
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
 
111
        RETVAL="$?"
 
112
        [ "$RETVAL" = 2 ] && return 2
 
113
        rm -f $PIDFILE
 
114
        return "$RETVAL"
 
115
}
 
116
 
 
117
#
 
118
#       Function that sends a SIGHUP to the daemon/service.
 
119
#
 
120
do_reload() {
 
121
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
 
122
        return 0
 
123
}
 
124
 
 
125
case "$1" in
 
126
  start)
 
127
        if [ -n "$INTERFACE" ]; then
 
128
                # try to add the multicast route
 
129
                if [ "$VERBOSE" != no ]; then
 
130
                        {
 
131
                                log_action_begin_msg \
 
132
                                "$NAME: Trying to add the multicast route"
 
133
                                $ROUTE_ADD $INTERFACE \
 
134
                                && log_action_end_msg 0
 
135
                        } || {
 
136
                                true && \
 
137
                                log_warning_msg "Failed to add multicast route. skipping."
 
138
                        }
 
139
                else
 
140
                        $ROUTE_ADD $INTERFACE >/dev/null 2>&1 || true
 
141
                fi
 
142
        fi
 
143
        log_daemon_msg "Starting $DESC" "$NAME"
 
144
        do_start
 
145
        case "$?" in
 
146
                0) log_end_msg 0 ;;
 
147
                1) log_warning_msg "$DESC" "'$NAME'" "was already started" ;;
 
148
                2) log_end_msg 1 ;;
 
149
        esac
 
150
        ;;
 
151
  stop)
 
152
        log_daemon_msg "Stopping $DESC" "$NAME"
 
153
        do_stop
 
154
        case "$?" in
 
155
                0)
 
156
                        log_end_msg 0
 
157
                        if [ -n "$INTERFACE" ]; then
 
158
                                # try to add the multicast route
 
159
                                if [ "$VERBOSE" != no ]; then
 
160
                                {
 
161
                                        log_action_begin_msg \
 
162
                                        "$NAME: Trying to delete the multicast route"
 
163
                                        $ROUTE_DEL $INTERFACE \
 
164
                                        && log_action_end_msg 0
 
165
                                } || {
 
166
                                        true && \
 
167
                                        log_warning_msg \
 
168
                                        "Failed to delete multicast route. skipping."
 
169
                                }
 
170
                                else
 
171
                                        $ROUTE_DEL $INTERFACE >/dev/null 2>&1 || true
 
172
                                fi
 
173
                        fi
 
174
                        ;;
 
175
                1) log_warning_msg "$DESC" "'$NAME'" "was already stopped" ;;
 
176
                2) log_end_msg 1 ;;
 
177
        esac
 
178
        ;;
 
179
  status)
 
180
        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
 
181
        ;;
 
182
  reload|force-reload)
 
183
        log_daemon_msg "Reloading $DESC" "$NAME"
 
184
        do_reload
 
185
        log_end_msg $?
 
186
        ;;
 
187
  restart)
 
188
        #
 
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".
 
192
        #
 
193
        log_daemon_msg "Restarting $DESC" "$NAME"
 
194
        do_stop
 
195
        case "$?" in
 
196
          0|1)
 
197
                sleep 1
 
198
                do_start
 
199
                case "$?" in
 
200
                        0) log_end_msg 0 ;;
 
201
                        1) log_end_msg 1 ;; # Old process is still running
 
202
                        *) log_end_msg 1 ;; # Failed to start
 
203
                esac
 
204
                ;;
 
205
          *)
 
206
                # Failed to stop
 
207
                log_end_msg 1
 
208
                ;;
 
209
        esac
 
210
        ;;
 
211
  *)
 
212
        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
 
213
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
 
214
        exit 3
 
215
        ;;
 
216
esac
 
217
 
 
218
: