]>
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} | |
24 | shift | |
25 | ||
26 | assert isset name | |
27 | ||
28 | systemctl start ${name}.service | |
4243f0ca SS |
29 | |
30 | # Check, if the service was successfully started and | |
31 | # return a proper exit code. | |
32 | service_is_active ${name} | |
33 | local ret=$? | |
34 | ||
35 | log INFO "Started service '${name}.service', code=${ret}." | |
36 | ||
37 | return ${ret} | |
1eec4672 MT |
38 | } |
39 | ||
40 | function service_stop() { | |
41 | local name=${1} | |
42 | shift | |
43 | ||
44 | assert isset name | |
45 | ||
46 | systemctl stop ${name}.service | |
47 | } | |
48 | ||
49 | function service_restart() { | |
50 | local name=${1} | |
51 | shift | |
52 | ||
53 | assert isset name | |
54 | ||
55 | systemctl restart ${name}.service | |
56 | } | |
57 | ||
58 | function service_reload() { | |
59 | local name=${1} | |
60 | shift | |
61 | ||
62 | assert isset name | |
63 | ||
64 | if service_status ${name}; then | |
65 | systemctl reload ${name}.service | |
66 | return $? | |
67 | else | |
68 | log WARNING "Cannot reload service '${name}' which is currently not running." | |
69 | fi | |
70 | } | |
71 | ||
72 | function service_status() { | |
73 | local name=${1} | |
74 | shift | |
75 | ||
76 | assert isset name | |
77 | ||
78 | systemctl status ${name}.service >/dev/null 2>&1 | |
79 | return $? | |
80 | } | |
4243f0ca SS |
81 | |
82 | function service_is_active() { | |
83 | local name=${1} | |
84 | shift | |
85 | ||
86 | assert isset name | |
87 | ||
88 | systemctl is-active ${name}.service >/dev/null 2>&1 | |
89 | return $? | |
90 | } |