-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitctl
More file actions
executable file
·112 lines (101 loc) · 3.03 KB
/
initctl
File metadata and controls
executable file
·112 lines (101 loc) · 3.03 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/sh
################################################################################
#### A wrapper around update-rc.d(8) and service(8) ####
#### to feel similar to systemctl and dispatch actions to multiple services ####
################################################################################
myname=${0##*/}
# program to run the action on the service
# can be "update-rc.d" or "service"
dispatcher=""
# action to be performed on the service
# can be:
# "start"
# "stop"
# "restart"
# "reload"
# "enable"
# "disable"
# "remove"
# "defaults"
# "defaults-disable"
action=""
# service file to have an action performed on
service=""
# werether to perform the action or only print out the command to run
DRYRUN=""
# return type: string
get_header_comment () {
sed -n '/^#### /p' "$0" | sed 's/^#### /\t/ ; s/ ####$//'
}
# usage: run_dispatch dispatcher service action
run_dispatch () {
case "$1" in
service|update-rc.d)
# sbin may not be in user's path
run_com="/usr/sbin/${1}"
if [ -z "$DRYRUN" ]; then
$run_com "$2" "$3"
else
printf '%s %s %s\n' "$run_com" "$2" "$3"
fi
;;
esac
}
show_usage () {
printf '%s\n' "Usage:"
printf '\t%s\n' "${myname} --help | [ ACTION ] <services>"
}
show_help () {
printf '%s\n' "${myname}"
get_header_comment
show_usage
printf ' %s' "ACTION"
printf '\t%s\n' "where action is one of the following:"
printf '\t\t %s\n' "start"
printf '\t\t %s\n' "stop"
printf '\t\t %s\n' "restart"
printf '\t\t %s\n' "reload"
printf '\t\t %s\n' "enable"
printf '\t\t %s\n' "disable"
printf '\t\t %s\n' "remove"
printf '\t\t %s\n' "defaults"
printf '\t\t %s\n' "defaults-disable"
printf '\t\t%s%s\n' "for more information on the actions check" \
" 'man service' and 'man update-rc.d'"
printf '\n'
printf ' %s' "services"
printf '\t%s\n' "is a space separated list of the services to perform the action on"
printf '\n'
printf ' %s' "--help"
printf '\t%s\n' "show this message, the shortcuts '-h' and 'help' are also supported."
}
service_list=""
# while the number of arguments is greater than 0
while [ "$#" -gt 0 ]; do
case "$1" in
enable|disable|defaults|remove|defaults-disable)
dispatcher=update-rc.d
action="$1"
;;
start|stop|restart|reload|status)
dispatcher=service
action="$1"
;;
-h|--help|help)
show_help
exit 0
;;
-n|--dryrun|dryrun)
DRYRUN=1
;;
*)
service="$1"
if [ -e "/etc/init.d/${service}" ]; then
run_dispatch "$dispatcher" "$service" "$action"
else
printf '[%s]: %s\n' "$myname" "service '$service' not present in /etc/init.d/"
fi
;;
esac
shift
done