1 |
# $Header: /magellan-cvs/mage/include/mtools.minc,v 1.3 2008/02/10 12:13:56 niro Exp $ |
# $Id$ |
2 |
|
|
3 |
# adds services to runlevels and starts them |
# adds services to runlevels and starts them |
4 |
# mstartservice service {/path/to/service_exec} |
# mstartservice service {/path/to/service_exec} |
7 |
local service="$1" |
local service="$1" |
8 |
local service_exec="$2" |
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})" |
[[ -z ${service_exec} ]] && service_exec="$(which ${service})" |
18 |
|
|
19 |
# add service to default runlevels |
# add service to default runlevels |
42 |
local service="$1" |
local service="$1" |
43 |
local service_exec="$2" |
local service_exec="$2" |
44 |
|
|
45 |
[[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)" |
# 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 |
# only stop the service if ${service_exec} does not exist |
55 |
[[ -f ${MROOT}/${service_exec} ]] && return |
[[ -f ${MROOT}/${service_exec} ]] && return |
78 |
local service="$1" |
local service="$1" |
79 |
local service_exec="$2" |
local service_exec="$2" |
80 |
|
|
81 |
[[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)" |
# 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!=/ |
# do not stop services on bootstrap or MROOT!=/ |
91 |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
114 |
fi |
fi |
115 |
|
|
116 |
# we do not support $MROOT atm |
# we do not support $MROOT atm |
117 |
if [[ ${MROOT} != / ]] || [[ ! -z ${MROOT} ]] |
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
118 |
then |
then |
119 |
echo "\$MROOT is set, doing nothing!" |
echo "\$MROOT is set, doing nothing!" |
120 |
echo "Please add unit ${service} manually to the runlevels!" |
echo "Please add unit ${service} manually to the runlevels!" |
122 |
return |
return |
123 |
fi |
fi |
124 |
|
|
125 |
[[ -z ${service_exec} ]] && service_exec="$(which ${service})" |
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 |
# add service to default runlevels |
137 |
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..." |
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..." |
142 |
# do not start services on bootstrap or MROOT!=/ |
# do not start services on bootstrap or MROOT!=/ |
143 |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
144 |
then |
then |
145 |
|
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} starting unit ${service} ..." |
146 |
# start or restart the service |
# start or restart the service |
147 |
systemctl try-restart ${service} |
# dont use try-restart, works only with active services! |
148 |
|
systemctl restart ${service} |
149 |
fi |
fi |
150 |
} |
} |
151 |
|
|
164 |
fi |
fi |
165 |
|
|
166 |
# we do not support $MROOT atm |
# we do not support $MROOT atm |
167 |
if [[ ${MROOT} != / ]] || [[ ! -z ${MROOT} ]] |
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
168 |
then |
then |
169 |
echo "\$MROOT is set, doing nothing!" |
echo "\$MROOT is set, doing nothing!" |
170 |
echo "Please remove unit ${service} manually from the runlevels!" |
echo "Please remove unit ${service} manually from the runlevels!" |
172 |
return |
return |
173 |
fi |
fi |
174 |
|
|
175 |
[[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)" |
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 |
# only stop the service if ${service_exec} does not exist |
187 |
[[ -f ${MROOT}/${service_exec} ]] && return |
[[ -f ${MROOT}/${service_exec} ]] && return |
195 |
# do not stop services on bootstrap or MROOT!=/ |
# do not stop services on bootstrap or MROOT!=/ |
196 |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
197 |
then |
then |
198 |
|
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} stopping unit ${service} ..." |
199 |
systemctl stop ${service} |
systemctl stop ${service} |
200 |
# try harder |
# try harder |
201 |
if [[ -n $(pidof ${service_exec}) ]] |
if [[ -n $(pidof ${service_exec}) ]] |
222 |
fi |
fi |
223 |
|
|
224 |
# we do not support $MROOT atm |
# we do not support $MROOT atm |
225 |
if [[ ${MROOT} != / ]] || [[ ! -z ${MROOT} ]] |
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
226 |
then |
then |
227 |
echo "\$MROOT is set, doing nothing!" |
echo "\$MROOT is set, doing nothing!" |
228 |
echo "Please remove unit ${service} manually from the runlevels!" |
echo "Please remove unit ${service} manually from the runlevels!" |
230 |
return |
return |
231 |
fi |
fi |
232 |
|
|
233 |
[[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)" |
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!=/ |
# do not stop services on bootstrap or MROOT!=/ |
248 |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |