rc.d 1.16 KB
Newer Older
Sébastien Luttringer's avatar
Sébastien Luttringer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash

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

usage() {
    cat >&2 << EOF
usage: rc action daemon ...

e.g: rc list
     rc help
     rc start sshd gpm
EOF
14
	exit 1
Sébastien Luttringer's avatar
Sébastien Luttringer committed
15
16
}

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

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

58
exit $ret
Sébastien Luttringer's avatar
Sébastien Luttringer committed
59
60

# vim: set ts=2 sw=2 noet: