# $Id$ provide basic-init systemd require basic-system set_system_service() { local command="$1" local service="$2" local opts="$3" [[ -z ${command} ]] && help_system_service && return 1 [[ -z ${service} ]] && help_system_service && return 1 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}' unkown!" 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}" ;; reload) ${chrooted} systemctl reload-or-try-restart "${service}" ;; enable) ${chrooted} systemctl enable "${service}" ;; disable) ${chrooted} systemctl disable "${service}" ;; *) help_system_service && return ;; esac } get_system_service() { local command="$1" local service="$2" [[ -z ${command} ]] && help_system_service && return 1 [[ -z ${service} ]] && help_system_service && return 1 local chrooted if [[ -n ${MROOT} ]] && [[ ${MROOT} != / ]] then chrooted="system_chroot" case ${command} in status) 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}' unkown!" return 1 fi case "${command}" in status) ${chrooted} systemctl status "${service}" ;; enabled) ${chrooted} systemctl is-enabled "${service}"; rvecho "$?" ;; runlevel) rvecho "$(readline ${MROOT}/etc/systemd/system/default.target)" ;; *) help_system_service && return ;; esac }