rc.d 1.18 KB
Newer Older
Sébastien Luttringer's avatar
Sébastien Luttringer committed
1
2
3
4
5
6
#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

usage() {
Sébastien Luttringer's avatar
Sébastien Luttringer committed
7
8
9
	local name=${0##*/}
	cat >&2 << EOF
usage: $name action daemon ...
Sébastien Luttringer's avatar
Sébastien Luttringer committed
10

Sébastien Luttringer's avatar
Sébastien Luttringer committed
11
12
13
e.g: $name list
     $name help
     $name start sshd gpm
Sébastien Luttringer's avatar
Sébastien Luttringer committed
14
EOF
15
	exit 1
Sébastien Luttringer's avatar
Sébastien Luttringer committed
16
17
}

18
(( $# < 1 )) && usage
Sébastien Luttringer's avatar
Sébastien Luttringer committed
19

20
declare -i ret=0
Sébastien Luttringer's avatar
Sébastien Luttringer committed
21
22
23
24
25
26
27
28
29
30
case $1 in
	help)
		usage
		;;
	list)
		cd /etc/rc.d/
		for d in *; do
			have_daemon "$d" || continue
			# print running / stopped satus
			if ! ck_daemon "$d"; then
31
				printf "${C_OTHER}[${C_DONE}STARTED${C_OTHER}]"
Sébastien Luttringer's avatar
Sébastien Luttringer committed
32
			else
33
				printf "${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]"
Sébastien Luttringer's avatar
Sébastien Luttringer committed
34
35
36
			fi
			# print auto / manual status
			if ! ck_autostart "$d"; then
37
				printf "${C_OTHER}[${C_DONE}AUTO${C_OTHER}]"
Sébastien Luttringer's avatar
Sébastien Luttringer committed
38
			else
39
				printf "${C_OTHER}[${C_FAIL}    ${C_OTHER}]"
Sébastien Luttringer's avatar
Sébastien Luttringer committed
40
			fi
Sébastien Luttringer's avatar
Sébastien Luttringer committed
41
			printf " ${C_CLEAR}$d\n"
Sébastien Luttringer's avatar
Sébastien Luttringer committed
42
43
44
45
46
		done
		;;
	*)
		action=$1
		shift
47
48
		# set same environment variables as init
		runlevel=$(/sbin/runlevel)
Dave Reisner's avatar
Dave Reisner committed
49
50
51
52
53
		ENV=("PATH=/bin:/usr/bin:/sbin:/usr/sbin"
			"PREVLEVEL=${runlevel%% *}"
			"RUNLEVEL=${runlevel##* }"
			"CONSOLE=${CONSOLE:-/dev/console}"
			"TERM=$TERM")
54
		cd /
Sébastien Luttringer's avatar
Sébastien Luttringer committed
55
		for i; do
56
			[[ -x "/etc/rc.d/$i" ]] && /usr/bin/env -i "${ENV[@]}" "/etc/rc.d/$i" "$action"
57
			(( ret += !! $? ))  # clamp exit value to 0/1
Sébastien Luttringer's avatar
Sébastien Luttringer committed
58
59
60
		done
esac

61
exit $ret
Sébastien Luttringer's avatar
Sébastien Luttringer committed
62

63
# vim: set ts=2 sw=2 ft=sh noet: