Switch to unified view

a b/debian/scweb.init
1
#!/bin/sh
2
#
3
# Upmpdcli Songcast Receiver control web interface init script.
4
#         Copyright (C) 2015 J.F. Dockes
5
6
# Derived from:
7
# 
8
#         VirtualBox web service API daemon init script.
9
#
10
#         Copyright (C) 2006-2012 Oracle Corporation
11
#
12
#         This file is part of VirtualBox Open Source Edition (OSE), as
13
#         available from http://www.virtualbox.org. This file is free software;
14
#     you can redistribute it and/or modify it under the terms of the GNU
15
#     General Public License (GPL) as published by the Free Software
16
#     Foundation, in version 2 as it comes in the "COPYING" file of the
17
#     VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18
#     hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19
#
20
#
21
# chkconfig: 35 35 65
22
# description: Songcast Receiver control web interface
23
#
24
### BEGIN INIT INFO
25
# Provides:       scweb-service
26
# Required-Start: $remote_fs $syslog
27
# Required-Stop:  $remote_fs $syslog
28
# Default-Start:  2 3 4 5
29
# Default-Stop:   0 1 6
30
# Description:    Songcast Receiver control web interface
31
### END INIT INFO
32
33
PATH=$PATH:/bin:/sbin:/usr/sbin
34
35
[ -f /etc/debian_release -a -f /lib/lsb/init-functions ] || NOLSB=yes
36
37
if [ -n "$INSTALL_DIR" ]; then
38
    binary="$INSTALL_DIR/scweb-standalone.py"
39
    scctl="$INSTALL_DIR/scctl"
40
else
41
    binary="/usr/share/upmpdcli/web/scweb-standalone.py"
42
    scctl="/usr/bin/scctl"
43
fi
44
45
# silently exit if the package was uninstalled but not purged,
46
# applies to Debian packages only (but shouldn't hurt elsewhere)
47
[ ! -f /etc/debian_release -o -x $binary ] || exit 0
48
49
[ -r /etc/default/scweb ] && . /etc/default/scweb
50
51
system=unknown
52
if [ -f /etc/redhat-release ]; then
53
    system=redhat
54
    PIDFILE="/var/lock/subsys/scweb-service"
55
elif [ -f /etc/SuSE-release ]; then
56
    system=suse
57
    PIDFILE="/var/lock/subsys/scweb-service"
58
elif [ -f /etc/debian_version ]; then
59
    system=debian
60
    PIDFILE="/var/run/scweb-service"
61
elif [ -f /etc/gentoo-release ]; then
62
    system=gentoo
63
    PIDFILE="/var/run/scweb-service"
64
elif [ -f /etc/arch-release ]; then
65
     system=arch
66
     PIDFILE="/var/run/scweb-service"
67
elif [ -f /etc/slackware-version ]; then
68
    system=slackware
69
    PIDFILE="/var/run/scweb-service"
70
elif [ -f /etc/lfs-release ]; then
71
    system=lfs
72
    PIDFILE="/var/run/scweb-service.pid"
73
else
74
    system=other
75
    if [ -d /var/run -a -w /var/run ]; then
76
        PIDFILE="/var/run/scweb-service"
77
    fi
78
fi
79
80
if [ -z "$NOLSB" ]; then
81
    . /lib/lsb/init-functions
82
    fail_msg() {
83
        echo ""
84
        log_failure_msg "$1"
85
    }
86
    succ_msg() {
87
        log_success_msg " done."
88
    }
89
    begin_msg() {
90
        log_daemon_msg "$@"
91
    }
92
fi
93
94
if [ "$system" = "redhat" ]; then
95
    . /etc/init.d/functions
96
    if [ -n "$NOLSB" ]; then
97
        start_daemon() {
98
            usr="$1"
99
            shift
100
            daemon --user $usr $@
101
        }
102
        fail_msg() {
103
            echo_failure
104
            echo
105
        }
106
        succ_msg() {
107
            echo_success
108
            echo
109
        }
110
        begin_msg() {
111
            echo -n "$1"
112
        }
113
    fi
114
fi
115
116
if [ "$system" = "suse" ]; then
117
    . /etc/rc.status
118
    start_daemon() {
119
        usr="$1"
120
        shift
121
        su - $usr -c "$*"
122
    }
123
    if [ -n "$NOLSB" ]; then
124
        fail_msg() {
125
            rc_failed 1
126
            rc_status -v
127
        }
128
        succ_msg() {
129
            rc_reset
130
            rc_status -v
131
        }
132
        begin_msg() {
133
            echo -n "$1"
134
        }
135
    fi
136
fi
137
138
if [ "$system" = "debian" ]; then
139
    start_daemon() {
140
        usr="$1"
141
        shift
142
        bin="$1"
143
        shift
144
        start-stop-daemon --background --chuid $usr --start --exec $bin -- $@
145
    }
146
    killproc() {
147
        start-stop-daemon --stop --exec $@
148
    }
149
    if [ -n "$NOLSB" ]; then
150
        fail_msg() {
151
            echo " ...fail!"
152
        }
153
        succ_msg() {
154
            echo " ...done."
155
        }
156
        begin_msg() {
157
            echo -n "$1"
158
       }
159
    fi
160
fi
161
162
if [ "$system" = "gentoo" ]; then
163
    if [ -f /sbin/functions.sh ]; then
164
        . /sbin/functions.sh
165
    elif [ -f /etc/init.d/functions.sh ]; then
166
        . /etc/init.d/functions.sh
167
    fi
168
    start_daemon() {
169
        usr="$1"
170
        shift
171
        bin="$1"
172
        shift
173
        start-stop-daemon --background --chuid $usr --start --exec $bin -- $@
174
    }
