rc.d 1.33 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
		done
		;;
	*)
45
46
		# check min args count
		(( $# < 2 )) && usage
Sébastien Luttringer's avatar
Sébastien Luttringer committed
47
48
		action=$1
		shift
49
50
		# set same environment variables as init
		runlevel=$(/sbin/runlevel)
Dave Reisner's avatar
Dave Reisner committed
51
52
53
54
55
		ENV=("PATH=/bin:/usr/bin:/sbin:/usr/sbin"
			"PREVLEVEL=${runlevel%% *}"
			"RUNLEVEL=${runlevel##* }"
			"CONSOLE=${CONSOLE:-/dev/console}"
			"TERM=$TERM")
56
		cd /
Sébastien Luttringer's avatar
Sébastien Luttringer committed
57
		for i; do
58
			if [[ -x "/etc/rc.d/$i" ]]; then
59
				env -i "${ENV[@]}" "/etc/rc.d/$i" "$action"
60
			else
61
				printf "${C_OTHER}:: ${C_FAIL}Error: ${C_DONE}Daemon script $i does not exist.\n"
62
			fi
63
			(( ret += !! $? ))  # clamp exit value to 0/1
Sébastien Luttringer's avatar
Sébastien Luttringer committed
64
65
66
		done
esac

67
exit $ret
Sébastien Luttringer's avatar
Sébastien Luttringer committed
68

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