/[vps]/baselayout-vserver/branches/baselayout-1_12/sbin/runscript.sh
Gentoo

Diff of /baselayout-vserver/branches/baselayout-1_12/sbin/runscript.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 275 Revision 276
4 4
5# Common functions 5# Common functions
6[[ ${RC_GOT_FUNCTIONS} != "yes" ]] && source /sbin/functions.sh 6[[ ${RC_GOT_FUNCTIONS} != "yes" ]] && source /sbin/functions.sh
7 7
8# User must be root to run most script stuff (except status) 8# User must be root to run most script stuff (except status)
9if [[ ${EUID} != 0 ]] && ! [[ $2 == "status" && $# -eq 2 ]] ; then 9if [[ ${EUID} != "0" ]] && ! [[ $2 == "status" && $# -eq 2 ]] ; then
10 eerror "$0: must be root to run init scripts" 10 eerror "$0: must be root to run init scripts"
11 exit 1 11 exit 1
12fi 12fi
13 13
14myscript="$1" 14myscript="$1"
15if [[ -L $1 && ! -L "/etc/init.d/${1##*/}" ]] ; then 15if [[ -L $1 && ! -L "/etc/init.d/${1##*/}" ]] ; then
16 myservice="$(readlink "$1")" 16 SVCNAME="$(readlink "$1")"
17else 17else
18 myservice="$1" 18 SVCNAME="$1"
19fi 19fi
20 20
21myservice="${myservice##*/}" 21declare -r SVCNAME="${SVCNAME##*/}"
22export SVCNAME="${myservice}" 22export SVCNAME
23# Support deprecated myservice variable
24myservice="${SVCNAME}"
23 25
24# Stop init scripts from working until sysinit completes 26# Stop init scripts from working until sysinit completes
25if [[ -e /dev/.rcsysinit ]] ; then 27if [[ -e /dev/.rcsysinit ]] ; then
26 eerror "ERROR: cannot run ${myservice} until sysinit completes" 28 eerror "ERROR: cannot run ${SVCNAME} until sysinit completes"
27 exit 1 29 exit 1
28fi 30fi
29 31
30svc_trap() { 32svc_trap() {
31 trap 'eerror "ERROR: ${myservice} caught an interrupt"; exit 1' \ 33 trap 'eerror "ERROR: ${SVCNAME} caught an interrupt"; exit 1' \
32 INT QUIT TSTP 34 INT QUIT TSTP
33} 35}
34 36
35# Setup a default trap 37# Setup a default trap
36svc_trap 38svc_trap
38# State variables 40# State variables
39svcpause="no" 41svcpause="no"
40svcrestart="no" 42svcrestart="no"
41 43
42# Functions to handle dependencies and services 44# Functions to handle dependencies and services
43[[ ${RC_GOT_SERVICES} != "yes" ]] && source "${svclib}/sh/rc-services.sh" 45[[ ${RC_GOT_SVCNAMES} != "yes" ]] && source "${svclib}/sh/rc-services.sh"
44# Functions to control daemons 46# Functions to control daemons
45[[ ${RC_GOT_DAEMON} != "yes" ]] && source "${svclib}/sh/rc-daemon.sh" 47[[ ${RC_GOT_DAEMON} != "yes" ]] && source "${svclib}/sh/rc-daemon.sh"
46 48
47# Set $IFACE to the name of the network interface if it is a 'net.*' script 49if [[ ${SVCNAME%%.*} == "net" && ${SVCNAME#*.} != "${SVCNAME}" ]] ; then
48if [[ ${myservice%%.*} == "net" && ${myservice#*.} != "${myservice}" ]] ; then
49 IFACE="${myservice#*.}"
50 NETSERVICE="yes" 50 NETSERVICE="yes"
51else 51else
52 IFACE=
53 NETSERVICE= 52 NETSERVICE="no"
54fi 53fi
55 54
56# Source configuration files. 55# Source configuration files.
57# (1) Source /etc/conf.d/net if it is a net.* service 56# (1) Source /etc/conf.d/net if it is a net.* service
58# (2) Source /etc/conf.d/${myservice} to get initscript-specific 57# (2) Source /etc/conf.d/${SVCNAME} to get initscript-specific
59# configuration (if it exists). 58# configuration (if it exists).
60# (3) Source /etc/rc.conf to pick up potentially overriding 59# (3) Source /etc/rc.conf to pick up potentially overriding
61# configuration, if the system administrator chose to put it 60# configuration, if the system administrator chose to put it
62# there (if it exists). 61# there (if it exists).
63if [[ ${NETSERVICE} == "yes" ]] ; then 62if [[ ${NETSERVICE} == "yes" ]] ; then
64 conf="$(add_suffix /etc/conf.d/net)" 63 conf="$(add_suffix /etc/conf.d/net)"
65 [[ -e ${conf} ]] && source "${conf}" 64 [[ -e ${conf} ]] && source "${conf}"
66fi 65fi
67conf="$(add_suffix "/etc/conf.d/${myservice}")" 66conf="$(add_suffix "/etc/conf.d/${SVCNAME}")"
68[[ -e ${conf} ]] && source "${conf}" 67[[ -e ${conf} ]] && source "${conf}"
69conf="$(add_suffix /etc/rc.conf)" 68conf="$(add_suffix /etc/rc.conf)"
70[[ -e ${conf} ]] && source "${conf}" 69[[ -e ${conf} ]] && source "${conf}"
71 70
72mylevel="${SOFTLEVEL}" 71mylevel="${SOFTLEVEL}"
73[[ ${SOFTLEVEL} == "${BOOTLEVEL}" \ 72[[ ${SOFTLEVEL} == "${BOOTLEVEL}" \
74 || ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]] \ 73 || ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]] \
75 && mylevel="${DEFAULTLEVEL}" 74 && mylevel="${DEFAULTLEVEL}"
76 75
77# Call svc_quit if we abort AND we have obtained a lock 76# Call svc_quit if we abort AND we have obtained a lock
78service_started "${myservice}" 77service_started "${SVCNAME}"
79svcstarted="$?" 78svcstarted="$?"
80service_inactive "${myservice}" 79service_inactive "${SVCNAME}"
81svcinactive="$?" 80svcinactive="$?"
82svc_quit() { 81svc_quit() {
83 eerror "ERROR: ${myservice} caught an interrupt" 82 eerror "ERROR: ${SVCNAME} caught an interrupt"
84 if service_inactive "${myservice}" || [[ ${svcinactive} == 0 ]] ; then 83 if service_inactive "${SVCNAME}" || [[ ${svcinactive} == 0 ]] ; then
85 mark_service_inactive "${myservice}" 84 mark_service_inactive "${SVCNAME}"
86 elif [[ ${svcstarted} == 0 ]] ; then 85 elif [[ ${svcstarted} == 0 ]] ; then
87 mark_service_started "${myservice}" 86 mark_service_started "${SVCNAME}"
88 else 87 else
89 mark_service_stopped "${myservice}" 88 mark_service_stopped "${SVCNAME}"
90 fi 89 fi
91 exit 1 90 exit 1
92} 91}
93 92
94usage() { 93usage() {
95 local IFS="|" 94 local IFS="|"
96 myline="Usage: ${myservice} { $* " 95 myline="Usage: ${SVCNAME} { $* "
97 echo 96 echo
98 eerror "${myline}}" 97 eerror "${myline}}"
99 eerror " ${myservice} without arguments for full help" 98 eerror " ${SVCNAME} without arguments for full help"
100} 99}
101 100
102stop() { 101stop() {
103 # Return success so the symlink gets removed 102 # Return success so the symlink gets removed
104 return 0 103 return 0
105} 104}
106 105
107start() { 106start() {
108 eerror "ERROR: ${myservice} does not have a start function." 107 eerror "ERROR: ${SVCNAME} does not have a start function."
109 # Return failure so the symlink doesn't get created 108 # Return failure so the symlink doesn't get created
110 return 1 109 return 1
111} 110}
112 111
113restart() { 112restart() {
127 && ln -snf "/etc/init.d/${service}" \ 126 && ln -snf "/etc/init.d/${service}" \
128 "${svcdir}/scheduled/${service}/${start}" 127 "${svcdir}/scheduled/${service}/${start}"
129} 128}
130 129
131svc_start_scheduled() { 130svc_start_scheduled() {
132 [[ ! -d "${svcdir}/scheduled/${myservice}" ]] && return 131 [[ ! -d "${svcdir}/scheduled/${SVCNAME}" ]] && return
133 local x= services= 132 local x= services=
134 133
135 for x in $(dolisting "${svcdir}/scheduled/${myservice}/") ; do 134 for x in $(dolisting "${svcdir}/scheduled/${SVCNAME}/") ; do
136 services="${services} ${x##*/}" 135 services="${services} ${x##*/}"
137 done 136 done
138 137
139 for x in ${services} ; do 138 for x in ${services} ; do
140 service_stopped "${x}" && start_service "${x}" 139 service_stopped "${x}" && start_service "${x}"
141 rm -f "${svcdir}/scheduled/${myservice}/${x}" 140 rm -f "${svcdir}/scheduled/${SVCNAME}/${x}"
142 done 141 done
143 142
144 rmdir "${svcdir}/scheduled/${myservice}" 143 rmdir "${svcdir}/scheduled/${SVCNAME}"
145} 144}
146 145
147svc_stop() { 146svc_stop() {
148 local x= mydep= mydeps= retval=0 147 local x= mydep= mydeps= retval=0
149 local -a servicelist=() 148 local -a servicelist=()
150 149
151 # Do not try to stop if it had already failed to do so 150 # Do not try to stop if it had already failed to do so
152 if is_runlevel_stop && service_failed "${myservice}" ; then 151 if is_runlevel_stop && service_failed "${SVCNAME}" ; then
153 return 1 152 return 1
154 elif service_stopped "${myservice}" ; then 153 elif service_stopped "${SVCNAME}" ; then
155 ewarn "WARNING: ${myservice} has not yet been started." 154 ewarn "WARNING: ${SVCNAME} has not yet been started."
156 return 0 155 return 0
157 fi 156 fi
158 if ! mark_service_stopping "${myservice}" ; then 157 if ! mark_service_stopping "${SVCNAME}" ; then
159 eerror "ERROR: ${myservice} is already stopping." 158 eerror "ERROR: ${SVCNAME} is already stopping."
160 return 1 159 return 1
161 fi 160 fi
162 161
163 # Ensure that we clean up if we abort for any reason 162 # Ensure that we clean up if we abort for any reason
164 trap "svc_quit" INT QUIT TSTP 163 trap "svc_quit" INT QUIT TSTP
165 164
166 mark_service_starting "${myservice}" 165 mark_service_starting "${SVCNAME}"
167 service_message "Service ${myservice} stopping" 166 service_message "Service ${SVCNAME} stopping"
168 167
169 if in_runlevel "${myservice}" "${BOOTLEVEL}" && \ 168 if in_runlevel "${SVCNAME}" "${BOOTLEVEL}" && \
170 [[ ${SOFTLEVEL} != "reboot" && ${SOFTLEVEL} != "shutdown" ]] ; then 169 [[ ${SOFTLEVEL} != "reboot" && ${SOFTLEVEL} != "shutdown" ]] ; then
171 ewarn "WARNING: you are stopping a boot service." 170 ewarn "WARNING: you are stopping a boot service."
172 fi 171 fi
173 172
174 if [[ ${svcpause} != "yes" ]] ; then 173 if [[ ${svcpause} != "yes" ]] ; then
175 if [[ ${NETSERVICE} == "yes" ]] ; then 174 if [[ ${NETSERVICE} == "yes" ]] ; then
176 # A net.* service 175 # A net.* service
177 if in_runlevel "${myservice}" "${BOOTLEVEL}" || \ 176 if in_runlevel "${SVCNAME}" "${BOOTLEVEL}" || \
178 in_runlevel "${myservice}" "${mylevel}" ; then 177 in_runlevel "${SVCNAME}" "${mylevel}" ; then
179 # Only worry about net.* services if this is the last one 178 # Only worry about net.* services if this is the last one
180 # running or if RC_NET_STRICT_CHECKING is set ... 179 # running or if RC_NET_STRICT_CHECKING is set ...
181 ! is_net_up && mydeps="net" 180 ! is_net_up && mydeps="net"
182 fi 181 fi
183 mydeps="${mydeps} ${myservice}" 182 mydeps="${mydeps} ${SVCNAME}"
184 else 183 else
185 mydeps="${myservice}" 184 mydeps="${SVCNAME}"
186 fi 185 fi
187 fi 186 fi
188 187
189 # Save the IN_BACKGROUND var as we need to clear it for stopping depends 188 # Save the IN_BACKGROUND var as we need to clear it for stopping depends
190 local ib_save="${IN_BACKGROUND}" 189 local ib_save="${IN_BACKGROUND}"
215 214
216 IN_BACKGROUND="${ib_save}" 215 IN_BACKGROUND="${ib_save}"
217 216
218 if [[ ${retval} != 0 ]] ; then 217 if [[ ${retval} != 0 ]] ; then
219 eerror "ERROR: problems stopping dependent services." 218 eerror "ERROR: problems stopping dependent services."
220 eerror " ${myservice} is still up." 219 eerror " ${SVCNAME} is still up."
221 else 220 else
222 # Now that deps are stopped, stop our service 221 # Now that deps are stopped, stop our service
223 ( 222 (
224 exit() { 223 exit() {
225 RC_QUIET_STDOUT="no" 224 RC_QUIET_STDOUT="no"
234 ) 233 )
235 retval="$?" 234 retval="$?"
236 235
237 # If a service has been marked inactive, exit now as something 236 # If a service has been marked inactive, exit now as something
238 # may attempt to start it again later 237 # may attempt to start it again later
239 if service_inactive "${myservice}" ; then 238 if service_inactive "${SVCNAME}" ; then
240 svcinactive=0 239 svcinactive=0
241 return 0 240 return 0
242 fi 241 fi
243 fi 242 fi
244 243
245 if [[ ${retval} != 0 ]] ; then 244 if [[ ${retval} != 0 ]] ; then
246 # Did we fail to stop? create symlink to stop multible attempts at 245 # Did we fail to stop? create symlink to stop multible attempts at
247 # runlevel change. Note this is only used at runlevel change ... 246 # runlevel change. Note this is only used at runlevel change ...
248 is_runlevel_stop && mark_service_failed "${myservice}" 247 is_runlevel_stop && mark_service_failed "${SVCNAME}"
249 248
250 # If we are halting the system, do it as cleanly as possible 249 # If we are halting the system, do it as cleanly as possible
251 if [[ ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]] ; then 250 if [[ ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]] ; then
252 mark_service_stopped "${myservice}" 251 mark_service_stopped "${SVCNAME}"
253 else 252 else
254 if [[ ${svcinactive} == 0 ]] ; then 253 if [[ ${svcinactive} == 0 ]] ; then
255 mark_service_inactive "${myservice}" 254 mark_service_inactive "${SVCNAME}"
256 else 255 else
257 mark_service_started "${myservice}" 256 mark_service_started "${SVCNAME}"
258 fi
259 fi 257 fi
258 fi
260 259
261 service_message "eerror" "ERROR: ${myservice} failed to stop" 260 service_message "eerror" "ERROR: ${SVCNAME} failed to stop"
262 else 261 else
263 svcstarted=1 262 svcstarted=1
264 if service_inactive "${myservice}" ; then 263 if service_inactive "${SVCNAME}" ; then
265 svcinactive=0 264 svcinactive=0
266 else 265 else
267 mark_service_stopped "${myservice}" 266 mark_service_stopped "${SVCNAME}"
268 fi 267 fi
269 service_message "Stopped service ${myservice}" 268 service_message "Stopped service ${SVCNAME}"
270 fi 269 fi
271 270
272 # Reset the trap 271 # Reset the trap
273 svc_trap 272 svc_trap
274 273
277 276
278svc_start() { 277svc_start() {
279 local x= y= retval=0 startfail= startinactive= 278 local x= y= retval=0 startfail= startinactive=
280 279
281 # Do not try to start if i have done so already on runlevel change 280 # Do not try to start if i have done so already on runlevel change
282 if is_runlevel_start && service_failed "${myservice}" ; then 281 if is_runlevel_start && service_failed "${SVCNAME}" ; then
283 return 1 282 return 1
284 elif service_started "${myservice}" ; then 283 elif service_started "${SVCNAME}" ; then
285 ewarn "WARNING: ${myservice} has already been started." 284 ewarn "WARNING: ${SVCNAME} has already been started."
286 return 0 285 return 0
287 elif service_inactive "${myservice}" ; then 286 elif service_inactive "${SVCNAME}" ; then
288 if [[ ${IN_BACKGROUND} != "true" ]] ; then 287 if [[ ${IN_BACKGROUND} != "true" ]] ; then
289 ewarn "WARNING: ${myservice} has already been started." 288 ewarn "WARNING: ${SVCNAME} has already been started."
290 return 0 289 return 0
291 fi 290 fi
292 fi 291 fi
293 292
294 if ! mark_service_starting "${myservice}" ; then 293 if ! mark_service_starting "${SVCNAME}" ; then
295 if service_stopping "${myservice}" ; then 294 if service_stopping "${SVCNAME}" ; then
296 eerror "ERROR: ${myservice} is already stopping." 295 eerror "ERROR: ${SVCNAME} is already stopping."
297 else 296 else
298 eerror "ERROR: ${myservice} is already starting." 297 eerror "ERROR: ${SVCNAME} is already starting."
299 fi 298 fi
300 return 1 299 return 1
301 fi 300 fi
302 301
303 # Ensure that we clean up if we abort for any reason 302 # Ensure that we clean up if we abort for any reason
304 trap "svc_quit" INT QUIT TSTP 303 trap "svc_quit" INT QUIT TSTP
305 304
306 service_message "Service ${myservice} starting" 305 service_message "Service ${SVCNAME} starting"
307 306
308 # Save the IN_BACKGROUND var as we need to clear it for starting depends 307 # Save the IN_BACKGROUND var as we need to clear it for starting depends
309 local ib_save="${IN_BACKGROUND}" 308 local ib_save="${IN_BACKGROUND}"
310 unset IN_BACKGROUND 309 unset IN_BACKGROUND
311 310
312 local startupservices="$(ineed "${myservice}") $(valid_iuse "${myservice}")" 311 local startupservices="$(ineed "${SVCNAME}") $(valid_iuse "${SVCNAME}")"
313 local netservices= 312 local netservices=
314 for x in $(dolisting "/etc/runlevels/${BOOTLEVEL}/net.*") \ 313 for x in $(dolisting "/etc/runlevels/${BOOTLEVEL}/net.*") \
315 $(dolisting "/etc/runlevels/${mylevel}/net.*") ; do 314 $(dolisting "/etc/runlevels/${mylevel}/net.*") ; do
316 netservices="${netservices} ${x##*/}" 315 netservices="${netservices} ${x##*/}"
317 done 316 done
332 fi 331 fi
333 332
334 # We also wait for any services we're after to finish incase they 333 # We also wait for any services we're after to finish incase they
335 # have a "before" dep but we don't dep on them. 334 # have a "before" dep but we don't dep on them.
336 if is_runlevel_start ; then 335 if is_runlevel_start ; then
337 startupservices="${startupservices} $(valid_iafter "${myservice}")" 336 startupservices="${startupservices} $(valid_iafter "${SVCNAME}")"
338 fi 337 fi
339 338
340 if [[ " ${startupservices} " == *" net "* ]] ; then 339 if [[ " ${startupservices} " == *" net "* ]] ; then
341 startupservices=" ${startupservices} " 340 startupservices=" ${startupservices} "
342 startupservices="${startupservices/ net / ${netservices} }" 341 startupservices="${startupservices/ net / ${netservices} }"
347 for x in ${startupservices} ; do 346 for x in ${startupservices} ; do
348 service_started "${x}" && continue 347 service_started "${x}" && continue
349 wait_service "${x}" 348 wait_service "${x}"
350 if ! service_started "${x}" ; then 349 if ! service_started "${x}" ; then
351 # A 'need' dependency is critical for startup 350 # A 'need' dependency is critical for startup
352 if ineed -t "${myservice}" "${x}" >/dev/null \ 351 if ineed -t "${SVCNAME}" "${x}" >/dev/null \
353 || net_service "${x}" && ineed -t "${myservice}" net \ 352 || net_service "${x}" && ineed -t "${SVCNAME}" net \
354 && ! is_net_up ; then 353 && ! is_net_up ; then
355 if service_inactive "${x}" || service_wasinactive "${x}" || \ 354 if service_inactive "${x}" || service_wasinactive "${x}" || \
356 [[ -n $(ls "${svcdir}"/scheduled/*/"${x}" 2>/dev/null) ]] ; then 355 [[ -n $(ls "${svcdir}"/scheduled/*/"${x}" 2>/dev/null) ]] ; then
357 svc_schedule_start "${x}" "${myservice}" 356 svc_schedule_start "${x}" "${SVCNAME}"
358 startinactive="${x}" 357 startinactive="${x}"
359 else 358 else
360 startfail="${x}" 359 startfail="${x}"
361 fi 360 fi
362 break 361 break
364 fi 363 fi
365 done 364 done
366 365
367 if [[ -n ${startfail} ]] ; then 366 if [[ -n ${startfail} ]] ; then
368 eerror "ERROR: Problem starting needed service ${startfail}" 367 eerror "ERROR: Problem starting needed service ${startfail}"
369 eerror " ${myservice} was not started." 368 eerror " ${SVCNAME} was not started."
370 retval=1 369 retval=1
371 elif [[ -n ${startinactive} ]] ; then 370 elif [[ -n ${startinactive} ]] ; then
372 ewarn "WARNING: ${myservice} is scheduled to start when ${startinactive} has started." 371 ewarn "WARNING: ${SVCNAME} is scheduled to start when ${startinactive} has started."
373 retval=1 372 retval=1
374 elif broken "${myservice}" ; then 373 elif broken "${SVCNAME}" ; then
375 eerror "ERROR: Some services needed are missing. Run" 374 eerror "ERROR: Some services needed are missing. Run"
376 eerror " './${myservice} broken' for a list of those" 375 eerror " './${SVCNAME} broken' for a list of those"
377 eerror " services. ${myservice} was not started." 376 eerror " services. ${SVCNAME} was not started."
378 retval=1 377 retval=1
379 else 378 else
380 IN_BACKGROUND="${ib_save}" 379 IN_BACKGROUND="${ib_save}"
381 ( 380 (
382 exit() { 381 exit() {
397 ) 396 )
398 retval="$?" 397 retval="$?"
399 398
400 # If a service has been marked inactive, exit now as something 399 # If a service has been marked inactive, exit now as something
401 # may attempt to start it again later 400 # may attempt to start it again later
402 if service_inactive "${myservice}" ; then 401 if service_inactive "${SVCNAME}" ; then
403 svcinactive=0 402 svcinactive=0
404 service_message "ewarn" "WARNING: ${myservice} has started but is inactive" 403 service_message "ewarn" "WARNING: ${SVCNAME} has started but is inactive"
405 return 1 404 return 1
406 fi 405 fi
407 fi 406 fi
408 407
409 if [[ ${retval} != 0 ]] ; then 408 if [[ ${retval} != 0 ]] ; then
410 if [[ ${svcinactive} == 0 ]] ; then 409 if [[ ${svcinactive} == 0 ]] ; then
411 mark_service_inactive "${myservice}" 410 mark_service_inactive "${SVCNAME}"
412 else 411 else
413 mark_service_stopped "${myservice}" 412 mark_service_stopped "${SVCNAME}"
414 fi 413 fi
415 414
416 if [[ -z ${startinactive} ]] ; then 415 if [[ -z ${startinactive} ]] ; then
417 is_runlevel_start && mark_service_failed "${myservice}" 416 is_runlevel_start && mark_service_failed "${SVCNAME}"
418 service_message "eerror" "ERROR: ${myservice} failed to start" 417 service_message "eerror" "ERROR: ${SVCNAME} failed to start"
419 fi 418 fi
420 else 419 else
421 svcstarted=0 420 svcstarted=0
422 mark_service_started "${myservice}" 421 mark_service_started "${SVCNAME}"
423 service_message "Service ${myservice} started" 422 service_message "Service ${SVCNAME} started"
424 fi 423 fi
425 424
426 # Reset the trap 425 # Reset the trap
427 svc_trap 426 svc_trap
428 427
429 return "${retval}" 428 return "${retval}"
430} 429}
431 430
432svc_restart() { 431svc_restart() {
433 if ! service_stopped "${myservice}" ; then 432 if ! service_stopped "${SVCNAME}" ; then
434 svc_stop || return "$?" 433 svc_stop || return "$?"
435 fi 434 fi
436 svc_start 435 svc_start
437} 436}
438 437
444 # to work with the printed " * status: foo". 443 # to work with the printed " * status: foo".
445 local efunc="" state="" 444 local efunc="" state=""
446 445
447 # If we are effectively root, check to see if required daemons are running 446 # If we are effectively root, check to see if required daemons are running
448 # and update our status accordingly 447 # and update our status accordingly
449 [[ ${EUID} == 0 ]] && update_service_status "${myservice}" 448 [[ ${EUID} == 0 ]] && update_service_status "${SVCNAME}"
450 449
451 if service_stopping "${myservice}" ; then 450 if service_stopping "${SVCNAME}" ; then
452 efunc="eerror" 451 efunc="eerror"
453 state="stopping" 452 state="stopping"
454 elif service_starting "${myservice}" ; then 453 elif service_starting "${SVCNAME}" ; then
455 efunc="einfo" 454 efunc="einfo"
456 state="starting" 455 state="starting"
457 elif service_inactive "${myservice}" ; then 456 elif service_inactive "${SVCNAME}" ; then
458 efunc="ewarn" 457 efunc="ewarn"
459 state="inactive" 458 state="inactive"
460 elif service_started "${myservice}" ; then 459 elif service_started "${SVCNAME}" ; then
461 efunc="einfo" 460 efunc="einfo"
462 state="started" 461 state="started"
463 else 462 else
464 efunc="eerror" 463 efunc="eerror"
465 state="stopped" 464 state="stopped"
537 536
538retval=0 537retval=0
539for arg in $* ; do 538for arg in $* ; do
540 case "${arg}" in 539 case "${arg}" in
541 stop) 540 stop)
542 if [[ -e "${svcdir}/scheduled/${myservice}" ]] ; then 541 if [[ -e "${svcdir}/scheduled/${SVCNAME}" ]] ; then
543 rm -Rf "${svcdir}/scheduled/${myservice}" 542 rm -Rf "${svcdir}/scheduled/${SVCNAME}"
544 fi 543 fi
545 544
546 # Stoped from the background - treat this as a restart so that 545 # Stoped from the background - treat this as a restart so that
547 # stopped services come back up again when started. 546 # stopped services come back up again when started.
548 if [[ ${IN_BACKGROUND} == "true" ]] ; then 547 if [[ ${IN_BACKGROUND} == "true" ]] ; then
549 rm -rf "${svcdir}/snapshot/$$" 548 rm -rf "${svcdir}/snapshot/$$"
550 mkdir -p "${svcdir}/snapshot/$$" 549 mkdir -p "${svcdir}/snapshot/$$"
551 cp -pP "${svcdir}"/started/* "${svcdir}/snapshot/$$/" 550 cp -pP "${svcdir}"/started/* "${svcdir}/snapshot/$$/"
552 rm -f "${svcdir}/snapshot/$$/${myservice}" 551 rm -f "${svcdir}/snapshot/$$/${SVCNAME}"
553 fi 552 fi
554 553
555 svc_stop 554 svc_stop
556 retval="$?" 555 retval="$?"
557 556
558 if [[ ${IN_BACKGROUND} == "true" ]] ; then 557 if [[ ${IN_BACKGROUND} == "true" ]] ; then
559 for x in $(dolisting "${svcdir}/snapshot/$$/") ; do 558 for x in $(dolisting "${svcdir}/snapshot/$$/") ; do
560 if service_stopped "${x##*/}" ; then 559 if service_stopped "${x##*/}" ; then
561 svc_schedule_start "${myservice}" "${x##*/}" 560 svc_schedule_start "${SVCNAME}" "${x##*/}"
562 fi 561 fi
563 done 562 done
564 else 563 else
565 rm -f "${svcdir}"/scheduled/*/"${myservice}" 564 rm -f "${svcdir}"/scheduled/*/"${SVCNAME}"
566 fi 565 fi
567 566
568 ;; 567 ;;
569 start) 568 start)
570 svc_start 569 svc_start
571 retval="$?" 570 retval="$?"
572 service_started "${myservice}" && svc_start_scheduled 571 service_started "${SVCNAME}" && svc_start_scheduled
573 ;; 572 ;;
574 needsme|ineed|usesme|iuse|broken) 573 needsme|ineed|usesme|iuse|broken)
575 trace_dependencies "-${arg}" 574 trace_dependencies "-${arg}"
576 ;; 575 ;;
577 status) 576 status)
578 svc_status 577 svc_status
579 retval="$?" 578 retval="$?"
580 ;; 579 ;;
581 zap) 580 zap)
582 einfo "Manually resetting ${myservice} to stopped state." 581 einfo "Manually resetting ${SVCNAME} to stopped state."
583 mark_service_stopped "${myservice}" 582 mark_service_stopped "${SVCNAME}"
584 ;; 583 ;;
585 restart) 584 restart)
586 svcrestart="yes" 585 svcrestart="yes"
587 586
588 # We don't kill child processes if we're restarting 587 # We don't kill child processes if we're restarting
591 590
592 # Create a snapshot of started services 591 # Create a snapshot of started services
593 rm -rf "${svcdir}/snapshot/$$" 592 rm -rf "${svcdir}/snapshot/$$"
594 mkdir -p "${svcdir}/snapshot/$$" 593 mkdir -p "${svcdir}/snapshot/$$"
595 cp -pP "${svcdir}"/started/* "${svcdir}/snapshot/$$/" 594 cp -pP "${svcdir}"/started/* "${svcdir}/snapshot/$$/"
596 rm -f "${svcdir}/snapshot/$$/${myservice}" 595 rm -f "${svcdir}/snapshot/$$/${SVCNAME}"
597 596
598 # Simple way to try and detect if the service use svc_{start,stop} 597 # Simple way to try and detect if the service use svc_{start,stop}
599 # to restart if it have a custom restart() funtion. 598 # to restart if it have a custom restart() funtion.
600 if [[ -n $(egrep '^[[:space:]]*restart[[:space:]]*()' "/etc/init.d/${myservice}") ]] ; then 599 if [[ -n $(egrep '^[[:space:]]*restart[[:space:]]*()' "/etc/init.d/${SVCNAME}") ]] ; then
601 if [[ -z $(egrep 'svc_stop' "/etc/init.d/${myservice}") || \ 600 if [[ -z $(egrep 'svc_stop' "/etc/init.d/${SVCNAME}") || \
602 -z $(egrep 'svc_start' "/etc/init.d/${myservice}") ]] ; then 601 -z $(egrep 'svc_start' "/etc/init.d/${SVCNAME}") ]] ; then
603 echo 602 echo
604 ewarn "Please use 'svc_stop; svc_start' and not 'stop; start' to" 603 ewarn "Please use 'svc_stop; svc_start' and not 'stop; start' to"
605 ewarn "restart the service in its custom 'restart()' function." 604 ewarn "restart the service in its custom 'restart()' function."
606 ewarn "Run ${myservice} without arguments for more info." 605 ewarn "Run ${SVCNAME} without arguments for more info."
607 echo 606 echo
608 svc_restart 607 svc_restart
609 else 608 else
610 restart 609 restart
611 fi 610 fi
612 else 611 else
613 restart 612 restart
614 fi 613 fi
615 retval="$?" 614 retval="$?"
616 615
617 [[ -e "${svcdir}/scheduled/${myservice}" ]] \ 616 [[ -e "${svcdir}/scheduled/${SVCNAME}" ]] \
618 && rm -Rf "${svcdir}/scheduled/${myservice}" 617 && rm -Rf "${svcdir}/scheduled/${SVCNAME}"
619 618
620 # Restart dependencies as well 619 # Restart dependencies as well
621 for x in $(dolisting "${svcdir}/snapshot/$$/") ; do 620 for x in $(dolisting "${svcdir}/snapshot/$$/") ; do
622 if service_stopped "${x##*/}" ; then 621 if service_stopped "${x##*/}" ; then
623 if service_inactive "${myservice}" \ 622 if service_inactive "${SVCNAME}" \
624 || service_wasinactive "${myservice}" ; then 623 || service_wasinactive "${SVCNAME}" ; then
625 svc_schedule_start "${myservice}" "${x##*/}" 624 svc_schedule_start "${SVCNAME}" "${x##*/}"
626 ewarn "WARNING: ${x##*/} is scheduled to start when ${myservice} has started." 625 ewarn "WARNING: ${x##*/} is scheduled to start when ${SVCNAME} has started."
627 elif service_started "${myservice}" ; then 626 elif service_started "${SVCNAME}" ; then
628 start_service "${x##*/}" 627 start_service "${x##*/}"
629 fi 628 fi
630 fi 629 fi
631 done 630 done
632 rm -rf "${svcdir}/snapshot/$$" 631 rm -rf "${svcdir}/snapshot/$$"
633 632
634 service_started "${myservice}" && svc_start_scheduled 633 service_started "${SVCNAME}" && svc_start_scheduled
635 634
636 # Wait for services to come up 635 # Wait for services to come up
637 [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && wait 636 [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && wait
638 637
639 svcrestart="no" 638 svcrestart="no"

Legend:
Removed from v.275  
changed lines
  Added in v.276

  ViewVC Help
Powered by ViewVC 1.1.20