#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2010 Michael Tremer & Christian Schmidt # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### service_start() { local name=${1} assert isset name # Don't start anything if this is already running if service_is_active "${name}"; then return ${EXIT_OK} fi 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}', code=${ret}." return ${ret} } service_stop() { local name="${1}" assert isset name systemctl stop "${name}" } service_restart() { local name="${1}" assert isset name systemctl restart "${name}" } service_reload() { local name="${1}" assert isset name if service_status "${name}"; then systemctl reload "${name}" return $? else log WARNING "Cannot reload service '${name}' which is currently not running." fi } service_status() { local name="${1}" 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. 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. 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. service_is_enabled() { local name="${1}" assert isset name systemctl is-enabled "${name}" >/dev/null 2>&1 return $? } service_is_active() { local name="${1}" assert isset name systemctl is-active "${name}" >/dev/null 2>&1 return $? } service_get_exitcode() { local name=${1} assert isset name local output=$(systemctl show "${name}" --property="ExecMainStatus") cli_get_val "${output}" }