diff --git a/usr.sbin/service/service.sh b/usr.sbin/service/service.sh --- a/usr.sbin/service/service.sh +++ b/usr.sbin/service/service.sh @@ -42,6 +42,7 @@ echo '' echo "-j Perform actions within the named jail" echo '-e Show services that are enabled' + echo '-s Show status of (enabled) services' echo "-R Stop and start enabled $local_startup services" echo "-l List all scripts in /etc/rc.d and $local_startup" echo '-r Show the results of boot time rcorder' @@ -49,10 +50,11 @@ echo '' } -while getopts 'j:ehlrRv' COMMAND_LINE_ARGUMENT ; do +while getopts 'j:eshlrRv' COMMAND_LINE_ARGUMENT ; do case "${COMMAND_LINE_ARGUMENT}" in j) JAIL="${OPTARG}" ;; e) ENABLED=eopt ;; + s) STATUS=sopt ;; h) usage ; exit 0 ;; l) LIST=lopt ;; r) RCORDER=ropt ;; @@ -111,7 +113,7 @@ exit 0 fi -if [ -n "$ENABLED" -o -n "$RCORDER" ]; then +if [ -n "$ENABLED" -o -n "$RCORDER" -o -n "$STATUS" ]; then # Copied from /etc/rc skip="-s nostart" if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then @@ -124,6 +126,29 @@ files=`rcorder ${skip} /etc/rc.d/* ${local_rc} 2>/dev/null` fi +if [ -n "$STATUS" ]; then + for file in $files; do + if grep -q ^rcvar $file; then + eval `grep ^name= $file` + eval `grep ^rcvar $file` + if [ -n "$rcvar" ]; then + load_rc_config_var ${name} ${rcvar} + fi + if [ -n "$ENABLED" ] ; then + if ! checkyesno $rcvar 2>/dev/null; then + continue; + fi + fi + if $file 2>&1 | grep -q "status"; then + status="Not running" + $file onestatus 1>/dev/null 2>&1 && status="Running" + printf "%s^%s\n" "${name}" "${status}" + fi + fi + done | column -ts^ + exit 0 +fi + if [ -n "$ENABLED" ]; then for file in $files; do if grep -q ^rcvar $file; then