# $OpenBSD: rc.subr,v 1.15 2010/12/24 10:37:24 ajacoutot Exp $ [ -z "${local_rcconf}" ] && . /etc/rc.conf rc_err() { echo $1 exit 1 } rc_start() { type rc_pre >/dev/null && rc_pre su -l -c ${daemon_class} -s ${daemon_shell} ${daemon_user} \ -c "${daemon} ${daemon_flags}" >/dev/null } rc_check() { pgrep -f "^${pexp}" >/dev/null } rc_reload() { pkill -HUP -f "^${pexp}" } rc_stop() { pkill -f "^${pexp}" type rc_post >/dev/null && rc_post || return 0 } rc_conf() { [ -n "${daemon}" ] || rc_err "$0: daemon is not set" _name=`basename $0` eval _rcflags=\${${_name}_flags} eval _rcuser=\${${_name}_user} eval _rcclass=\${${_name}_class} eval _rcshell=\${${_name}_shell} [ -z "${daemon_class}" ] && daemon_class=daemon [ -z "${daemon_shell}" ] && daemon_shell=/bin/sh [ -z "${daemon_user}" ] && daemon_user=root [ -n "${_rcflags}" ] && daemon_flags=${_rcflags} [ -n "${_rcuser}" ] && daemon_user=${_rcuser} [ -n "${_rcclass}" ] && daemon_class=${_rcclass} [ -n "${_rcshell}" ] && daemon_shell=${_rcshell} daemon_flags=`echo ${daemon_flags} | tr -s "[:space:]"` pexp="${daemon}${daemon_flags:+ ${daemon_flags}}" } rc_cmd() { [ `id -u` -eq 0 -o X"$1" = "Xcheck" ] || \ rc_err "$0: need root privileges" eval _enotsup=\${rc_${1}} [ X"${_enotsup}" != X"NO" ] || rc_err "$0: $1 is not supported" case "$1" in check) rc_check ;; start) rc_check || rc_start ;; stop) rc_stop ;; reload) rc_check && rc_reload ;; restart) rc_stop while rc_check; do sleep 1 done rc_start ;; *) rc_err "usage: $0 {start|check|reload|restart|stop}" esac }