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!=/ |
133 |
local service="$1" |
local service="$1" |
134 |
local service_exec="$2" |
local service_exec="$2" |
135 |
local opts |
local opts |
136 |
|
local chroot |
137 |
|
|
138 |
# only run if systemd was found |
# only run if systemd was found |
139 |
if [[ ! -x /bin/systemctl ]] |
if [[ ! -x /bin/systemctl ]] && [[ ! -x /usr/bin/systemctl ]] |
140 |
then |
then |
141 |
echo "systemd not found, not adding unit ${service} to runlevels!" |
echo "systemd not found, not adding unit ${service} to runlevels!" |
142 |
return |
return |
143 |
fi |
fi |
144 |
|
|
145 |
|
# don't run if feature !autosvc was set |
146 |
|
if mqueryfeature "!autosvc" |
147 |
|
then |
148 |
|
echo "!autosvc detected; auto management of services disabled." |
149 |
|
return |
150 |
|
fi |
151 |
|
|
152 |
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
153 |
then |
then |
154 |
opts="--root ${MROOT}" |
# symlinks root path too, not exactly what we want |
155 |
|
#opts="--root ${MROOT}" |
156 |
|
if [ -x $(type -P systemd-nspawn) ] |
157 |
|
then |
158 |
|
chroot="$(type -P systemd-nspawn)" |
159 |
|
else |
160 |
|
chroot="chroot" |
161 |
|
fi |
162 |
fi |
fi |
163 |
|
|
164 |
if [[ -z ${service_exec} ]] |
if [[ -z ${service_exec} ]] |
175 |
# add service to default runlevels |
# add service to default runlevels |
176 |
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..." |
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..." |
177 |
# reload daemon to honor changed unit files |
# reload daemon to honor changed unit files |
178 |
systemctl ${opts} daemon-reload |
if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
179 |
systemctl ${opts} enable ${service} |
then |
180 |
|
systemctl ${opts} daemon-reload |
181 |
|
fi |
182 |
|
${chroot} systemctl ${opts} enable ${service} |
183 |
|
|
184 |
# do not start services on bootstrap or MROOT!=/ |
# do not start services on bootstrap or MROOT!=/ |
185 |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
200 |
local opts |
local opts |
201 |
|
|
202 |
# only run if systemd was found |
# only run if systemd was found |
203 |
if [[ ! -x /bin/systemctl ]] |
if [[ ! -x /bin/systemctl ]] && [[ ! -x /usr/bin/systemctl ]] |
204 |
then |
then |
205 |
echo "systemd not found, not removing unit ${service} from runlevels!" |
echo "systemd not found, not removing unit ${service} from runlevels!" |
206 |
return |
return |
207 |
fi |
fi |
208 |
|
|
209 |
|
# don't run if feature !autosvc was set |
210 |
|
if mqueryfeature "!autosvc" |
211 |
|
then |
212 |
|
echo "!autosvc detected; auto management of services disabled." |
213 |
|
return |
214 |
|
fi |
215 |
|
|
216 |
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
217 |
then |
then |
218 |
opts="--root ${MROOT}" |
opts="--root ${MROOT}" |
227 |
*.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;; |
*.target) service_exec="$(which ${service%%.target} 2> /dev/null)" ;; |
228 |
*) service_exec="$(which ${service} 2> /dev/null)" ;; |
*) service_exec="$(which ${service} 2> /dev/null)" ;; |
229 |
esac |
esac |
230 |
|
elif [[ x$(basename ${service_exec}) = x${service_exec} ]] |
231 |
|
then |
232 |
|
# expand full path |
233 |
|
service_exec="$(which ${service_exec})" |
234 |
fi |
fi |
235 |
|
|
236 |
# only stop the service if ${service_exec} does not exist |
# only stop the service if ${service_exec} does not exist |
237 |
[[ -f ${MROOT}/${service_exec} ]] && return |
[[ -x ${MROOT}/${service_exec} ]] && return |
238 |
|
|
239 |
# del services from runlevel regardless if they exist or not |
# del services from runlevel regardless if they exist or not |
240 |
echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..." |
echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..." |
266 |
local opts |
local opts |
267 |
|
|
268 |
# only run if systemd was found |
# only run if systemd was found |
269 |
if [[ ! -x /bin/systemctl ]] |
if [[ ! -x /bin/systemctl ]] && [[ ! -x /usr/bin/systemctl ]] |
270 |
then |
then |
271 |
echo "systemd not found, not removing unit ${service} from runlevels!" |
echo "systemd not found, not removing unit ${service} from runlevels!" |
272 |
return |
return |
273 |
fi |
fi |
274 |
|
|
275 |
|
# don't run if feature !autosvc was set |
276 |
|
if mqueryfeature "!autosvc" |
277 |
|
then |
278 |
|
echo "!autosvc detected; auto management of services disabled." |
279 |
|
return |
280 |
|
fi |
281 |
|
|
282 |
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
283 |
then |
then |
284 |
opts="--root ${MROOT}" |
opts="--root ${MROOT}" |