14 |
return |
return |
15 |
fi |
fi |
16 |
|
|
17 |
|
# don't run if feature !autosvc was set |
18 |
|
if mqueryfeature "!autosvc" |
19 |
|
then |
20 |
|
echo "!autosvc detected; auto management of services disabled." |
21 |
|
return |
22 |
|
fi |
23 |
|
|
24 |
[[ -z ${service_exec} ]] && service_exec="$(which ${service})" |
[[ -z ${service_exec} ]] && service_exec="$(which ${service})" |
25 |
|
|
26 |
# add service to default runlevels |
# add service to default runlevels |
56 |
return |
return |
57 |
fi |
fi |
58 |
|
|
59 |
[[ -z ${service_exec} ]] && service_exec="$(which ${service})" |
# don't run if feature !autosvc was set |
60 |
|
if mqueryfeature "!autosvc" |
61 |
|
then |
62 |
|
echo "!autosvc detected; auto management of services disabled." |
63 |
|
return |
64 |
|
fi |
65 |
|
|
66 |
|
if [[ -z ${service_exec} ]] |
67 |
|
then |
68 |
|
service_exec="$(which ${service})" |
69 |
|
elif [[ x$(basename ${service_exec}) = x${service_exec} ]] |
70 |
|
then |
71 |
|
# expand full path |
72 |
|
service_exec="$(which ${service_exec})" |
73 |
|
fi |
74 |
|
|
75 |
# only stop the service if ${service_exec} does not exist |
# only stop the service if ${service_exec} does not exist |
76 |
[[ -f ${MROOT}/${service_exec} ]] && return |
[[ -x ${MROOT}/${service_exec} ]] && return |
77 |
|
|
78 |
# del services from runlevel regardless if they exist or not |
# del services from runlevel regardless if they exist or not |
79 |
echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing ${service} from default runlevels ..." |
echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing ${service} from default runlevels ..." |
106 |
return |
return |
107 |
fi |
fi |
108 |
|
|
109 |
|
# don't run if feature !autosvc was set |
110 |
|
if mqueryfeature "!autosvc" |
111 |
|
then |
112 |
|
echo "!autosvc detected; auto management of services disabled." |
113 |
|
return |
114 |
|
fi |
115 |
|
|
116 |
[[ -z ${service_exec} ]] && service_exec="$(which ${service})" |
[[ -z ${service_exec} ]] && service_exec="$(which ${service})" |
117 |
|
|
118 |
# do not stop services on bootstrap or MROOT!=/ |
# do not stop services on bootstrap or MROOT!=/ |
126 |
fi |
fi |
127 |
} |
} |
128 |
|
|
|
|
|
129 |
# adds systemd units to runlevels and starts them |
# adds systemd units to runlevels and starts them |
130 |
# mstartunit service {/path/to/service_exec} |
# mstartunit service {/path/to/service_exec} |
131 |
mstartunit() |
mstartunit() |
132 |
{ |
{ |
133 |
local service="$1" |
local service="$1" |
134 |
local service_exec="$2" |
local service_exec="$2" |
135 |
|
local opts |
136 |
|
|
137 |
# only run if systemd was found |
# only run if systemd was found |
138 |
if [[ ! -x /bin/systemctl ]] |
if [[ ! -x /bin/systemctl ]] && [[ ! -x /usr/bin/systemctl ]] |
139 |
then |
then |
140 |
echo "systemd not found, not adding unit ${service} to runlevels!" |
echo "systemd not found, not adding unit ${service} to runlevels!" |
141 |
return |
return |
142 |
fi |
fi |
143 |
|
|
144 |
# we do not support $MROOT atm |
# don't run if feature !autosvc was set |
145 |
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
if mqueryfeature "!autosvc" |
146 |
then |
then |
147 |
echo "\$MROOT is set, doing nothing!" |
echo "!autosvc detected; auto management of services disabled." |
|
echo "Please add unit ${service} manually to the runlevels!" |
|
|
echo "Run 'systemctl enable ${service}' in your chroot later on." |
|
148 |
return |
return |
149 |
fi |
fi |
150 |
|
|
151 |
|
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
152 |
|
then |
153 |
|
opts="--root ${MROOT}" |
154 |
|
fi |
155 |
|
|
156 |
if [[ -z ${service_exec} ]] |
if [[ -z ${service_exec} ]] |
157 |
then |
then |
158 |
case ${service} in |
case ${service} in |
167 |
# add service to default runlevels |
# add service to default runlevels |
168 |
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..." |
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..." |
169 |
# reload daemon to honor changed unit files |
# reload daemon to honor changed unit files |
170 |
systemctl daemon-reload |
systemctl ${opts} daemon-reload |
171 |
systemctl enable ${service} |
systemctl ${opts} enable ${service} |
172 |
|
|
173 |
# do not start services on bootstrap or MROOT!=/ |
# do not start services on bootstrap or MROOT!=/ |
174 |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
175 |
then |
then |
176 |
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} starting unit ${service} ..." |
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} starting unit ${service} ..." |
177 |
# start or restart the service |
# start or restart the service |
178 |
systemctl try-restart ${service} |
# dont use try-restart, works only with active services! |
179 |
|
systemctl restart ${service} |
180 |
fi |
fi |
181 |
} |
} |
182 |
|
|
186 |
{ |
{ |
187 |
local service="$1" |
local service="$1" |
188 |
local service_exec="$2" |
local service_exec="$2" |
189 |
|
local opts |
190 |
|
|
191 |
# only run if systemd was found |
# only run if systemd was found |
192 |
if [[ ! -x /bin/systemctl ]] |
if [[ ! -x /bin/systemctl ]] && [[ ! -x /usr/bin/systemctl ]] |
193 |
then |
then |
194 |
echo "systemd not found, not removing unit ${service} from runlevels!" |
echo "systemd not found, not removing unit ${service} from runlevels!" |
195 |
return |
return |
196 |
fi |
fi |
197 |
|
|
198 |
# we do not support $MROOT atm |
# don't run if feature !autosvc was set |
199 |
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
if mqueryfeature "!autosvc" |
200 |
then |
then |
201 |
echo "\$MROOT is set, doing nothing!" |
echo "!autosvc detected; auto management of services disabled." |
|
echo "Please remove unit ${service} manually from the runlevels!" |
|
|
echo "Run 'systemctl disable ${service}' in your chroot later on." |
|
202 |
return |
return |
203 |
fi |
fi |
204 |
|
|
205 |
|
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
206 |
|
then |
207 |
|
opts="--root ${MROOT}" |
208 |
|
fi |
209 |
|
|
210 |
if [[ -z ${service_exec} ]] |
if [[ -z ${service_exec} ]] |
211 |
then |
then |
212 |
case ${service} in |
case ${service} in |
216 |
*.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;; |
*.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;; |
217 |
*) service_exec="$(which ${service} 2> /dev/null)" ;; |
*) service_exec="$(which ${service} 2> /dev/null)" ;; |
218 |
esac |
esac |
219 |
|
elif [[ x$(basename ${service_exec}) = x${service_exec} ]] |
220 |
|
then |
221 |
|
# expand full path |
222 |
|
service_exec="$(which ${service_exec})" |
223 |
fi |
fi |
224 |
|
|
225 |
# only stop the service if ${service_exec} does not exist |
# only stop the service if ${service_exec} does not exist |
226 |
[[ -f ${MROOT}/${service_exec} ]] && return |
[[ -x ${MROOT}/${service_exec} ]] && return |
227 |
|
|
228 |
# del services from runlevel regardless if they exist or not |
# del services from runlevel regardless if they exist or not |
229 |
echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..." |
echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..." |
230 |
# reload daemon to honor changed unit files |
# reload daemon to honor changed unit files |
231 |
systemctl daemon-reload |
systemctl ${opts} daemon-reload |
232 |
systemctl disable ${service} |
systemctl ${opts} disable ${service} |
233 |
|
|
234 |
# do not stop services on bootstrap or MROOT!=/ |
# do not stop services on bootstrap or MROOT!=/ |
235 |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
252 |
{ |
{ |
253 |
local service="$1" |
local service="$1" |
254 |
local service_exec="$2" |
local service_exec="$2" |
255 |
|
local opts |
256 |
|
|
257 |
# only run if systemd was found |
# only run if systemd was found |
258 |
if [[ ! -x /bin/systemctl ]] |
if [[ ! -x /bin/systemctl ]] && [[ ! -x /usr/bin/systemctl ]] |
259 |
then |
then |
260 |
echo "systemd not found, not removing unit ${service} from runlevels!" |
echo "systemd not found, not removing unit ${service} from runlevels!" |
261 |
return |
return |
262 |
fi |
fi |
263 |
|
|
264 |
# we do not support $MROOT atm |
# don't run if feature !autosvc was set |
265 |
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
if mqueryfeature "!autosvc" |
266 |
then |
then |
267 |
echo "\$MROOT is set, doing nothing!" |
echo "!autosvc detected; auto management of services disabled." |
|
echo "Please remove unit ${service} manually from the runlevels!" |
|
|
echo "Run 'systemctl disable ${service}' in your chroot later on." |
|
268 |
return |
return |
269 |
fi |
fi |
270 |
|
|
271 |
|
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
272 |
|
then |
273 |
|
opts="--root ${MROOT}" |
274 |
|
fi |
275 |
|
|
276 |
if [[ -z ${service_exec} ]] |
if [[ -z ${service_exec} ]] |
277 |
then |
then |
278 |
case ${service} in |
case ${service} in |
284 |
esac |
esac |
285 |
fi |
fi |
286 |
|
|
287 |
|
# reload daemon to honor changed unit files |
288 |
|
systemctl ${opts} daemon-reload |
289 |
|
|
290 |
# do not stop services on bootstrap or MROOT!=/ |
# do not stop services on bootstrap or MROOT!=/ |
291 |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
292 |
then |
then |