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 |
|
# 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} 2> /dev/null)" |
[[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)" |
53 |
|
|
54 |
# only stop the service if ${service_exec} does not exist |
# only stop the service if ${service_exec} does not exist |
78 |
local service="$1" |
local service="$1" |
79 |
local service_exec="$2" |
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} 2> /dev/null)" |
[[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)" |
89 |
|
|
90 |
# do not stop services on bootstrap or MROOT!=/ |
# do not stop services on bootstrap or MROOT!=/ |
97 |
fi |
fi |
98 |
fi |
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 |
|
[[ -z ${service_exec} ]] && service_exec="$(which ${service})" |
126 |
|
|
127 |
|
# add service to default runlevels |
128 |
|
echo -e " ${COLBLUE}[${COLGREEN}+${COLBLUE}]${COLDEFAULT} adding unit ${service} to default runlevels ..." |
129 |
|
# reload daemon to honor changed unit files |
130 |
|
systemctl daemon-reload |
131 |
|
systemctl enable ${service} |
132 |
|
|
133 |
|
# do not start services on bootstrap or MROOT!=/ |
134 |
|
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
135 |
|
then |
136 |
|
# start or restart the service |
137 |
|
systemctl try-restart ${service} |
138 |
|
fi |
139 |
|
} |
140 |
|
|
141 |
|
# removes systemd units from runlevels and stops them |
142 |
|
# mstopunit service {/path/to/service_exec} |
143 |
|
mstopunit() |
144 |
|
{ |
145 |
|
local service="$1" |
146 |
|
local service_exec="$2" |
147 |
|
|
148 |
|
# only run if systemd was found |
149 |
|
if [[ ! -x /bin/systemctl ]] |
150 |
|
then |
151 |
|
echo "systemd not found, not removing unit ${service} from runlevels!" |
152 |
|
return |
153 |
|
fi |
154 |
|
|
155 |
|
# we do not support $MROOT atm |
156 |
|
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
157 |
|
then |
158 |
|
echo "\$MROOT is set, doing nothing!" |
159 |
|
echo "Please remove unit ${service} manually from the runlevels!" |
160 |
|
echo "Run 'systemctl disable ${service}' in your chroot later on." |
161 |
|
return |
162 |
|
fi |
163 |
|
|
164 |
|
[[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)" |
165 |
|
|
166 |
|
# only stop the service if ${service_exec} does not exist |
167 |
|
[[ -f ${MROOT}/${service_exec} ]] && return |
168 |
|
|
169 |
|
# del services from runlevel regardless if they exist or not |
170 |
|
echo -e " ${COLBLUE}[${COLRED}-${COLBLUE}]${COLDEFAULT} removing unit ${service} from default runlevels ..." |
171 |
|
# reload daemon to honor changed unit files |
172 |
|
systemctl daemon-reload |
173 |
|
systemctl disable ${service} |
174 |
|
|
175 |
|
# do not stop services on bootstrap or MROOT!=/ |
176 |
|
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
177 |
|
then |
178 |
|
systemctl stop ${service} |
179 |
|
# try harder |
180 |
|
if [[ -n $(pidof ${service_exec}) ]] |
181 |
|
then |
182 |
|
killall -15 ${service_exec} &> /dev/null |
183 |
|
sleep 1 |
184 |
|
killall -9 ${service_exec} &> /dev/null |
185 |
|
fi |
186 |
|
fi |
187 |
|
} |
188 |
|
|
189 |
|
# reloads a systemd unit if already running |
190 |
|
# mreloadunit service {/path/to/service_exec} |
191 |
|
mreloadunit() |
192 |
|
{ |
193 |
|
local service="$1" |
194 |
|
local service_exec="$2" |
195 |
|
|
196 |
|
# only run if systemd was found |
197 |
|
if [[ ! -x /bin/systemctl ]] |
198 |
|
then |
199 |
|
echo "systemd not found, not removing unit ${service} from runlevels!" |
200 |
|
return |
201 |
|
fi |
202 |
|
|
203 |
|
# we do not support $MROOT atm |
204 |
|
if [[ ${MROOT} != / ]] && [[ ! -z ${MROOT} ]] |
205 |
|
then |
206 |
|
echo "\$MROOT is set, doing nothing!" |
207 |
|
echo "Please remove unit ${service} manually from the runlevels!" |
208 |
|
echo "Run 'systemctl disable ${service}' in your chroot later on." |
209 |
|
return |
210 |
|
fi |
211 |
|
|
212 |
|
[[ -z ${service_exec} ]] && service_exec="$(which ${service} 2> /dev/null)" |
213 |
|
|
214 |
|
# do not stop services on bootstrap or MROOT!=/ |
215 |
|
if [[ ${MAGE_BOOTSTRAP} != true ]] && [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
216 |
|
then |
217 |
|
# only reload the service if running |
218 |
|
systemctl reload-or-try-restart ${service} |
219 |
|
fi |
220 |
|
} |