From db828b5e03653c1159b0e1adaf8190be6574edba Mon Sep 17 00:00:00 2001 From: Roland Smith Date: Mon, 27 Apr 2015 19:58:07 +0200 Subject: [PATCH] Used service(8) to discover running services. On all supported FreeBSD releases, the service(8) program can be used to discover which services are running. This program has been added to the test for binaries. If available, it will be used to test for services. If not, the original code that parses /etc/rc.conf is used. On my system, the following information is produced in the logfile: [19:51:22] Performing test ID BOOT-5165 (Check for FreeBSD boot services) [19:51:22] Searching for services at startup (service) [19:51:23] Found service (service/rc.conf): bgfsck [19:51:23] Found service (service/rc.conf): cleanvar [19:51:23] Found service (service/rc.conf): cron [19:51:23] Found service (service/rc.conf): cupsd [19:51:23] Found service (service/rc.conf): dbus [19:51:23] Found service (service/rc.conf): devd [19:51:23] Found service (service/rc.conf): dmesg [19:51:23] Found service (service/rc.conf): dnsmasq [19:51:23] Found service (service/rc.conf): gptboot [19:51:23] Found service (service/rc.conf): hostid [19:51:23] Found service (service/rc.conf): hostid_save [19:51:23] Found service (service/rc.conf): ip6addrctl [19:51:23] Found service (service/rc.conf): ipfw [19:51:23] Found service (service/rc.conf): mixer [19:51:23] Found service (service/rc.conf): motd [19:51:23] Found service (service/rc.conf): newsyslog [19:51:23] Found service (service/rc.conf): nginx [19:51:23] Found service (service/rc.conf): openntpd [19:51:23] Found service (service/rc.conf): postfix [19:51:23] Found service (service/rc.conf): powerd [19:51:23] Found service (service/rc.conf): sendmail [19:51:23] Found service (service/rc.conf): smartd [19:51:23] Found service (service/rc.conf): syslogd [19:51:23] Found service (service/rc.conf): virecover [19:51:23] Found 24 services/options to run at startup The report shows: [+] Boot and services ------------------------------------ - Service Manager [ UNKNOWN ] - Checking presence FreeBSD loader [ FOUND ] - Checking services at startup (service/rc.conf) [ DONE ] Result: found 24 services/options set --- include/tests_boot_services | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/include/tests_boot_services b/include/tests_boot_services index 35fee381..58f6ef5e 100644 --- a/include/tests_boot_services +++ b/include/tests_boot_services @@ -382,16 +382,22 @@ # Description : Check for FreeBSD boot services Register --test-no BOOT-5165 --os FreeBSD --weight L --network NO --description "Check for FreeBSD boot services" if [ ${SKIPTEST} -eq 0 ]; then - # FreeBSD (Read /etc/rc.conf file for enabled services) - logtext "Searching for services at startup (rc.conf)" - FIND=`egrep -v -i '^#|none' /etc/rc.conf | egrep -i '_enable.*(yes|on|1)' | sort | awk -F= '{ print $1 }' | sed 's/_enable//'` + if [ ! "${SERVICEBINARY}" = "" ]; then + # FreeBSD (Ask services(8) for enabled services) + logtext "Searching for services at startup (service)" + FIND=`${SERVICEBINARY} -e | sed 's|^.*\/||' | sort` + else + # FreeBSD (Read /etc/rc.conf file for enabled services) + logtext "Searching for services at startup (rc.conf)" + FIND=`egrep -v -i '^#|none' /etc/rc.conf | egrep -i '_enable.*(yes|on|1)' | sort | awk -F= '{ print $1 }' | sed 's/_enable//'` + fi N=0 for I in ${FIND}; do - logtext "Found service (rc.conf): ${I}" + logtext "Found service (service/rc.conf): ${I}" report "boottask[]=${I}" N=`expr ${N} + 1` done - Display --indent 2 --text "- Checking services at startup (rc.conf)" --result "DONE" --color GREEN + Display --indent 2 --text "- Checking services at startup (service/rc.conf)" --result "DONE" --color GREEN Display --indent 6 --text "Result: found $N services/options set" logtext "Found $N services/options to run at startup" fi