]> git.pld-linux.org Git - projects/rc-scripts.git/commitdiff
- detect if service is in systemd (if LoadError means it's not present in systemd)
authorElan Ruusamäe <glen@pld-linux.org>
Sat, 17 Mar 2012 08:39:11 +0000 (08:39 +0000)
committerElan Ruusamäe <glen@pld-linux.org>
Sat, 17 Mar 2012 08:39:11 +0000 (08:39 +0000)
- add --no-systemd option to override detect

svn-id: @12494

service

diff --git a/service b/service
index 3c3071caed0934069fd6f97c9932915a6801b90d..cf7b1bc73b07f2be7287a6caddea6bbe24f87502 100755 (executable)
--- a/service
+++ b/service
@@ -16,6 +16,18 @@ is_ignored_file() {
        return 1
 }
 
+# check if SERVICE is present in systemd
+# returns false if systemd is disabled or not active
+is_systemd_service() {
+       local SERVICE=$1
+
+       [ "$USE_SYSTEMD" = "no" ] && return 1
+       [ -x /bin/systemd_booted ] || return 1
+       /bin/systemd_booted || return 1
+
+       /bin/systemctl show "$SERVICE".service | grep -q LoadError= && return 1 || return 0
+}
+
 status_all() {
        local SERVICE TYPE
        cd ${SERVICEDIR}
@@ -62,6 +74,7 @@ USAGE="Usage: $(basename $0) < option > | --status-all | \
 
 SERVICE=
 USE_UPSTART=
+USE_SYSTEMD=
 
 if [ -d /etc/rc.d/init.d ]; then
        SERVICEDIR="/etc/rc.d/init.d"
@@ -101,6 +114,10 @@ while [ $# -gt 0 ]; do
                USE_UPSTART=no
                shift
                ;;
+       --no-systemd)
+               USE_SYSTEMD=no
+               shift
+               ;;
          *)
                if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ]; then
                        status_all
@@ -124,7 +141,7 @@ while [ $# -gt 0 ]; do
        esac
 done
 
-if [ -x /bin/systemd_booted ] && /bin/systemd_booted; then
+if is_systemd_service "${SERVICE}"; then
        echo >&2 "Redirecting to /bin/systemctl ${ACTION} ${SERVICE}.service ${OPTIONS}"
        exec /bin/systemctl ${ACTION} ${SERVICE}.service ${OPTIONS}
 elif [ -x "${SERVICEDIR}/${SERVICE}" ]; then
This page took 0.169071 seconds and 4 git commands to generate.