1 | # /usr/etc/rc - continued system initialization.
|
---|
2 |
|
---|
3 | RANDOM_FILE=/usr/adm/random.dat
|
---|
4 | LOCAL_FILE=/usr/etc/rc.local
|
---|
5 |
|
---|
6 | case "$#:$1" in
|
---|
7 | 1:start|1:stop|1:down)
|
---|
8 | action=$1
|
---|
9 | ;;
|
---|
10 | *) echo >&2 "Usage: $0 start|stop|down"
|
---|
11 | exit 1
|
---|
12 | esac
|
---|
13 |
|
---|
14 | if [ -f "$LOCAL_FILE" ]
|
---|
15 | then . "$LOCAL_FILE" $1
|
---|
16 | fi
|
---|
17 |
|
---|
18 | disabled()
|
---|
19 | {
|
---|
20 | ifs="$IFS"; IFS=,
|
---|
21 | for skip in `sysenv disable`
|
---|
22 | do
|
---|
23 | if [ "$skip" = "$1" ]
|
---|
24 | then
|
---|
25 | IFS="$ifs"; unset ifs
|
---|
26 | return 0
|
---|
27 | fi
|
---|
28 | done
|
---|
29 | IFS="$ifs"; unset ifs
|
---|
30 | return 1
|
---|
31 | }
|
---|
32 |
|
---|
33 | daemonize()
|
---|
34 | {
|
---|
35 | # Function to start a daemon, if it exists.
|
---|
36 | local IFS=':'
|
---|
37 | local name="$1"
|
---|
38 | test "$1" = tcpd && name="$2"
|
---|
39 |
|
---|
40 | for dir in $PATH
|
---|
41 | do
|
---|
42 | if [ -f "$dir/$1" ]
|
---|
43 | then
|
---|
44 |
|
---|
45 | # check if this service is disabled at the boot monitor.
|
---|
46 | if disabled $name; then return; fi
|
---|
47 |
|
---|
48 | echo -n " $name"
|
---|
49 | "$@" &
|
---|
50 | return
|
---|
51 | fi
|
---|
52 | done
|
---|
53 | }
|
---|
54 |
|
---|
55 | up()
|
---|
56 | {
|
---|
57 | service=$1
|
---|
58 | shift
|
---|
59 |
|
---|
60 | # Function to dynamically start a system service
|
---|
61 |
|
---|
62 | # First check if this service is disabled at the boot monitor.
|
---|
63 | if disabled $service; then return; fi
|
---|
64 |
|
---|
65 | # Service is not disabled. Try to bring it up.
|
---|
66 | echo -n " $service"
|
---|
67 | service up /usr/sbin/$service "$@"
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | DAEMONS=/etc/rc.daemons
|
---|
72 |
|
---|
73 | case $action in
|
---|
74 | start)
|
---|
75 | # Select console font.
|
---|
76 | test -f /etc/font && loadfont /etc/font </dev/console
|
---|
77 |
|
---|
78 | # Cleanup.
|
---|
79 | rm -rf /tmp/. /usr/run/. /usr/spool/lpd/. /usr/spool/locks/.
|
---|
80 |
|
---|
81 | # Start servers and drivers set at the boot monitor.
|
---|
82 | echo -n "Starting services:"
|
---|
83 | up random -dev /dev/random -period 3HZ
|
---|
84 |
|
---|
85 | # load random number generator
|
---|
86 | if [ -f $RANDOM_FILE ]
|
---|
87 | then
|
---|
88 | cat < $RANDOM_FILE >/dev/random
|
---|
89 | # overwrite $RANDOM_FILE. We don't want to use this data again
|
---|
90 | dd if=/dev/random of=$RANDOM_FILE bs=1024 count=1 2> /dev/null
|
---|
91 | fi
|
---|
92 |
|
---|
93 | # start only network drivers that are in use
|
---|
94 | for driver in lance rtl8139 fxp dpeth dp8390
|
---|
95 | do
|
---|
96 | if grep " $driver " /etc/inet.conf > /dev/null 2>&1
|
---|
97 | then
|
---|
98 | eval arg=\$${driver}_arg
|
---|
99 | if [ ! -z "$arg" ]; then arg="-args \"$arg\""; fi
|
---|
100 | eval up $driver $arg -period 5HZ
|
---|
101 | fi
|
---|
102 | done
|
---|
103 | up inet
|
---|
104 | up printer -dev /dev/lp -period 10HZ
|
---|
105 | echo .
|
---|
106 |
|
---|
107 | # Network initialization.
|
---|
108 | (: </dev/tcp) 2>/dev/null && net=t # Is there a TCP/IP server?
|
---|
109 |
|
---|
110 | echo -n "Starting daemons:"
|
---|
111 | daemonize update
|
---|
112 |
|
---|
113 | # Ugly error message when starting cron from CD.
|
---|
114 | # (and cron unnecessary then so..)
|
---|
115 | if [ ! -f /CD ]
|
---|
116 | then daemonize cron
|
---|
117 | else mkdir /tmp/log
|
---|
118 | rm -f /var/log || true
|
---|
119 | ln -s /tmp/log /var/log || true
|
---|
120 | . /etc/rc.cd
|
---|
121 | fi
|
---|
122 | # syslogd has not been started yet
|
---|
123 | rm -f /var/run/syslogd.pid
|
---|
124 | daemonize syslogd
|
---|
125 | echo .
|
---|
126 |
|
---|
127 | if [ "$net" ]
|
---|
128 | then
|
---|
129 | if [ -f /etc/rc.net ]
|
---|
130 | then
|
---|
131 | # Let a customized TCP/IP initialization script figure it out.
|
---|
132 | . /etc/rc.net
|
---|
133 | else
|
---|
134 | # Standard network daemons.
|
---|
135 | echo -n "Starting networking:"
|
---|
136 | if grep -s 'psip0.*default' /etc/inet.conf
|
---|
137 | then ifconfig -h 10.0.0.1
|
---|
138 | else daemonize dhcpd
|
---|
139 | fi
|
---|
140 | daemonize nonamed -L
|
---|
141 | if [ -f "$DAEMONS" ]
|
---|
142 | then . "$DAEMONS"
|
---|
143 | fi
|
---|
144 | # The last daemon has been started, so close the list:
|
---|
145 | echo .
|
---|
146 | fi
|
---|
147 | fi
|
---|
148 |
|
---|
149 | if [ "$net" ]
|
---|
150 | then
|
---|
151 | # Get the nodename from the DNS and set it.
|
---|
152 | trap '' 2
|
---|
153 | intr -t 20 hostaddr -h || echo "Unable to obtain an IP address."
|
---|
154 | trap 2
|
---|
155 | fi
|
---|
156 |
|
---|
157 | # Recover files being edited when the system crashed.
|
---|
158 | test -f /usr/bin/elvprsv && elvprsv /usr/tmp/elv*
|
---|
159 |
|
---|
160 | # Run the daily cleanup on systems that are not on at night.
|
---|
161 | test -f /usr/etc/daily && sh /usr/etc/daily boot &
|
---|
162 |
|
---|
163 | ;;
|
---|
164 | stop|down)
|
---|
165 | # Save random data, if /usr is mounted rw.
|
---|
166 | if grep ' \/usr .*rw' /etc/mtab >/dev/null
|
---|
167 | then
|
---|
168 | if dd if=/dev/random of=$RANDOM_FILE.new bs=1024 count=1 2>/dev/null
|
---|
169 | then
|
---|
170 | mv $RANDOM_FILE.new $RANDOM_FILE
|
---|
171 | else
|
---|
172 | echo 'Failed to save random data.'
|
---|
173 | fi
|
---|
174 | fi
|
---|
175 | esac
|
---|
176 |
|
---|
177 | d=/usr/local/etc/rc.d
|
---|
178 | # Let packages run their own scripts
|
---|
179 | if [ -d "$d" ]
|
---|
180 | then if cd $d
|
---|
181 | then
|
---|
182 | echo -n "Local packages ($action): "
|
---|
183 | for f in *
|
---|
184 | do
|
---|
185 | if [ -x "$f" ]
|
---|
186 | then echo -n "$f "
|
---|
187 | sh "$f" "$action"
|
---|
188 | fi
|
---|
189 | done
|
---|
190 | echo " done."
|
---|
191 | fi
|
---|
192 | fi
|
---|
193 |
|
---|