-
Notifications
You must be signed in to change notification settings - Fork 0
/
svactivate
executable file
·52 lines (48 loc) · 1.31 KB
/
svactivate
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
#!/bin/sh
#
# runit service activation
# (cloux@rote.ch)
# We need to be root
if [ $(id -u) -ne 0 ]; then printf '%s: Need to be root!\n' "$0"; exit 1; fi
if [ $# -eq 0 ]; then
printf 'Enter runit service names as parameters.\n'
printf 'Supported services are listed in /etc/sv/\n'
exit
fi
# process all services provided as command line parameters
RET=0
for SRV in "$@"; do
SRVNAME=${SRV##*/}
if [ -d "/etc/service/$SRVNAME" ]; then
printf '%s: runit service "%s" is already active\n' "${0##*/}" "$SRVNAME"
continue
fi
if [ ! -d "/etc/sv/$SRVNAME" ]; then
printf '%s: runit service definition "/etc/sv/%s" not found, activation failed\n' "${0##*/}" "$SRVNAME"
RET=1
continue
fi
# mark service as enabled
rm -f "/etc/sv/$SRVNAME/disabled"
# remove supervise symlinks
find "/etc/sv/$SRVNAME/" -type l -name supervise -delete
# enable service supervision
ln -s "/etc/sv/$SRVNAME" /etc/service/ 2>/dev/null
if [ $? -eq 0 ]; then
# wait for runsv to become available
COUNT=0
while ! sv status $SRVNAME >/dev/null; do
sleep 0.2
COUNT=$((COUNT+1))
if [ "$COUNT" -gt 40 ]; then
printf '%s: runsv for runit service "%s" failed to start\n' "${0##*/}" "$SRVNAME"
RET=1
break
fi
done
else
printf '%s: runit service "%s" activation failed\n' "${0##*/}" "$SRVNAME"
RET=1
fi
done
exit $RET