blob: a7b214e0a2f832576d72314f4a14c80ea373f312 (
plain)
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
|
#!/bin/bash
NEED_ROOT=0 # this script can be run without be root
. /etc/rc.conf
. /etc/rc.d/functions
usage() {
local name=${0##*/}
cat >&2 << EOF
usage: $name <action> <daemon> [daemon] ...
$name list [started|stopped]
$name help
<daemon> is the name of a script in /etc/rc.d
<action> can be a start, stop, restart, reload, status, ...
WARNING: initscripts are free to implement or not the above actions.
e.g: $name list
$name list started
$name help
$name start sshd gpm
EOF
exit 1
}
(( $# < 1 )) && usage
declare -i ret=0
case $1 in
help)
usage
;;
list)
shift
cd /etc/rc.d/
for d in *; do
have_daemon "$d" || continue
# print running / stopped satus
if ! ck_daemon "$d"; then
[[ "$1" == stopped ]] && continue
printf "${C_OTHER}[${C_DONE}STARTED${C_OTHER}]"
else
[[ "$1" == started ]] && continue
printf "${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]"
fi
# print auto / manual status
if ! ck_autostart "$d"; then
printf "${C_OTHER}[${C_DONE}AUTO${C_OTHER}]"
else
printf "${C_OTHER}[${C_FAIL} ${C_OTHER}]"
fi
printf " ${C_CLEAR}$d\n"
done
;;
*)
# check min args count
(( $# < 2 )) && usage
action=$1
shift
# set same environment variables as init
runlevel=$(/sbin/runlevel)
ENV=("PATH=/bin:/usr/bin:/sbin:/usr/sbin"
"PREVLEVEL=${runlevel%% *}"
"RUNLEVEL=${runlevel##* }"
"CONSOLE=${CONSOLE:-/dev/console}"
"TERM=$TERM")
cd /
for i; do
if [[ -x "/etc/rc.d/$i" ]]; then
env -i "${ENV[@]}" "/etc/rc.d/$i" "$action"
else
printf "${C_OTHER}:: ${C_FAIL}Error: ${C_DONE}Daemon script $i does not exist.${C_CLEAR}\n"
fi
(( ret += !! $? )) # clamp exit value to 0/1
done
;;
esac
exit $ret
# vim: set ts=2 sw=2 ft=sh noet:
|