38d4ae2dfa8f722699d4883ef858d2711bde3066
[people/pmueller/ipfire-2.x.git] / src / initscripts / init.d / rc
1 #!/bin/sh
2 ########################################################################
3 # Begin $rc_base/init.d/rc
4 #
5 # Description : Main Run Level Control Script
6 #
7 # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
8 #
9 # Version : 00.00
10 #
11 # Notes :
12 #
13 ########################################################################
14
15 . /etc/sysconfig/rc
16 . ${rc_functions}
17
18 # This sets a few default terminal options.
19 stty sane
20
21 # These 3 signals will not cause our script to exit
22 trap "" INT QUIT TSTP
23
24 [ "${1}" != "" ] && runlevel=${1}
25
26 if [ "${runlevel}" = "" ]; then
27 echo "Usage: ${0} <runlevel>" >&2
28 exit 1
29 fi
30
31 previous=${PREVLEVEL}
32 [ "${previous}" = "" ] && previous=N
33
34 if [ ! -d ${rc_base}/rc${runlevel}.d ]; then
35 boot_mesg "${rc_base}/rc${runlevel}.d does not exist." ${WARNING}
36 boot_mesg_flush
37 exit 1
38 fi
39
40 # Attempt to stop all service started by previous runlevel,
41 # and killed in this runlevel
42 if [ "${previous}" != "N" ]; then
43 for i in $(ls -v ${rc_base}/rc${runlevel}.d/K* 2> /dev/null)
44 do
45 check_script_status
46
47 suffix=${i#$rc_base/rc$runlevel.d/K[0-9][0-9]}
48 prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix
49 sysinit_start=$rc_base/rcsysinit.d/S[0-9][0-9]$suffix
50
51 if [ "${runlevel}" != "0" ] && [ "${runlevel}" != "6" ]; then
52 if [ ! -f ${prev_start} ] && [ ! -f ${sysinit_start} ]; then
53 boot_mesg -n "WARNING:\n\n${i} can't be" ${WARNING}
54 boot_mesg -n " executed because it was not"
55 boot_mesg -n " not started in the previous"
56 boot_mesg -n " runlevel (${previous})."
57 boot_mesg "" ${NORMAL}
58 boot_mesg_flush
59 continue
60 fi
61 fi
62 ${i} stop
63 error_value=${?}
64
65 if [ "${error_value}" != "0" ]; then
66 print_error_msg
67 fi
68 done
69 fi
70
71 #Start all functions in this runlevel
72 for i in $( ls -v ${rc_base}/rc${runlevel}.d/S* 2> /dev/null)
73 do
74 if [ "${previous}" != "N" ]; then
75 suffix=${i#$rc_base/rc$runlevel.d/S[0-9][0-9]}
76 stop=$rc_base/rc$runlevel.d/K[0-9][0-9]$suffix
77 prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix
78
79 [ -f ${prev_start} ] && [ ! -f ${stop} ] && continue
80 fi
81
82 check_script_status
83
84 case ${runlevel} in
85 0|6)
86 ${i} stop
87 ;;
88 *)
89 ${i} start
90 ;;
91 esac
92 error_value=${?}
93
94 if [ "${error_value}" != "0" ]; then
95 print_error_msg
96 fi
97 done
98
99 # End $rc_base/init.d/rc