d8511a3d7c 2022-05-30 1: OTHER_TARGETS+=_service_pre
d8511a3d7c 2022-05-30 2:
d8511a3d7c 2022-05-30 3: STARTER?=svc
d8511a3d7c 2022-05-30 4:
04f7295047 2022-05-30 5: _service_check: .USEBEFORE
d8511a3d7c 2022-05-30 6: # check whether service is enabled
4d5a9b2632 2022-05-30 7: if [ -z "$${DAEMON_$@_ENABLE}" -a -z "${FORCE}" ]; then \
4d5a9b2632 2022-05-30 8: exit 0 ;\
adf4eb9997 2023-11-04 9: fi
adf4eb9997 2023-11-04 10: # check for first present executable
5066f4e4fd 2023-11-04 11: for CHECK_CMD in ${DAEMON_$@_COMMAND}; do \
5066f4e4fd 2023-11-04 12: if [ -x $${CHECK_CMD} ]; then \
5066f4e4fd 2023-11-04 13: export CMD="$${CHECK_CMD}" ;\
cbff0b494f 2023-08-18 14: break ;\
cbff0b494f 2023-08-18 15: fi ;\
adf4eb9997 2023-11-04 16: done
adf4eb9997 2023-11-04 17: # bail out if binary not found
adf4eb9997 2023-11-04 18: if [ -z $${CMD} ]; then \
5066f4e4fd 2023-11-04 19: echo "MRC:$@> Executable not found." ;\
adf4eb9997 2023-11-04 20: exit 0 ;\
adf4eb9997 2023-11-04 21: fi
1ae31ed8a2 2025-03-10 22:
1ae31ed8a2 2025-03-10 23: _service_check_start: .USEBEFORE
adf4eb9997 2023-11-04 24: # check for rtprio/idprio
adf4eb9997 2023-11-04 25: if [ -n "$${DAEMON_$@_IDPRIO}" ]; then \
adf4eb9997 2023-11-04 26: export CMD="/usr/sbin/idprio $${DAEMON_$@_IDPRIO} $${CMD}" ;\
adf4eb9997 2023-11-04 27: elif [ -n "$${DAEMON_$@_RTPRIO}" ]; then \
adf4eb9997 2023-11-04 28: export CMD="/usr/sbin/rtprio $${DAEMON_$@_RTPRIO} $${CMD}" ;\
adf4eb9997 2023-11-04 29: fi
d8511a3d7c 2022-05-30 30:
04f7295047 2022-05-30 31: _service_pre: .USEBEFORE
d8511a3d7c 2022-05-30 32: # kldload modules if any
cbff0b494f 2023-08-18 33: echo "MRC:$@> Starting service." ;\
d8511a3d7c 2022-05-30 34: if [ -n "${DAEMON_$@_MODULES}" ]; then \
d8511a3d7c 2022-05-30 35: kldload -n ${DAEMON_$@_MODULES}; \
04f7295047 2022-05-30 36: fi
04f7295047 2022-05-30 37:
04f7295047 2022-05-30 38: _service_post_exit: .USE
04f7295047 2022-05-30 39: echo "MRC:${@:S/_exit//}> stopped."
d8511a3d7c 2022-05-30 40:
d8511a3d7c 2022-05-30 41: .for starter_source in ${:!find /etc/mrc -name '*.starter.mk'!:S/\/etc\/mrc\///}
d8511a3d7c 2022-05-30 42: starter:=${starter_source:S/.starter.mk$//}
d8511a3d7c 2022-05-30 43: Starter:=${starter:tu}
d8511a3d7c 2022-05-30 44:
d8511a3d7c 2022-05-30 45: OTHER_TARGETS:=${OTHER_TARGETS} _service_${starter} _service_${starter}_exit _service_${starter}_status
d8511a3d7c 2022-05-30 46:
f2a642cc7a 2025-02-22 47: # here we are inheriting pieces of different targets into one single target, so
f2a642cc7a 2025-02-22 48: # everything is appended in the order, but gets organized a little bit
f2a642cc7a 2025-02-22 49: # differently, all targets with .USEBEFORE are added before current target
f2a642cc7a 2025-02-22 50: # script, so after "_service_pre _service_check" we got that order inverted
f2a642cc7a 2025-02-22 51:
1ae31ed8a2 2025-03-10 52: _SERVICE_${Starter}:=_service_pre DAEMON _service_${starter} _service_check_start _service_check
1ae31ed8a2 2025-03-10 53: _EARLYSERVICE_${Starter}:=_service_pre SERVICE _service_${starter} _service_check_start _service_check
1ae31ed8a2 2025-03-10 54: _SERVICE_${Starter}_EXIT:=_service_${starter}_exit _service_post_exit _service_check
f2a642cc7a 2025-02-22 55:
f2a642cc7a 2025-02-22 56: . if "${STARTER}" == "${starter}"
1ae31ed8a2 2025-03-10 57: _SERVICE:=${_SERVICE_${Starter}}
1ae31ed8a2 2025-03-10 58: _EARLYSERVICE:=${_EARLYSERVICE_${Starter}}
1ae31ed8a2 2025-03-10 59: _SERVICE_EXIT:=${_SERVICE_${Starter}_EXIT}
f2a642cc7a 2025-02-22 60: . endif
f2a642cc7a 2025-02-22 61:
1ae31ed8a2 2025-03-10 62: . export-all
f2a642cc7a 2025-02-22 63: . include "${starter_source}"
d8511a3d7c 2022-05-30 64: .endfor