* Fixed problem when BASEDIR paths were given without a trailing '/'.
[linux_from_scratch.git] / bootscripts / lfs / init.d / rc
blobfb57f5304b8c257c0894c4bc87cdd351922703d5
1 #!/bin/sh
2 # Begin $rc_base/init.d/rc - Main Run Level Control Script
4 # Based on rc script from LFS-3.1 and earlier.
5 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
7 . /etc/sysconfig/rc
8 . $rc_functions
10 # This sets a few default terminal options.
11 stty sane
13 # These 3 signals will not cause our script to exit
14 trap "" INT QUIT TSTP
16 [ "$1" != "" ] && runlevel=$1
18 if [ "$runlevel" = "" ]
19 then
20 echo "Usage: $0 <runlevel>" >&2
21 exit 1
24 previous=$PREVLEVEL
25 [ "$previous" = "" ] && previous=N
27 if [ ! -d $rc_base/rc$runlevel.d ]
28 then
29 echo "$rc_base/rc$runlevel.d does not exist"
30 exit 1
33 # Attempt to stop all service started by previous runlevel,
34 # and killed in this runlevel
35 if [ "$previous" != "N" ]
36 then
37 for i in $(ls -v $rc_base/rc$runlevel.d/K* 2> /dev/null)
40 check_script_status
42 suffix=${i#$rc_base/rc$runlevel.d/K[0-9][0-9]}
43 prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix
44 sysinit_start=$rc_base/rcsysinit.d/S[0-9][0-9]$suffix
46 if [ "$runlevel" != "0" ] && [ "$runlevel" != "6" ]
47 then
48 if [ ! -f $prev_start ] && [ ! -f $sysinit_start ]
49 then
50 echo -n -e $WARNING
51 echo "$i can't be executed because it was"
52 echo "not started in the previous runlevel ($previous)"
53 echo -n -e $NORMAL
54 continue
57 $i stop
58 error_value=$?
60 if [ "$error_value" != "0" ]
61 then
62 print_error_msg
64 done
67 #Start all functions in this runlevel
68 for i in $( ls -v $rc_base/rc$runlevel.d/S* 2> /dev/null)
70 if [ "$previous" != "N" ]
71 then
72 suffix=${i#$rc_base/rc$runlevel.d/S[0-9][0-9]}
73 stop=$rc_base/rc$runlevel.d/K[0-9][0-9]$suffix
74 prev_start=$rc_base/rc$previous.d/S[0-9][0-9]$suffix
76 [ -f $prev_start ] && [ ! -f $stop ] && continue
79 check_script_status
81 $i start
82 error_value=$?
84 if [ "$error_value" != "0" ]
85 then
86 print_error_msg
88 done
90 # End $rc_base/init.d/rc