Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -1,11 +1,11 @@ .include "defaults.mk" .include "order.mk" .include "/etc/mrc.mk" .export -.MAKE.JOBS?=1 +.MAKE.JOBS?= ${NCPU} .if !empty(.MAKE.MODE:Mcompat) .error "ERROR: MRC doesn't support "compat" mode." .endif OTHER_TARGETS:= @@ -34,27 +34,38 @@ 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}) +. if !target(${service}) ${service}: ${SERVICE_EXIT} ${_SERVICE} -. endif +. endif # Service status targets -. if !target(${service}_status) +. if !target(${service}_status) ${service}_status: ${_SERVICE_STATUS} -. endif +. endif # Service exit targets -. if !target(${service}_exit) +. if !target(${service}_exit) ${service}_exit: ${_SERVICE_EXIT} ${DAEMON_${service}_DEPS:S/$/_exit/} -. endif +. endif DAEMON_EXIT: ${service}_exit +. endif .endfor .MAIN: ${SCRIPTS} ${TARGETS} .PHONY: ${SCRIPTS} ${OTHER_TARGETS} ${TARGETS} Index: daemon.starter.mk ================================================================== --- daemon.starter.mk +++ daemon.starter.mk @@ -1,7 +1,8 @@ _service_daemon: .USE - daemon -c -u ${DAEMON_$@_USER:Uroot} -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 ${DAEMON_$@_COMMAND} ${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 @@ -1,13 +1,16 @@ # vim:ft=make: -# command to start service -DAEMON_example_COMMAND?=/path/service - # flags to force daemonizing DAEMON_example_BACKGROUND?= +# default working directory +DAEMON_example_CWD?=/some/path + +# command to start service +DAEMON_example_COMMAND?=/path/service + # enabled by default? DAEMON_example_ENABLE?=no # general service flags DAEMON_example_FLAGS?= Index: plain.starter.mk ================================================================== --- plain.starter.mk +++ plain.starter.mk @@ -1,7 +1,7 @@ _service_plain: .USE - chroot -u ${DAEMON_$@_USER:Uroot} -g ${DAEMON_$@_GROUP:Uwheel} / ${DAEMON_$@_COMMAND} ${DAEMON_$@_FLAGS} ${DAEMON_$@_BACKGROUND} + chroot -u ${DAEMON_$@_USER} -g ${DAEMON_$@_GROUP} ${DAEMON_$@_CWD} ${DAEMON_$@_COMMAND} ${DAEMON_$@_FLAGS} ${DAEMON_$@_BACKGROUND} _service_status: .USE echo "Plain service status doesn't work right now." _service_exit: .USEBEFORE Index: svc.starter.mk ================================================================== --- svc.starter.mk +++ svc.starter.mk @@ -1,8 +1,9 @@ _service_svc: .USE + cd ${DAEMON_$@_CWD} ;\ svc list $@ | grep -q $@ || \ - svc -u ${DAEMON_$@_USER:Uroot} -g ${DAEMON_$@_GROUP:Uwheel} ${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 $@ ${DAEMON_$@_COMMAND} ${DAEMON_$@_FLAGS} ${DAEMON_$@_FOREGROUND} _service_svc_status: .USE svc status ${@:S/_status//} _service_svc_exit: .USEBEFORE