/[baselayout]/trunk/sbin/rc-services.sh
Gentoo

Contents of /trunk/sbin/rc-services.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1179 - (show annotations) (download) (as text)
Thu May 19 15:23:43 2005 UTC (14 years ago) by uberlord
File MIME type: text/x-sh
File size: 19287 byte(s)
Merged Paul Pacheco's parallel startup #69854 and modules update
#55329 patches

If RC_PARALLEL_STARTUP==yes then we no longer output einfo/ebegin
messages as they don't line up on screen correctly - instead we output
service ${myservice} starting/started/stopping/stopped/failed

1 # Copyright 1999-2004 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header$
4
5 # RC Dependency and misc service functions
6
7 RC_GOT_SERVICES="yes"
8
9 [[ ${RC_GOT_FUNCTIONS} != "yes" ]] && source /sbin/functions.sh
10
11 if [[ ${RC_GOT_DEPTREE_INFO} != "yes" ]]; then
12 # Only try and update if we are root
13 if [[ ${EUID} == "0" ]] && ! /sbin/depscan.sh -u ; then
14 echo
15 eerror "Error running '/sbin/depscan.sh'!"
16 eerror "Please correct any problems above."
17 exit 1
18 fi
19
20 source "${svcdir}/deptree"
21 if [[ ${RC_GOT_DEPTREE_INFO} != "yes" ]]; then
22 echo
23 eerror "Dependency info is missing! Please run"
24 eerror " # /sbin/depscan.sh"
25 eerror "to fix this."
26 exit 1
27 fi
28 fi
29
30 #####################
31 # Internal variables
32 #####################
33
34 # The name of the service whose dependency info we currently have
35 rc_name=
36 # The index of the service whose dependency info we currently have
37 rc_index=0
38 # Our dependency types ...
39 rc_ineed=
40 rc_needsme=
41 rc_iuse=
42 rc_usesme=
43 rc_ibefore=
44 rc_iafter=
45 rc_broken=
46 rc_parallel=
47 rc_mtime=
48
49 ############
50 # Functions
51 ############
52
53 # bool get_service_index(service, index)
54 #
55 # Print the index of 'service'. 'index' is the current index.
56 #
57 get_service_index() {
58 if [[ -z $1 || -z $2 ]]; then
59 echo "0"
60 return 1
61 fi
62
63 local x myservice="$1" index="$2"
64
65 # Do we already have the index?
66 if [[ -n ${index} && ${index} -gt 0 \
67 && ${myservice} == ${RC_DEPEND_TREE[${index}]} ]]; then
68 echo "${index}"
69 return 0
70 fi
71
72 for (( x=1; x<=${RC_DEPEND_TREE[0]}; x++ )); do
73 index=$(( ${x} * ${rc_index_scale} ))
74 if [[ ${myservice} == ${RC_DEPEND_TREE[${index}]} ]]; then
75 echo "${index}"
76 return 0
77 fi
78 done
79
80 echo "0"
81 return 1
82 }
83
84 # bool get_dep_info(service)
85 #
86 # Set the Dependency variables to contain data for 'service'
87 #
88 get_dep_info() {
89 [[ -z $1 ]] && return 1
90
91 local myservice="$1"
92
93 # We already have the right stuff ...
94 [[ ${myservice} == ${rc_name} && -n ${rc_mtime} ]] && return 0
95
96 rc_index="`get_service_index "${myservice}" "${rc_index}"`"
97 rc_mtime="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_mtime}))]}"
98
99 # Verify that we have the correct index (rc_index) ...
100 # [[ ${rc_index} == "0" ]] && return 1
101
102 rc_name="${RC_DEPEND_TREE[${rc_index}]}"
103 rc_ineed="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_ineed}))]}"
104 rc_needsme="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_needsme}))]}"
105 rc_iuse="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_iuse}))]}"
106 rc_usesme="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_usesme}))]}"
107 rc_ibefore="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_ibefore}))]}"
108 rc_iafter="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_iafter}))]}"
109 rc_broken="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_broken}))]}"
110 rc_parallel="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_parallel}))]}"
111 rc_mtime="${RC_DEPEND_TREE[$((${rc_index} + ${rc_type_mtime}))]}"
112 return 0
113 }
114
115 # string check_dependency(deptype, service1)
116 #
117 # List all the services that depend on 'service1' of dependency
118 # type 'deptype'
119 #
120 # bool check_dependency(deptype, -t, service1, service2)
121 #
122 # Returns true if 'service2' is a dependency of type 'deptype'
123 # of 'service1'
124 #
125 check_dependency() {
126 [[ -z $1 || -z $2 ]] && return 1
127
128 local x myservice deps
129
130 # Set the dependency variables to relate to 'service1'
131 if [[ $2 == "-t" ]]; then
132 [[ -z $3 || -z $4 ]] && return 1
133 myservice="$3"
134 else
135 myservice="$2"
136 fi
137
138 if ! get_dep_info "${myservice}" >/dev/null ; then
139 eerror "Could not get dependency info for \"${myservice}\"!" > /dev/stderr
140 eerror "Please run:" > /dev/stderr
141 eerror " # /sbin/depscan.sh" > /dev/stderr
142 eerror "to try and fix this." > /dev/stderr
143 return 1
144 fi
145
146 # Do we have valid info for 'deptype' ?
147 eval deps=\"\$\{rc_$1\}\"
148 [[ -z ${deps} ]] && return 1
149
150 if [[ $2 == "-t" && -n $4 ]]; then
151 # Check if 'service1' have 'deptype' dependency on 'service2'
152 for x in ${deps}; do
153 [[ ${x} == $4 ]] && return 0
154 done
155 return 1
156 else
157 # Just list all services that 'service1' have 'deptype' dependency on.
158 echo "${deps}"
159 return 0
160 fi
161 }
162
163 # Same as for check_dependency, except 'deptype' is set to
164 # 'ineed'. It will return all the services 'service1' NEED's.
165 ineed() {
166 check_dependency ineed "$@"
167 }
168
169 # Same as for check_dependency, except 'deptype' is set to
170 # 'needsme'. It will return all the services that NEED 'service1'.
171 needsme() {
172 check_dependency needsme "$@"
173 }
174
175 # Same as for check_dependency, except 'deptype' is set to
176 # 'iuse'. It will return all the services 'service1' USE's.
177 iuse() {
178 check_dependency iuse "$@"
179 }
180
181 # Same as for check_dependency, except 'deptype' is set to
182 # 'usesme'. It will return all the services that USE 'service1'.
183 usesme() {
184 check_dependency usesme "$@"
185 }
186
187 # Same as for check_dependency, except 'deptype' is set to
188 # 'ibefore'. It will return all the services that are started
189 # *after* 'service1' (iow, it will start 'service1' before the
190 # list of services returned).
191 ibefore() {
192 check_dependency ibefore "$@"
193 }
194
195 # Same as for check_dependency, except 'deptype' is set to
196 # 'iafter'. It will return all the services that are started
197 # *before* 'service1' (iow, it will start 'service1' after the
198 # list of services returned).
199 iafter() {
200 check_dependency iafter "$@"
201 }
202
203 # Same as for check_dependency, except 'deptype' is set to
204 # 'broken'. It will return all the services that 'service1'
205 # NEED, but are not present.
206 broken() {
207 check_dependency broken "$@"
208 }
209
210 # bool iparallel(service)
211 #
212 # Returns true if the service can be started in parallel.
213 #
214 iparallel() {
215 ! check_dependency parallel -t "$1" "no"
216 }
217
218 # bool is_fake_service(service, runlevel)
219 #
220 # Returns ture if 'service' is a fake service in 'runlevel'.
221 #
222 is_fake_service() {
223 local x fake_services
224
225 [[ -z $1 || -z $2 ]] && return 1
226
227 [[ $2 != ${BOOTLEVEL} && -e "/etc/runlevels/${BOOTLEVEL}/.fake" ]] \
228 && fake_services="$( < /etc/runlevels/${BOOTLEVEL}/.fake )"
229
230 [[ -e "/etc/runlevels/$2/.fake" ]] \
231 && fake_services="${fake_services} $( < /etc/runlevels/$2/.fake )"
232
233 for x in ${fake_services}; do
234 [[ $1 == ${x##*/} ]] && return 0
235 done
236
237 return 1
238 }
239
240 # bool in_runlevel(service, runlevel)
241 #
242 # Returns true if 'service' is in runlevel 'runlevel'.
243 #
244 in_runlevel() {
245 [[ -z $1 || -z $2 ]] && return 1
246
247 [[ -L "/etc/runlevels/$2/$1" ]] && return 0
248
249 return 1
250 }
251
252 # bool is_runlevel_start()
253 #
254 # Returns true if it is a runlevel change, and we are busy
255 # starting services.
256 #
257 is_runlevel_start() {
258 [[ -d "${svcdir}/softscripts.old" ]] && return 0
259
260 return 1
261 }
262
263 # bool is_runlevel_stop()
264 #
265 # Returns true if it is a runlevel change, and we are busy
266 # stopping services.
267 #
268 is_runlevel_stop() {
269 [[ -d "${svcdir}/softscripts.new" ]] && return 0
270
271 return 1
272 }
273
274 service_message() {
275 [[ ${RC_PARALLEL_STARTUP} != "yes" || ${RC_QUIET_STDOUT} != "yes" ]] \
276 && return
277
278 local cmd="einfo"
279 if [[ $1 == 1 || $1 == "error" || $1 == "eerror" ]]; then
280 cmd="eerror"
281 shift
282 fi
283
284 RC_QUIET_STDOUT="no"
285 ${cmd} "$@"
286 RC_QUIET_STDOUT="yes"
287 }
288
289 # bool begin_service( service )
290 #
291 # atomically marks the service as being executed
292 # use like this:
293 #
294 # if begin_service service ; then
295 # whatever is in here can only be executed by one process
296 # end_service service
297 # fi
298 begin_service()
299 {
300 [[ {$START_CRITICAL} == "yes" ]] && return 0
301
302 mkfifo "${svcdir}/exclusive/${service}" 2> /dev/null
303 return $?
304 }
305
306 # void end_exclusive(service, exitcode)
307 #
308 # stops executing a exclusive region and
309 # wakes up anybody who is waiting for the exclusive region
310 #
311 end_service()
312 {
313 local service="$1" exitstatus="$2"
314
315 # if we are doing critical services, there is no fifo
316 [[ "${START_CRITICAL}" == "yes" ]] && return
317
318 if [[ -n ${exitstatus} ]] ; then
319 echo "${exitstatus}" > "${svcdir}/exitcodes/${service}"
320 fi
321
322 # move the fifo to a unique name so no-one is waiting for it
323 if [[ -e "${svcdir}/exclusive/${service}" ]]; then
324 local tempname="${svcdir}/exclusive/${service}.$$"
325 mv -f "${svcdir}/exclusive/${service}" "${tempname}"
326
327 # wake up anybody that was waiting for the fifo
328 touch "${tempname}"
329
330 # We dont need the fifo anymore
331 rm -f "${tempname}"
332 fi
333 }
334
335 # int wait_exclusive(service)
336 wait_service()
337 {
338 local service="$1"
339
340 [[ ${START_CRITICAL} == "yes" ]] && return 0
341 service_started "${service}" && return 0
342
343 # This will block until the service fifo is touched
344 # Otheriwse we don't block
345 #cat "${svcdir}/exclusive/${service}" 2> /dev/null
346 local tmp=$( < "${svcdir}/exclusive/${service}" 2>/dev/null )
347 local exitstatus=$( < "${svcdir}/exitcodes/${service}" )
348
349 return "${exitstatus}"
350 }
351
352 # int start_service(service)
353 #
354 # Start 'service' if it is not already running.
355 #
356 start_service() {
357 local service="$1"
358 [[ -z ${service} ]] && return 1
359
360 ! service_stopped "${service}" && return 0
361
362 splash "svc_start" "${service}"
363 if is_fake_service "${service}" "${SOFTLEVEL}" ; then
364 mark_service_started "${service}"
365 splash "svc_started" "${service}" "0"
366 end_service "${service}"
367 return 0
368 fi
369
370 begin_service "${service}"
371 if [[ ${RC_PARALLEL_STARTUP} != "yes" \
372 || ${START_CRITICAL} == "yes" ]] ; then
373
374 # if we can not start the services in parallel
375 # then just start it and return the exit status
376 (. /sbin/runscript.sh "/etc/init.d/${service}" start)
377 retval="$?"
378 splash "svc_started" "${service}" "${retval}"
379 end_service "${service}" "${retval}"
380 return "${retval}"
381 else
382 # if parallel startup is allowed, start it in background
383 (
384 (. /sbin/runscript.sh "/etc/init.d/${service}" start)
385 retval="$?"
386 splash "svc_started" "${service}" "${retval}"
387 end_service "${service}" "${retval}"
388 ) &
389 return 0
390 fi
391 }
392
393 # int stop_service(service)
394 #
395 # Stop 'service' if it is not already running.
396 #
397 stop_service() {
398 [[ -z $1 ]] && return 1
399
400 ! service_started "$1" && return 0
401
402 splash "svc_stop" "$1"
403
404 local level="${SOFTLEVEL}"
405 is_runlevel_stop && level="${OLDSOFTLEVEL}"
406
407 if is_fake_service "$1" "${level}" ; then
408 mark_service_stopped "$1"
409 splash "svc_stopped" "$1" "0"
410 return 0
411 fi
412
413 (. /sbin/runscript.sh "/etc/init.d/$1" stop)
414 local retval="$?"
415 splash "svc_stopped" "$1" "${retval}"
416
417 return "${retval}"
418 }
419
420 # bool mark_service_starting(service)
421 #
422 # Mark 'service' as starting.
423 #
424 mark_service_starting() {
425 [[ -z $1 ]] && return 1
426
427 ln -snf "/etc/init.d/$1" "${svcdir}/starting/$1"
428 local retval=$?
429
430 [[ -f "${svcdir}/inactive/$1" ]] && rm -f "${svcdir}/inactive/$1"
431
432 return "${retval}"
433 }
434
435 # bool mark_service_started(service)
436 #
437 # Mark 'service' as started.
438 #
439 mark_service_started() {
440 [[ -z $1 ]] && return 1
441
442 ln -snf "/etc/init.d/$1" "${svcdir}/started/$1"
443 local retval="$?"
444
445 [[ -f "${svcdir}/starting/$1" ]] && rm -f "${svcdir}/starting/$1"
446 [[ -f "${svcdir}/inactive/$1" ]] && rm -f "${svcdir}/inactive/$1"
447 [[ -f "${svcdir}/stopping/$1" ]] && rm -f "${svcdir}/stopping/$1"
448
449 echo "0" > "${svcdir}/exitcodes/$1"
450 return "${retval}"
451 }
452
453 # bool mark_service_inactive(service)
454 #
455 # Mark service as inactive
456 #
457 mark_service_inactive() {
458 [[ -z $1 ]] && return 1
459
460 ln -snf "/etc/init.d/$1" "${svcdir}/inactive/$1"
461 local retval="$?"
462
463 echo "0" > "${svcdir}/exitcodes/$1"
464 return "${retval}"
465 }
466
467 # bool mark_service_stopping(service)
468 #
469 # Mark 'service' as stopping.
470 #
471 mark_service_stopping() {
472 [[ -z $1 ]] && return 1
473
474 ln -snf "/etc/init.d/$1" "${svcdir}/stopping/$1"
475 local retval="$?"
476
477 [ -f "${svcdir}/starting/$1" ] && rm -f "${svcdir}/starting/$1"
478 [ -f "${svcdir}/started/$1" ] && rm -f "${svcdir}/started/$1"
479 [ -f "${svcdir}/inactive/$1" ] && rm -f "${svcdir}/inactive/$1"
480
481 return "${retval}"
482 }
483
484 # bool mark_service_stopped(service)
485 #
486 # Mark 'service' as stopped.
487 #
488 mark_service_stopped() {
489 [[ -z $1 ]] && return 1
490
491 [[ -f "${svcdir}/starting/$1" ]] && rm -f "${svcdir}/starting/$1"
492 [[ -f "${svcdir}/started/$1" ]] && rm -f "${svcdir}/started/$1"
493 [[ -f "${svcdir}/inactive/$1" ]] && rm -f "${svcdir}/inactive/$1"
494 [[ -f "${svcdir}/stopping/$1" ]] && rm -f "${svcdir}/stopping/$1"
495
496 return $?
497 }
498
499 # bool test_service_state(char *service, char *state)
500 #
501 # Returns 0 if the service link exists and points to a file, otherwise 1
502 # If 1 then the link is erased if it exists
503 test_service_state() {
504 [[ -z $1 || -z $2 ]] && return 1
505
506 local f="${svcdir}/$2/$1"
507
508 [[ -L ${f} ]] || return 1
509
510 if [[ ! -e ${f} ]]; then
511 rm -f "${f}"
512 return 1
513 fi
514
515 return 0
516 }
517
518 # bool service_starting(service)
519 #
520 # Returns true if 'service' is starting
521 #
522 service_starting() {
523 test_service_state "$1" "starting"
524 }
525
526 # bool service_started(service)
527 #
528 # Returns true if 'service' is started
529 #
530 service_started() {
531 test_service_state "$1" "started"
532 }
533
534 # bool service_inactive(service)
535 #
536 # Returns true if 'service' is inactive
537 #
538 service_inactive() {
539 test_service_state "$1" "inactive"
540 }
541
542 # bool service_stopping(service)
543 #
544 # Returns true if 'service' is stopping
545 #
546 service_stopping() {
547 test_service_state "$1" "stopping"
548 }
549
550 # bool service_stopped(service)
551 #
552 # Returns true if 'service' is stopped
553 #
554 service_stopped() {
555 [[ -z $1 ]] && return 1
556
557 service_starting "$1" && return 1
558 service_started "$1" && return 1
559 service_stopping "$1" && return 1
560
561 return 0
562 }
563
564 # bool mark_service_failed(service)
565 #
566 # Mark service as failed for current runlevel. Note that
567 # this is only valid on runlevel change ...
568 #
569 mark_service_failed() {
570 [[ -z $1 || ! -d "${svcdir}/failed" ]] && return 1
571
572 ln -snf "/etc/init.d/$1" "${svcdir}/failed/$1"
573 }
574
575 # bool service_failed(service)
576 #
577 # Return true if 'service' have failed during this runlevel.
578 #
579 service_failed() {
580 [[ -n $1 && -L "${svcdir}/failed/$1" ]]
581 }
582
583 # bool net_service(service)
584 #
585 # Returns true if 'service' is a service controlling a network interface
586 #
587 net_service() {
588 [[ -n $1 && ${1%%.*} == "net" && ${1##*.} != $1 ]]
589 }
590
591 # bool is_net_up()
592 #
593 # Return true if service 'net' is considered up, else false.
594 #
595 # Notes for RC_NET_STRICT_CHECKING values:
596 # none net is up without checking anything - usefull for vservers
597 # lo Interface 'lo' is counted and if only it is up, net is up.
598 # no Interface 'lo' is not counted, and net is down even with it up,
599 # so there have to be at least one other interface up.
600 # yes All interfaces must be up.
601 is_net_up() {
602 local netcount=0
603
604 case "${RC_NET_STRICT_CHECKING}" in
605 none)
606 return 0
607 ;;
608 lo)
609 netcount="$(ls -1 "${svcdir}"/started/net.* 2> /dev/null | \
610 egrep -c "\/net\..*$")"
611 ;;
612 *)
613 netcount="$(ls -1 "${svcdir}"/started/net.* 2> /dev/null | \
614 grep -v 'net\.lo' | egrep -c "\/net\..*$")"
615 ;;
616 esac
617
618 # Only worry about net.* services if this is the last one running,
619 # or if RC_NET_STRICT_CHECKING is set ...
620 if [ "${netcount}" -lt 1 -o "${RC_NET_STRICT_CHECKING}" = "yes" ]
621 then
622 return 1
623 fi
624
625 return 0
626 }
627
628 # void schedule_service_startup(service)
629 #
630 # Schedule 'service' for startup, in parallel if possible.
631 #
632 schedule_service_startup() {
633 local service="$1"
634
635 if ! iparallel "${service}"; then
636 wait
637 fi
638 start_service "${service}"
639
640 return 0
641 }
642
643 # bool dependon(service1, service2)
644 #
645 # Does service1 depend (NEED or USE) on service2 ?
646 #
647 dependon() {
648 ineed -t "$1" "$2" || iuse -t "$1" "$2"
649 }
650
651 # string validi(use/after, service)
652 #
653 # This is the main code for valid_after and valid_iuse
654 # No point in writing it twice!
655 valid_i() {
656 local x mylevel=$( < "${svcdir}/softlevel" 2>/dev/null)
657 # Cannot be SOFTLEVEL, as we need to know current runlevel
658
659 [[ $1 != "after" && $1 != "use" ]] && return 1
660
661 # Just set to dummy if not softlevel not initialized
662 [[ -z ${mylevel} ]] && mylevel=${BOOTLEVEL}
663
664 for x in $( i$1 "$2" )
665 do
666 [[ -e "/etc/runlevels/${BOOTLEVEL}/${x}" \
667 || -e "/etc/runlevels/${mylevel}/${x}" \
668 || ${x} == "net" ]] \
669 && echo "${x}"
670 done
671
672 return 0
673 }
674
675 # string valid_iuse(service)
676 #
677 # This will only give the valid use's for the service
678 # (they must be in the boot or current runlevel)
679 #
680 valid_iuse() {
681 valid_i "use" "$1"
682 }
683
684 #string valid_iafter(service)
685 #
686 # Valid services for current or boot rc level that should start
687 # before 'service'
688 #
689 valid_iafter() {
690 valid_i "after" "$1"
691 }
692
693 # string trace_dependencies(service[s])
694 #
695 # Get and sort the dependencies of given service[s].
696 #
697 trace_dependencies() {
698 local -a unsorted=( "$@" )
699 local -a sorted dependencies
700 local service dependency x deptype
701
702 case "$1" in
703 -*)
704 deptype=${1/-}
705 unsorted=( "${myservice}" )
706 # We need to check what deps matches the 'net' service
707 # as well
708 net_service "${myservice}" && \
709 unsorted=( "net" ${unsorted[@]} )
710 ;;
711 esac
712
713 # If its a net service, just replace it with 'net'
714 if [[ -z ${deptype} ]] ; then
715 for (( x=0 ; x < ${#unsorted[*]} ; x++ )) ; do
716 net_service "${unsorted[x]}" && unsorted[x]="net"
717 done
718 fi
719
720 while (( ${#unsorted[*]} > 0 )) ; do
721 # Get a service from the list and remove it
722 service=${unsorted[0]}
723 unset unsorted[0]
724 # Reindex the array
725 unsorted=( ${unsorted[@]} )
726
727 if [[ -n ${deptype} ]] ; then
728 dependencies=(
729 $( "${deptype}" "${service}" )
730 )
731 else
732 # Services that should start before $service
733 dependencies=(
734 $(ineed "${service}")
735 $(valid_iuse "${service}")
736 )
737 if is_runlevel_start || is_runlevel_stop ; then
738 dependencies=(
739 ${dependencies[@]}
740 $(valid_iafter "${service}")
741 )
742 fi
743 fi
744
745 # Remove each one of those from the sorted list and add
746 # them all to the unsorted so we analyze them later
747 for dependency in ${dependencies[@]} ; do
748 for (( x=0 ; x < ${#sorted[*]} ; x++ )) ; do
749 if [[ ${sorted[x]} == "${dependency}" ]] ; then
750 unset sorted[x]
751 break
752 fi
753 done
754 for (( x=0 ; x < ${#unsorted[*]} ; x++ )) ; do
755 if [[ ${unsorted[x]} == "${dependency}" ]] ; then
756 unset unsorted[x]
757 break
758 fi
759 done
760
761 sorted=( ${sorted[@]} )
762 unsorted=( ${unsorted[@]} ${dependency} )
763 done
764
765 sorted=( ${service} ${sorted[@]} )
766 done
767
768 if [[ -n ${deptype} ]] ; then
769 # If deptype is set, we do not want the name of this service
770 for (( x=0 ; x < ${#sorted[*]} ; x++ )) ; do
771 if [[ ${sorted[x]} == "${myservice}" ]] ; then
772 unset sorted[x]
773 break
774 fi
775 done
776 sorted=( ${sorted[@]} )
777
778 # If its a net service, do not include "net"
779 if net_service "${myservice}" ; then
780 for (( x=0 ; x < ${#sorted[*]} ; x++ )) ; do
781 if [[ ${sorted[x]} == "net" ]] ; then
782 unset sorted[x]
783 break
784 fi
785 done
786 sorted=( ${sorted[@]} )
787 fi
788 else
789 local netserv y
790
791 # XXX: I dont think RC_NET_STRICT_CHECKING should be considered
792 # here, but you never know ...
793 netserv=$(cd "${svcdir}"/started; ls net.* 2>/dev/null)
794
795 # Replace 'net' with the actual running services
796 for (( x=0 ; x < ${#sorted[*]} ; x++ )) ; do
797 if [[ ${sorted[x]} == "net" ]] ; then
798 y=$((${x} + 1))
799 sorted=( "${sorted[@]:0:${x}}" ${netserv} "${sorted[@]:${y}}" )
800 fi
801 done
802 fi
803
804 echo ${sorted[@]}
805 }
806
807 # bool query_before(service1, service2)
808 #
809 # Return true if 'service2' should be started *before*
810 # service1.
811 #
812 query_before() {
813 local x list
814 local netservice="no"
815
816 [[ -z $1 || -z $2 ]] && return 1
817
818 list=$( trace_dependencies "$1" )
819
820 net_service "$2" && netservice="yes"
821
822 for x in ${list} ; do
823 [[ ${x} == "$2" ]] && return 0
824
825 # Also match "net" if this is a network service ...
826 [[ ${netservice} == "yes" && ${x} == "net" ]] && return 0
827 done
828
829 return 1
830 }
831
832 # vim:ts=4

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20