]>
Commit | Line | Data |
---|---|---|
1eec4672 MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2010 Michael Tremer & Christian Schmidt # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
22 | function service_start() { | |
23 | local name=${1} | |
1eec4672 MT |
24 | assert isset name |
25 | ||
1d08b9b3 | 26 | systemctl start ${name} |
4243f0ca SS |
27 | |
28 | # Check, if the service was successfully started and | |
29 | # return a proper exit code. | |
30 | service_is_active ${name} | |
31 | local ret=$? | |
32 | ||
1d08b9b3 | 33 | log INFO "Started service '${name}', code=${ret}." |
4243f0ca SS |
34 | |
35 | return ${ret} | |
1eec4672 MT |
36 | } |
37 | ||
38 | function service_stop() { | |
39 | local name=${1} | |
1eec4672 MT |
40 | assert isset name |
41 | ||
1d08b9b3 | 42 | systemctl stop ${name} |
1eec4672 MT |
43 | } |
44 | ||
45 | function service_restart() { | |
46 | local name=${1} | |
1eec4672 MT |
47 | assert isset name |
48 | ||
1d08b9b3 | 49 | systemctl restart ${name} |
1eec4672 MT |
50 | } |
51 | ||
52 | function service_reload() { | |
53 | local name=${1} | |
1eec4672 MT |
54 | assert isset name |
55 | ||
56 | if service_status ${name}; then | |
1d08b9b3 | 57 | systemctl reload ${name} |
1eec4672 MT |
58 | return $? |
59 | else | |
60 | log WARNING "Cannot reload service '${name}' which is currently not running." | |
61 | fi | |
62 | } | |
63 | ||
64 | function service_status() { | |
65 | local name=${1} | |
1eec4672 MT |
66 | assert isset name |
67 | ||
1d08b9b3 | 68 | systemctl status ${name} >/dev/null 2>&1 |
1eec4672 MT |
69 | return $? |
70 | } | |
4243f0ca | 71 | |
5c5b8e36 SS |
72 | # This function calls the "enable" command from systemd, |
73 | # to mark services to be automatically started during | |
74 | # boot up. | |
75 | function service_enable() { | |
76 | local name=${1} | |
77 | assert isset name | |
78 | ||
79 | systemctl enable "${name}" >/dev/null 2>&1 | |
80 | } | |
81 | ||
82 | # This function calls the "disable" command of systemd, | |
83 | # to drop the autostart ability of the service during the | |
84 | # boot up. | |
85 | function service_disable() { | |
86 | local name=${1} | |
87 | assert isset name | |
88 | ||
89 | systemctl disable "${name}" >/dev/null 2>&1 | |
90 | } | |
91 | ||
92 | # This function uses the systemd command "is-enabled" to check, | |
93 | # if a service has been enabled or not. | |
94 | function service_is_enabled() { | |
95 | local name="${1}" | |
96 | assert isset name | |
97 | ||
98 | systemctl is-enabled "${name}" >/dev/null 2>&1 | |
99 | return $? | |
100 | } | |
101 | ||
4243f0ca SS |
102 | function service_is_active() { |
103 | local name=${1} | |
4243f0ca SS |
104 | assert isset name |
105 | ||
106 | systemctl is-active ${name}.service >/dev/null 2>&1 | |
107 | return $? | |
108 | } | |
81d0c0b9 MT |
109 | |
110 | function service_get_exitcode() { | |
111 | local name=${1} | |
112 | assert isset name | |
113 | ||
81d0c0b9 MT |
114 | local output=$(systemctl show ${name} --property="ExecMainStatus") |
115 | cli_get_val "${output}" | |
116 | } |