d8511a3d7c 2022-05-30 arcade: OTHER_TARGETS+=_service_pre
d8511a3d7c 2022-05-30 arcade:
d8511a3d7c 2022-05-30 arcade: STARTER?=svc
d8511a3d7c 2022-05-30 arcade:
04f7295047 2022-05-30 arcade: _service_check: .USEBEFORE
d8511a3d7c 2022-05-30 arcade: # check whether service is enabled
4d5a9b2632 2022-05-30 arcade: if [ -z "$${DAEMON_$@_ENABLE}" -a -z "${FORCE}" ]; then \
4d5a9b2632 2022-05-30 arcade: exit 0 ;\
adf4eb9997 2023-11-04 arcade: fi
adf4eb9997 2023-11-04 arcade: # check for first present executable
5066f4e4fd 2023-11-04 arcade: for CHECK_CMD in ${DAEMON_$@_COMMAND}; do \
5066f4e4fd 2023-11-04 arcade: if [ -x $${CHECK_CMD} ]; then \
5066f4e4fd 2023-11-04 arcade: export CMD="$${CHECK_CMD}" ;\
cbff0b494f 2023-08-18 arcade: break ;\
cbff0b494f 2023-08-18 arcade: fi ;\
adf4eb9997 2023-11-04 arcade: done
adf4eb9997 2023-11-04 arcade: # bail out if binary not found
adf4eb9997 2023-11-04 arcade: if [ -z $${CMD} ]; then \
5066f4e4fd 2023-11-04 arcade: echo "MRC:$@> Executable not found." ;\
adf4eb9997 2023-11-04 arcade: exit 0 ;\
adf4eb9997 2023-11-04 arcade: fi
1ae31ed8a2 2025-03-10 arcade:
1ae31ed8a2 2025-03-10 arcade: _service_check_start: .USEBEFORE
adf4eb9997 2023-11-04 arcade: # check for rtprio/idprio
adf4eb9997 2023-11-04 arcade: if [ -n "$${DAEMON_$@_IDPRIO}" ]; then \
adf4eb9997 2023-11-04 arcade: export CMD="/usr/sbin/idprio $${DAEMON_$@_IDPRIO} $${CMD}" ;\
adf4eb9997 2023-11-04 arcade: elif [ -n "$${DAEMON_$@_RTPRIO}" ]; then \
adf4eb9997 2023-11-04 arcade: export CMD="/usr/sbin/rtprio $${DAEMON_$@_RTPRIO} $${CMD}" ;\
adf4eb9997 2023-11-04 arcade: fi
d8511a3d7c 2022-05-30 arcade:
04f7295047 2022-05-30 arcade: _service_pre: .USEBEFORE
d8511a3d7c 2022-05-30 arcade: # kldload modules if any
cbff0b494f 2023-08-18 arcade: echo "MRC:$@> Starting service." ;\
d8511a3d7c 2022-05-30 arcade: if [ -n "${DAEMON_$@_MODULES}" ]; then \
d8511a3d7c 2022-05-30 arcade: kldload -n ${DAEMON_$@_MODULES}; \
04f7295047 2022-05-30 arcade: fi
04f7295047 2022-05-30 arcade:
04f7295047 2022-05-30 arcade: _service_post_exit: .USE
04f7295047 2022-05-30 arcade: echo "MRC:${@:S/_exit//}> stopped."
d8511a3d7c 2022-05-30 arcade:
d8511a3d7c 2022-05-30 arcade: .for starter_source in ${:!find /etc/mrc -name '*.starter.mk'!:S/\/etc\/mrc\///}
d8511a3d7c 2022-05-30 arcade: starter:=${starter_source:S/.starter.mk$//}
d8511a3d7c 2022-05-30 arcade: Starter:=${starter:tu}
d8511a3d7c 2022-05-30 arcade:
d8511a3d7c 2022-05-30 arcade: OTHER_TARGETS:=${OTHER_TARGETS} _service_${starter} _service_${starter}_exit _service_${starter}_status
d8511a3d7c 2022-05-30 arcade:
f2a642cc7a 2025-02-22 arcade: # here we are inheriting pieces of different targets into one single target, so
f2a642cc7a 2025-02-22 arcade: # everything is appended in the order, but gets organized a little bit
f2a642cc7a 2025-02-22 arcade: # differently, all targets with .USEBEFORE are added before current target
f2a642cc7a 2025-02-22 arcade: # script, so after "_service_pre _service_check" we got that order inverted
f2a642cc7a 2025-02-22 arcade:
1ae31ed8a2 2025-03-10 arcade: _SERVICE_${Starter}:=_service_pre DAEMON _service_${starter} _service_check_start _service_check
1ae31ed8a2 2025-03-10 arcade: _EARLYSERVICE_${Starter}:=_service_pre SERVICE _service_${starter} _service_check_start _service_check
1ae31ed8a2 2025-03-10 arcade: _SERVICE_${Starter}_EXIT:=_service_${starter}_exit _service_post_exit _service_check
f2a642cc7a 2025-02-22 arcade:
f2a642cc7a 2025-02-22 arcade: . if "${STARTER}" == "${starter}"
1ae31ed8a2 2025-03-10 arcade: _SERVICE:=${_SERVICE_${Starter}}
1ae31ed8a2 2025-03-10 arcade: _EARLYSERVICE:=${_EARLYSERVICE_${Starter}}
1ae31ed8a2 2025-03-10 arcade: _SERVICE_EXIT:=${_SERVICE_${Starter}_EXIT}
f2a642cc7a 2025-02-22 arcade: . endif
f2a642cc7a 2025-02-22 arcade:
1ae31ed8a2 2025-03-10 arcade: . export-all
f2a642cc7a 2025-02-22 arcade: . include "${starter_source}"
d8511a3d7c 2022-05-30 arcade: .endfor