forked from imeyer/runit-rpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runit.init
90 lines (77 loc) · 2.1 KB
/
runit.init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#! /bin/bash
#
# runit Startup script for runit under sysvinit
#
# chkconfig: - 85 15
# description: Runit is a process supervisor
#
### BEGIN INIT INFO
# Provides: runit
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop runit
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
PROG=/sbin/runsvdir
PIDFILE=/var/run/runsvdir.pid
SVDIR=/service
SVWAIT=200
if [ -L $0 ]; then
initscript=`/bin/readlink -f $0`
else
initscript=$0
fi
sysconfig=`/bin/basename $initscript`
if [ -f /etc/sysconfig/$sysconfig ]; then
. /etc/sysconfig/$sysconfig
fi
declare -r PROG PIDFILE SVDIR SVWAIT
RETVAL=0
start() {
local logspace='log: ...........................................................................................................................................................................................................................................................................................................................................................................................................'
local shortname=${PROG##*/}
echo -n $"Starting $shortname: "
local envset=""
if [ -d /etc/runit/envdir-runsvdir ]; then
envset="/sbin/chpst -e /etc/runit/envdir-runsvdir"
fi
$envset $PROG -P ${SVDIR} "$logspace" &
echo $! > "$PIDFILE"
if checkpid $!; then
success $shortname
else
failure $shortname
fi
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $PROG: "
killproc -p ${PIDFILE} ${PROG}
/sbin/sv -w${SVWAIT} force-shutdown ${SVDIR}/* &>/dev/null
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${PIDFILE}
}
# See how we were called.
case "$1" in
start)
status -p ${PIDFILE} $PROG &>/dev/null && exit 0
start
;;
stop)
stop
;;
status)
status -p ${PIDFILE} $PROG
RETVAL=$?
;;
*)
echo $"Usage: $PROG {start|stop|status|help}"
RETVAL=2
esac
exit $RETVAL