-
Notifications
You must be signed in to change notification settings - Fork 0
/
s6.sh
64 lines (58 loc) · 1.17 KB
/
s6.sh
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
#!/bin/sh
set -eu
live="/run/s6/live"
status() {
active="$(mktemp -p /run/s6)"
trap 'rm -f "$active"' EXIT
s6-rc -l "$live" -a list >"$active"
s6-rc-db -l "$live" list services |
grep -v '^s6rc-' |
sort |
while read -r i; do
if grep -qF "$i" "$active"; then
printf "\e[1;32m UP \e[m\t%s\n" "$i"
else
printf "\e[1;31mDOWN\e[m\t%s\n" "$i"
fi
done
s6-rc-db -l "$live" list bundles |
sort |
while read -r i; do
printf "\e[1;34mBNDL\e[m\t%s: " "$i"
find \
"$live/compiled/src/$i/contents.d" \
-type f -exec basename -a {} + |
sort |
tr '\n' ' '
echo
done
}
change() {
set +e
s6-rc -l "$live" "$1" "$2"
code="$?"
status
exit $code
}
usage() {
cat <<EOF
Usage: $0 [mode]
status Prints all services (with up/down state) and bundles
start|up|u <service> Starts the given service
stop|down|d <service> Stops the given service
help Print this help
EOF
}
op="${1-status}"
case "$op" in
status) status ;;
start | up | u) change start "$2" ;;
stop | down | d) change stop "$2" ;;
help | --help | h | -h) usage ;;
*)
exec >&2
echo "Unknown operation '$op'"
usage
exit 1
;;
esac