Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -8,20 +8,16 @@ .error "ERROR: MRC doesn't support "compat" mode." .endif OTHER_TARGETS:= -.include "starter.mk" - .SILENT: install: install rc /etc/rc install rc.shutdown /etc/rc.shutdown -SCRIPTS:=${:!find /etc/mrc -name '*.service.mk'!:S/^\/etc\/mrc\///:S/.service.mk$//} - .if defined(AUTOBOOT) .include "init.mk" .ERROR: : ERROR: ABORTING BOOT (sending SIGTERM to parent)! @@ -31,47 +27,13 @@ .endif test: echo Empty target. -# Create service targets -.for service in ${SCRIPTS} -. include "${service}.service.mk" - -# Set DAEMON defaults -DAEMON_${service}_CWD?= / -DAEMON_${service}_ENABLE?= no -DAEMON_${service}_USER?= root -DAEMON_${service}_GROUP?= wheel - -. if !defined(DAEMON_${service}_COMMAND) -. warning MRC> Service [${service}] defunct: no COMMAND specified -. else - -# Service creation targets -. if !target(${service}) -${service}: ${SERVICE_EXIT} ${_SERVICE} -. endif - -# Service status targets -. if !target(${service}_status) -${service}_status: ${_SERVICE_STATUS} -. endif - -# Service exit targets -. if !target(${service}_exit) -${service}_exit: ${_SERVICE_EXIT} ${DAEMON_${service}_DEPS:S/$/_exit/} -. endif - -DAEMON_EXIT: ${service}_exit -. endif -.endfor - -.MAIN: ${SCRIPTS} ${TARGETS} - -.PHONY: ${SCRIPTS} ${OTHER_TARGETS} ${TARGETS} -.undef OTHER_TARGETS SCRIPTS TARGETS +.include "service.mk" + +.undef OTHER_TARGETS TARGETS ENABLED:=${:!env!:C/=.*//:M*_ENABLE} .for var in ${ENABLED} . if !empty(${var}:tl:Mno) Index: daemon.starter.mk ================================================================== --- daemon.starter.mk +++ daemon.starter.mk @@ -1,8 +1,8 @@ _service_daemon: .USE - cd ${DAEMON_$@_CWD} - daemon -u ${DAEMON_$@_USER} -r -P /var/run/daemon.$@.pid ${DAEMON_$@_COMMAND} ${DAEMON_$@_FLAGS} ${DAEMON$@_FOREGROUND} + cd ${DAEMON_$@_CWD} ;\ + daemon -u ${DAEMON_$@_USER} -r -P /var/run/daemon.$@.pid $${CMD} ${DAEMON_$@_FLAGS} ${DAEMON$@_FOREGROUND} _service_daemon_status: .USE echo "Not supported yet." _service_daemon_exit: .USEBEFORE Index: example.service_mk ================================================================== --- example.service_mk +++ example.service_mk @@ -4,12 +4,12 @@ DAEMON_example_BACKGROUND?= # default working directory DAEMON_example_CWD?=/some/path -# command to start service -DAEMON_example_COMMAND?=/path/service +# command to start service, first present executable is used +DAEMON_example_COMMAND?=/path/service /path/other/service # enabled by default? DAEMON_example_ENABLE?=no # general service flags Index: init.mk ================================================================== --- init.mk +++ init.mk @@ -215,14 +215,14 @@ NETWORK_EXIT: nfsclient_exit netif: adjkerntz wlans cloned kld mounttmpfs utmpx echo "MRC:$@> Starting interfaces: ${IFCONFIG_IFACES}" .for iface in ${IFCONFIG_IFACES} -.for item in ${IFCONFIG_${iface}:tW:ts;} +. for item in ${IFCONFIG_${iface}:tW:ts;} ifconfig ${iface} ${item} -.endfor -.undef _IFCONFIG_ARGS +. endfor +. undef _IFCONFIG_ARGS .endfor pf: pflogd .if empty(PF_ENABLE:tl:Mno) echo "MRC:$@> Enabling and loading rules." Index: plain.starter.mk ================================================================== --- plain.starter.mk +++ plain.starter.mk @@ -1,7 +1,7 @@ _service_plain: .USE - chroot -u ${DAEMON_$@_USER} -g ${DAEMON_$@_GROUP} ${DAEMON_$@_CWD} ${DAEMON_$@_COMMAND} ${DAEMON_$@_FLAGS} ${DAEMON_$@_BACKGROUND} + chroot -u ${DAEMON_$@_USER} -g ${DAEMON_$@_GROUP} ${DAEMON_$@_CWD} $${CMD} ${DAEMON_$@_FLAGS} ${DAEMON_$@_BACKGROUND} _service_status: .USE echo "Plain service status doesn't work right now." _service_exit: .USEBEFORE ADDED service.mk Index: service.mk ================================================================== --- /dev/null +++ service.mk @@ -0,0 +1,42 @@ +SCRIPTS:=${:!find /etc/mrc -name '*.service.mk'!:S/^\/etc\/mrc\///:S/.service.mk$//} + +.include "starter.mk" + +# Create service targets +.for service in ${SCRIPTS} +. include "${service}.service.mk" + +# Set DAEMON defaults +DAEMON_${service}_CWD?= / +DAEMON_${service}_ENABLE?= no +DAEMON_${service}_USER?= root +DAEMON_${service}_GROUP?= wheel + +. if !defined(DAEMON_${service}_COMMAND) +. warning MRC> Service [${service}] defunct: no COMMAND specified +. else + +# Service creation targets +. if !target(${service}) +${service}: ${SERVICE_EXIT} ${_SERVICE} +. endif + +# Service status targets +. if !target(${service}_status) +${service}_status: ${_SERVICE_STATUS} +. endif + +# Service exit targets +. if !target(${service}_exit) +${service}_exit: ${_SERVICE_EXIT} ${DAEMON_${service}_DEPS:S/$/_exit/} +. endif + +DAEMON_EXIT: ${service}_exit +. endif +.endfor + +.MAIN: ${SCRIPTS} ${TARGETS} + +.PHONY: ${SCRIPTS} ${OTHER_TARGETS} ${TARGETS} + +.undef SCRIPTS Index: starter.mk ================================================================== --- starter.mk +++ starter.mk @@ -4,16 +4,22 @@ _service_check: .USEBEFORE # check whether service is enabled if [ -z "$${DAEMON_$@_ENABLE}" -a -z "${FORCE}" ]; then \ exit 0 ;\ - fi + fi ;\ + for CMD in ${DAEMON_$@_COMMAND}; do \ + if [ -x $${CMD} ]; then \ + export CMD ;\ + break ;\ + fi ;\ + done ;\ + echo $${CMD} _service_pre: .USEBEFORE - echo "MRC:$@> Starting service." - # kldload modules if any + echo "MRC:$@> Starting service." ;\ if [ -n "${DAEMON_$@_MODULES}" ]; then \ kldload -n ${DAEMON_$@_MODULES}; \ fi _service_post_exit: .USE Index: svc.starter.mk ================================================================== --- svc.starter.mk +++ svc.starter.mk @@ -1,9 +1,9 @@ _service_svc: .USE cd ${DAEMON_$@_CWD} ;\ svc list $@ | grep -q $@ || \ - svc -u ${DAEMON_$@_USER} -g ${DAEMON_$@_GROUP} ${DAEMON_$@_RESTART:D-r} ${DAEMON_$@_RESTART} init $@ ${DAEMON_$@_COMMAND} ${DAEMON_$@_FLAGS} ${DAEMON_$@_FOREGROUND} + svc -u ${DAEMON_$@_USER} -g ${DAEMON_$@_GROUP} ${DAEMON_$@_RESTART:D-r} ${DAEMON_$@_RESTART} init $@ $${CMD} ${DAEMON_$@_FLAGS} ${DAEMON_$@_FOREGROUND} _service_svc_status: .USE svc status ${@:S/_status//} _service_svc_exit: .USEBEFORE Index: wpa_supplicant.service.mk ================================================================== --- wpa_supplicant.service.mk +++ wpa_supplicant.service.mk @@ -1,10 +1,6 @@ -.if exists(/usr/local/sbin/wpa_supplicant) -DAEMON_wpa_supplicant_COMMAND?=/usr/local/sbin/wpa_supplicant -.elif exists(/usr/sbin/wpa_supplicant) -DAEMON_wpa_supplicant_COMMAND?=/usr/sbin/wpa_supplicant -.endif +DAEMON_wpa_supplicant_COMMAND?=/usr/local/sbin/wpa_supplicant /usr/sbin/wpa_supplicant DAEMON_wpa_supplicant_BACKGROUND?=-B DAEMON_wpa_supplicant_ENABLE?=no DAEMON_wpa_supplicant_FLAGS?=-M -iwlan* -Dbsd -c/etc/wpa_supplicant.conf wpa_supplicant: ${_SERVICE}