]> git.ipfire.org Git - network.git/blobdiff - functions.service
Introduce enable/disable option for network zones.
[network.git] / functions.service
index 9d9951748f48f609837358243884e236001d3c7d..6b5b73c9aea14f53c4cb4cb9955cba61ab877733 100644 (file)
 
 function service_start() {
        local name=${1}
-       shift
-
        assert isset name
 
-       systemctl start ${name}.service
+       systemctl start ${name}
 
        # Check, if the service was successfully started and
        # return a proper exit code.
        service_is_active ${name}
        local ret=$?
 
-       log INFO "Started service '${name}.service', code=${ret}."
+       log INFO "Started service '${name}', code=${ret}."
 
        return ${ret}
 }
 
 function service_stop() {
        local name=${1}
-       shift
-
        assert isset name
 
-       systemctl stop ${name}.service
+       systemctl stop ${name}
 }
 
 function service_restart() {
        local name=${1}
-       shift
-
        assert isset name
 
-       systemctl restart ${name}.service
+       systemctl restart ${name}
 }
 
 function service_reload() {
        local name=${1}
-       shift
-
        assert isset name
 
        if service_status ${name}; then
-               systemctl reload ${name}.service
+               systemctl reload ${name}
                return $?
        else
                log WARNING "Cannot reload service '${name}' which is currently not running."
@@ -71,20 +63,54 @@ function service_reload() {
 
 function service_status() {
        local name=${1}
-       shift
+       assert isset name
+
+       systemctl status ${name} >/dev/null 2>&1
+       return $?
+}
+
+# This function calls the "enable" command from systemd,
+# to mark services to be automatically started during
+# boot up.
+function service_enable() {
+       local name=${1}
+       assert isset name
+
+       systemctl enable "${name}" >/dev/null 2>&1
+}
+
+# This function calls the "disable" command of systemd,
+# to drop the autostart ability of the service during the
+# boot up.
+function service_disable() {
+       local name=${1}
+       assert isset name
+
+       systemctl disable "${name}" >/dev/null 2>&1
+}
 
+# This function uses the systemd command "is-enabled" to check,
+# if a service has been enabled or not.
+function service_is_enabled() {
+       local name="${1}"
        assert isset name
 
-       systemctl status ${name}.service >/dev/null 2>&1
+       systemctl is-enabled "${name}" >/dev/null 2>&1
        return $?
 }
 
 function service_is_active() {
        local name=${1}
-       shift
-
        assert isset name
 
        systemctl is-active ${name}.service >/dev/null 2>&1
        return $?
 }
+
+function service_get_exitcode() {
+       local name=${1}
+       assert isset name
+
+       local output=$(systemctl show ${name} --property="ExecMainStatus")
+       cli_get_val "${output}"
+}