Skip to content
Snippets Groups Projects
rc.d 1.18 KiB
Newer Older
Sébastien Luttringer's avatar
Sébastien Luttringer committed
#!/bin/bash

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

usage() {
	local name=${0##*/}
	cat >&2 << EOF
usage: $name action daemon ...
e.g: $name list
     $name help
     $name start sshd gpm
Sébastien Luttringer's avatar
Sébastien Luttringer committed
EOF
(( $# < 1 )) && usage
declare -i ret=0
Sébastien Luttringer's avatar
Sébastien Luttringer committed
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
				printf "${C_OTHER}[${C_DONE}STARTED${C_OTHER}]"
Sébastien Luttringer's avatar
Sébastien Luttringer committed
			else
				printf "${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]"
Sébastien Luttringer's avatar
Sébastien Luttringer committed
			fi
			# print auto / manual status
			if ! ck_autostart "$d"; then
				printf "${C_OTHER}[${C_DONE}AUTO${C_OTHER}]"
Sébastien Luttringer's avatar
Sébastien Luttringer committed
			else
				printf "${C_OTHER}[${C_FAIL}    ${C_OTHER}]"
Sébastien Luttringer's avatar
Sébastien Luttringer committed
			fi
			printf " ${C_CLEAR}$d\n"
Sébastien Luttringer's avatar
Sébastien Luttringer committed
		done
		;;
	*)
		action=$1
		shift
		# 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
		for i; do
			[[ -x "/etc/rc.d/$i" ]] && cd / && eval /usr/bin/env -i $ENV "/etc/rc.d/$i" "$action"
			(( ret += !! $? ))  # clamp exit value to 0/1
Sébastien Luttringer's avatar
Sébastien Luttringer committed
		done
esac

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

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