diff options
Diffstat (limited to 'meta/packages/sysvinit/sysvinit/rc')
-rwxr-xr-x | meta/packages/sysvinit/sysvinit/rc | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/meta/packages/sysvinit/sysvinit/rc b/meta/packages/sysvinit/sysvinit/rc new file mode 100755 index 0000000000..fdb0fce887 --- /dev/null +++ b/meta/packages/sysvinit/sysvinit/rc | |||
@@ -0,0 +1,102 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # rc This file is responsible for starting/stopping | ||
4 | # services when the runlevel changes. | ||
5 | # | ||
6 | # Optimization feature: | ||
7 | # A startup script is _not_ run when the service was | ||
8 | # running in the previous runlevel and it wasn't stopped | ||
9 | # in the runlevel transition (most Debian services don't | ||
10 | # have K?? links in rc{1,2,3,4,5} ) | ||
11 | # | ||
12 | # Author: Miquel van Smoorenburg <miquels@cistron.nl> | ||
13 | # Bruce Perens <Bruce@Pixar.com> | ||
14 | # | ||
15 | # Version: @(#)rc 2.78 07-Nov-1999 miquels@cistron.nl | ||
16 | # | ||
17 | |||
18 | . /etc/default/rcS | ||
19 | export VERBOSE | ||
20 | |||
21 | # | ||
22 | # Start script or program. | ||
23 | # | ||
24 | startup() { | ||
25 | case "$1" in | ||
26 | *.sh) | ||
27 | sh "$@" | ||
28 | ;; | ||
29 | *) | ||
30 | "$@" | ||
31 | ;; | ||
32 | esac | ||
33 | } | ||
34 | |||
35 | # Ignore CTRL-C only in this shell, so we can interrupt subprocesses. | ||
36 | trap ":" INT QUIT TSTP | ||
37 | |||
38 | # Set onlcr to avoid staircase effect. | ||
39 | stty onlcr 0>&1 | ||
40 | |||
41 | # Now find out what the current and what the previous runlevel are. | ||
42 | |||
43 | runlevel=$RUNLEVEL | ||
44 | # Get first argument. Set new runlevel to this argument. | ||
45 | [ "$1" != "" ] && runlevel=$1 | ||
46 | if [ "$runlevel" = "" ] | ||
47 | then | ||
48 | echo "Usage: $0 <runlevel>" >&2 | ||
49 | exit 1 | ||
50 | fi | ||
51 | previous=$PREVLEVEL | ||
52 | [ "$previous" = "" ] && previous=N | ||
53 | |||
54 | export runlevel previous | ||
55 | |||
56 | # Is there an rc directory for this new runlevel? | ||
57 | if [ -d /etc/rc$runlevel.d ] | ||
58 | then | ||
59 | # First, run the KILL scripts. | ||
60 | if [ $previous != N ] | ||
61 | then | ||
62 | for i in /etc/rc$runlevel.d/K[0-9][0-9]* | ||
63 | do | ||
64 | # Check if the script is there. | ||
65 | [ ! -f $i ] && continue | ||
66 | |||
67 | # Stop the service. | ||
68 | startup $i stop | ||
69 | done | ||
70 | fi | ||
71 | # Now run the START scripts for this runlevel. | ||
72 | for i in /etc/rc$runlevel.d/S* | ||
73 | do | ||
74 | [ ! -f $i ] && continue | ||
75 | |||
76 | if [ $previous != N ] && [ $previous != S ] | ||
77 | then | ||
78 | # | ||
79 | # Find start script in previous runlevel and | ||
80 | # stop script in this runlevel. | ||
81 | # | ||
82 | suffix=${i#/etc/rc$runlevel.d/S[0-9][0-9]} | ||
83 | stop=/etc/rc$runlevel.d/K[0-9][0-9]$suffix | ||
84 | previous_start=/etc/rc$previous.d/S[0-9][0-9]$suffix | ||
85 | # | ||
86 | # If there is a start script in the previous level | ||
87 | # and _no_ stop script in this level, we don't | ||
88 | # have to re-start the service. | ||
89 | # | ||
90 | [ -f $previous_start ] && [ ! -f $stop ] && continue | ||
91 | fi | ||
92 | case "$runlevel" in | ||
93 | 0|6) | ||
94 | startup $i stop | ||
95 | ;; | ||
96 | *) | ||
97 | startup $i start | ||
98 | ;; | ||
99 | esac | ||
100 | done | ||
101 | fi | ||
102 | # eof /etc/init.d/rc | ||