#!/bin/bash MCORE_LIBDIR="@@MCORE_LIBDIR@@" source @@SYSCONFDIR@@/mcore/mcore.conf source ${MCORE_LIBDIR}/include/common.global.class source ${MCORE_LIBDIR}/include/daemon.global.class die() { echo "ERROR: $@"; exit 1; } control_service() { local command="$1" local service="$2" local chrooted if [[ -n ${MROOT} ]] && [[ ${MROOT} != / ]] then chrooted="system_chroot" case ${command} in start|stop|restart|reload) eecho "Command not available while \$MROOT is set" return 1 ;; esac fi if [[ -n $(${chrooted} systemctl status ${service} | grep 'Reason: No such file or directory') ]] then eecho "Service '${service}' unknown!" return 1 fi # auto-append .service to fix issues while $MROOT is set if [[ -n $(echo ${service} | grep -v '.service$\|.target$\|.mount$\|.socket$\|.timer$') ]] then service="${service}.service" decho "\$service replaced with '${service}'" fi case "${command}" in start) ${chrooted} systemctl start "${service}" ;; stop) ${chrooted} systemctl stop "${service}" ;; #restart) ${chrooted} systemctl try-restart "${service}" ;; restart) ${chrooted} systemctl restart "${service}" ;; reload) ${chrooted} systemctl reload-or-try-restart "${service}" ;; enable) ${chrooted} systemctl enable "${service}" ;; disable) ${chrooted} systemctl disable "${service}" ;; status) ${chrooted} systemctl status "${service}" ;; enabled) ${chrooted} systemctl is-enabled "${service}"; rvecho "$?" ;; runlevel) rvecho "$(readline ${MROOT}@@SYSTEMDSYSTEMCONFDIR@@/default.target)" ;; *) return 1 ;; esac } # very basic getops for argv in $* do case $1 in --start|--stop|--restart|--reload|--enable|--disable|--status|--enabled|--runlevel) command="${1//--}" ;; --service) shift; service="$1" ;; esac shift done [[ -n ${command} ]] || die "No command given" control_service "${command}" "${service}"