175
    killproc() {
176
        start-stop-daemon --stop --exec $@
177
    }
178
    if [ -n "$NOLSB" ]; then
179
        fail_msg() {
180
            echo " ...fail!"
181
        }
182
        succ_msg() {
183
            echo " ...done."
184
        }
185
        begin_msg() {
186
            echo -n "$1"
187
        }
188
        if [ "`which $0`" = "/sbin/rc" ]; then
189
            shift
190
        fi
191
    fi
192
fi
193
194
if [ "$system" = "arch" ]; then
195
    USECOLOR=yes
196
    . /etc/rc.d/functions
197
    start_daemon() {
198
        usr="$1"
199
        shift
200
        su - $usr -c "$*"
201
        test $? -eq 0 && add_daemon rc.`basename $2`
202
    }
203
    killproc() {
204
        killall $@
205
        rm_daemon `basename $@`
206
    }
207
    if [ -n "$NOLSB" ]; then
208
        fail_msg() {
209
            stat_fail
210
        }
211
        succ_msg() {
212
            stat_done
213
        }
214
        begin_msg() {
215
            stat_busy "$1"
216
        }
217
    fi
218
fi
219
220
if [ "$system" = "slackware" ]; then
221
    killproc() {
222
        killall $1
223
        rm -f $PIDFILE
224
    }
225
    if [ -n "$NOLSB" ]; then
226
        fail_msg() {
227
            echo " ...fail!"
228
        }
229
        succ_msg() {
230
            echo " ...done."
231
        }
232
        begin_msg() {
233
            echo -n "$1"
234
        }
235
    fi
236
    start_daemon() {
237
        usr="$1"
238
        shift
239
        su - $usr -c "$*"
240
    }
241
fi
242
243
if [ "$system" = "lfs" ]; then
244
    . /etc/rc.d/init.d/functions
245
    if [ -n "$NOLSB" ]; then
246
        fail_msg() {
247
            echo_failure
248
        }
249
        succ_msg() {
250
            echo_ok
251
        }
252
        begin_msg() {
253
            echo $1
254
        }
255
    fi
256
    start_daemon() {
257
        usr="$1"
258
        shift
259
        su - $usr -c "$*"
260
    }
261
    status() {
262
        statusproc $1
263
    }
264
fi
265
266
if [ "$system" = "other" ]; then
267
    if [ -n "$NOLSB" ]; then
268
        fail_msg() {
269
            echo " ...fail!"
270
        }
271
        succ_msg() {
272
            echo " ...done."
273
        }
274
        begin_msg() {
275
            echo -n "$1"
276
        }
277
    fi
278
fi
279
280
check_single_user() {
281
    if [ -n "$2" ]; then
282
        fail_msg "VBOXWEB_USER must not contain multiple users!"
283
        exit 1
284
    fi
285
}
286
287
start() {
288
    #echo "START"
289
    if ! test -f $PIDFILE; then
290
        #echo "DORUN?"
291
        [ "$SCWEB_DORUN" = "yes" ] || exit 0
292
        #echo "USER SET?"
293
        [ -z "$SCWEB_USER" ] && exit 0
294
        begin_msg "Starting scweb Songcast control web interface";
295
        check_single_user $SCWEB_USER
296
        #echo SCWEB_USER $SCWEB_USER single ok
297
        PARAMS=""
298
        [ -n "$SCWEB_ADDRESS" ]        && PARAMS="$PARAMS -a $SCWEB_ADDRESS"
299
        [ -n "$SCWEB_PORT" ]           && PARAMS="$PARAMS -p $SCWEB_PORT"
300
301
        #echo start_daemon $SCWEB_USER $binary $PARAMS
302
        start_daemon $SCWEB_USER $binary $PARAMS > /dev/null 2>&1
303
        # ugly: wait until the final process has forked
304
        sleep .1
305
        PID=`ps ax | egrep 'python .*/scweb-standalone' | grep -v grep | awk '{print $1}'`
306
        if [ -n "$PID" ]; then
307
            echo "$PID" > $PIDFILE
308
            RETVAL=0
309
            succ_msg
310
        else
311
            RETVAL=1
312
            fail_msg
313
        fi
314
    else
315
        echo "Pidfile $PIDFILE already exists" 1>&2
316
    fi
317
    
318
    return $RETVAL
319
}
320
321
scwebpid()
322
{
323
    echo `ps ax | grep 'python.*scweb-standalone' |grep -v grep | \
324
        awk '{print $1}'`
325
}
326
327
stop() {
328
    if test -f $PIDFILE; then
329
        begin_msg "Stopping scweb web interface";
330
331
        RPID=`scwebpid`
332
        [ -n "$RPID" ] && kill "$RPID"
333
        RETVAL=$?
334
335
        RPID=`scwebpid`
336
        if test -z "$RPID"; then
337
            rm -f $PIDFILE
338
            succ_msg
339
        else
340
            fail_msg
341
        fi
342
    fi
343
    return $RETVAL
344
}
345
346
restart() {
347
    stop && start
348
}
349
350
status() {
351
    echo -n "Checking for scweb web interface"
352
    if [ -f $PIDFILE ]; then
353
        echo " ...running"
354
    else
355
        echo " ...not running"
356
    fi
357
}
358
359
case "$1" in
360
start)
361
    start
362
    ;;
363
stop)
364
    stop
365
    ;;
366
restart)
367
    restart
368
    ;;
369
force-reload)
370
    restart
371
    ;;
372
status)
373
    status
374
    ;;
375
setup)
376
    ;;
377
cleanup)
378
    ;;
379
*)
380
    echo "Usage: $0 {start|stop|restart|status}"
381
    exit 1
382
esac
383
384
exit $RETVAL