Contents of /branches/magellan-next/include/mtools.minc
Parent Directory | Revision Log
Revision 28 -
(show annotations)
(download)
Fri Aug 26 22:18:48 2011 UTC (13 years, 1 month ago) by niro
File size: 7329 byte(s)
Fri Aug 26 22:18:48 2011 UTC (13 years, 1 month ago) by niro
File size: 7329 byte(s)
-reload systemd daemon on service reload too, to get changes in unit files
1 | # $Id$ |
2 | |
3 | # adds services to runlevels and starts them |
4 | # mstartservice service {/path/to/service_exec} |
5 | mstartservice() |
6 | { |
7 | local service="$1" |
8 | local service_exec="$2" |
9 | |
10 | # only run if sysV init was found |
11 | if [[ ! -f /etc/rc.d/init.d/functions ]] |
12 | then |
13 | echo "sysV init not found, not adding service ${service} to runlevels!" |
14 | return |
15 | fi |
16 | |
17 | [[ -z ${service_exec} ]] && service_exec="$(which ${service})" |
18 | |
19 | # add service to default runlevels |
20 | echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding ${service} to default runlevels ..." |
21 | [[ -x ${MROOT}/etc/rc.d/init.d/${service} ]] && rc-config add ${service} &> /dev/null |
22 | |
23 | # do not start services on bootstrap or MROOT!=/ |
24 | if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
25 | then |
26 | # start service |
27 | if [[ -n $(pidof ${service_exec}) ]] |
28 | then |
29 | # restart service |
30 | /etc/init.d/${service} restart |
31 | else |
32 | # start service |
33 | /etc/init.d/${service} start |
34 | fi |
35 | fi |
36 | } |
37 | |
38 | # removes services from runlevels and stops them |
39 | # mstopservice service {/path/to/service_exec} |
40 | mstopservice() |
41 | { |
42 | local service="$1" |
43 | local service_exec="$2" |
44 | |
45 | # only run if sysV init was found |
46 | if [[ ! -f /etc/rc.d/init.d/functions ]] |
47 | then |
48 | echo "sysV init not found, not adding service ${service} to runlevels!" |
49 | return |
50 | fi |
51 | |
52 | [[ -z ${service_exec} ]] && service_exec="$(which ${service})" |
53 | |
54 | # only stop the service if ${service_exec} does not exist |
55 | [[ -f ${MROOT}/${service_exec} ]] && return |
56 | |
57 | # del services from runlevel regardless if they exist or not |
58 | echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing ${service} from default runlevels ..." |
59 | rc-config del ${service} &> /dev/null |
60 | |
61 | # do not stop services on bootstrap or MROOT!=/ |
62 | if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
63 | then |
64 | # stop service if running |
65 | if [[ -n $(pidof ${service_exec}) ]] |
66 | then |
67 | killall -15 ${service_exec} &> /dev/null |
68 | sleep 1 |
69 | killall -9 ${service_exec} &> /dev/null |
70 | fi |
71 | fi |
72 | } |
73 | |
74 | # reloads a service if already running |
75 | # mreloadservice service {/path/to/service_exec} |
76 | mreloadservice() |
77 | { |
78 | local service="$1" |
79 | local service_exec="$2" |
80 | |
81 | # only run if sysV init was found |
82 | if [[ ! -f /etc/rc.d/init.d/functions ]] |
83 | then |
84 | echo "sysV init not found, not adding service ${service} to runlevels!" |
85 | return |
86 | fi |
87 | |
88 | [[ -z ${service_exec} ]] && service_exec="$(which ${service})" |
89 | |
90 | # do not stop services on bootstrap or MROOT!=/ |
91 | if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
92 | then |
93 | # only reload the service if running |
94 | if [[ -n $(pidof ${service_exec}) ]] |
95 | then |
96 | /etc/init.d/${service} reload |
97 | fi |
98 | fi |
99 | } |
100 | |
101 | |
102 | # adds systemd units to runlevels and starts them |
103 | # mstartunit service {/path/to/service_exec} |
104 | mstartunit() |
105 | { |
106 | local service="$1" |
107 | local service_exec="$2" |
108 | |
109 | # only run if systemd was found |
110 | if [[ ! -x /bin/systemctl ]] |
111 | then |
112 | echo "systemd not found, not adding unit ${service} to runlevels!" |
113 | return |
114 | fi |
115 | |
116 | # we do not support $MROOT atm |
117 | if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
118 | then |
119 | echo "\$MROOT is set, doing nothing!" |
120 | echo "Please add unit ${service} manually to the runlevels!" |
121 | echo "Run 'systemctl enable ${service}' in your chroot later on." |
122 | return |
123 | fi |
124 | |
125 | if [[ -z ${service_exec} ]] |
126 | then |
127 | case ${service} in |
128 | *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;; |
129 | *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;; |
130 | *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;; |
131 | *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;; |
132 | *) service_exec="$(which ${service} 2> /dev/null)" ;; |
133 | esac |
134 | fi |
135 | |
136 | # add service to default runlevels |
137 | echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..." |
138 | # reload daemon to honor changed unit files |
139 | systemctl daemon-reload |
140 | systemctl enable ${service} |
141 | |
142 | # do not start services on bootstrap or MROOT!=/ |
143 | if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
144 | then |
145 | echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} starting unit ${service} ..." |
146 | # start or restart the service |
147 | # dont use try-restart, works only with active services! |
148 | systemctl restart ${service} |
149 | fi |
150 | } |
151 | |
152 | # removes systemd units from runlevels and stops them |
153 | # mstopunit service {/path/to/service_exec} |
154 | mstopunit() |
155 | { |
156 | local service="$1" |
157 | local service_exec="$2" |
158 | |
159 | # only run if systemd was found |
160 | if [[ ! -x /bin/systemctl ]] |
161 | then |
162 | echo "systemd not found, not removing unit ${service} from runlevels!" |
163 | return |
164 | fi |
165 | |
166 | # we do not support $MROOT atm |
167 | if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
168 | then |
169 | echo "\$MROOT is set, doing nothing!" |
170 | echo "Please remove unit ${service} manually from the runlevels!" |
171 | echo "Run 'systemctl disable ${service}' in your chroot later on." |
172 | return |
173 | fi |
174 | |
175 | if [[ -z ${service_exec} ]] |
176 | then |
177 | case ${service} in |
178 | *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;; |
179 | *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;; |
180 | *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;; |
181 | *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;; |
182 | *) service_exec="$(which ${service} 2> /dev/null)" ;; |
183 | esac |
184 | fi |
185 | |
186 | # only stop the service if ${service_exec} does not exist |
187 | [[ -f ${MROOT}/${service_exec} ]] && return |
188 | |
189 | # del services from runlevel regardless if they exist or not |
190 | echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..." |
191 | # reload daemon to honor changed unit files |
192 | systemctl daemon-reload |
193 | systemctl disable ${service} |
194 | |
195 | # do not stop services on bootstrap or MROOT!=/ |
196 | if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
197 | then |
198 | echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} stopping unit ${service} ..." |
199 | systemctl stop ${service} |
200 | # try harder |
201 | if [[ -n $(pidof ${service_exec}) ]] |
202 | then |
203 | killall -15 ${service_exec} &> /dev/null |
204 | sleep 1 |
205 | killall -9 ${service_exec} &> /dev/null |
206 | fi |
207 | fi |
208 | } |
209 | |
210 | # reloads a systemd unit if already running |
211 | # mreloadunit service {/path/to/service_exec} |
212 | mreloadunit() |
213 | { |
214 | local service="$1" |
215 | local service_exec="$2" |
216 | |
217 | # only run if systemd was found |
218 | if [[ ! -x /bin/systemctl ]] |
219 | then |
220 | echo "systemd not found, not removing unit ${service} from runlevels!" |
221 | return |
222 | fi |
223 | |
224 | # we do not support $MROOT atm |
225 | if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
226 | then |
227 | echo "\$MROOT is set, doing nothing!" |
228 | echo "Please remove unit ${service} manually from the runlevels!" |
229 | echo "Run 'systemctl disable ${service}' in your chroot later on." |
230 | return |
231 | fi |
232 | |
233 | if [[ -z ${service_exec} ]] |
234 | then |
235 | case ${service} in |
236 | *.service) service_exec="$(which ${service%%.service} 2> /dev/null)" ;; |
237 | *.socket) service_exec="$(which ${service%%.socket} 2> /dev/null)" ;; |
238 | *.mount) service_exec="$(which ${service%%.mount} 2> /dev/null)" ;; |
239 | *.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;; |
240 | *) service_exec="$(which ${service} 2> /dev/null)" ;; |
241 | esac |
242 | fi |
243 | |
244 | # reload daemon to honor changed unit files |
245 | systemctl daemon-reload |
246 | |
247 | # do not stop services on bootstrap or MROOT!=/ |
248 | if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
249 | then |
250 | # only reload the service if running |
251 | systemctl reload-or-try-restart ${service} |
252 | fi |
253 | } |