xref: /minix/etc/rc (revision 0a6a1f1d)
1# /etc/rc - System startup script run by init before going multiuser.
2
3# Are we booting from CD?
4bootcd="`/bin/sysenv bootcd`"
5
6exec >/dev/log
7exec 2>/dev/log
8exec </dev/null
9
10umask 022
11
12# Same settings as in the default /etc/profile. We do not source this file
13# as the system administrator may decide to change those values for his users.
14RC_TZ=/etc/rc.timezone
15PATH=/usr/local/sbin:/usr/pkg/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/pkg/bin:/usr/bin:/bin
16
17# Set TERM to minix if not present.
18TERM="${TERM-minix}"
19
20export TERM PATH
21
22# Local variables
23ARCH="`sysenv arch`"
24
25usage()
26{
27    echo >&2 "Usage: $0 [-saf] autoboot|start|stop|down"
28    exec intr sh
29}
30
31up()
32{
33    # Function to dynamically start a system service
34    opt=""
35    prefix=$(expr "$1 " : '\(-\)')
36    if [ "$prefix" = "-" ];
37    then
38         opt=$1
39         shift
40    fi
41    service=$1
42    shift
43
44    service $opt up /service/$service "$@"
45}
46
47edit()
48{
49    # Function to dynamically edit system service settings
50    opt=""
51    prefix=$(expr "$1 " : '\(-\)')
52    if [ "$prefix" = "-" ];
53    then
54         opt=$1
55         shift
56    fi
57    service=$1
58    shift
59
60    # Assume binaries are always in /service or /usr/pkg/service
61    binlocation=/service/$service
62    if [ ! -x $binlocation ]
63    then	binlocation=/usr/pkg/service/$service
64    fi
65
66    # Mostly to find init...
67    if [ ! -x $binlocation ]
68    then	binlocation=/sbin/$service
69    fi
70    service $opt edit $binlocation -label $service "$@"
71}
72
73while getopts 'saf' opt
74do
75    case $opt in
76    s)	sflag=t ;;	# Single user
77    a)	aflag=t ;;	# Ask for /usr
78    f)	fflag=-f ;;	# Force a full file system check
79    *)	usage
80    esac
81done
82shift `expr $OPTIND - 1`
83
84case "$#:$1" in
851:start|1:stop|1:down|1:autoboot)
86    action=$1
87    ;;
88*)  usage
89esac
90
91case $action in
92autoboot|start)
93    # If booting from CD, we want some directories to be ramdisks
94    if [ ! -z "$bootcd" ]
95    then
96	. /etc/rc.cd
97    fi
98
99    # National keyboard?
100    test -f /etc/keymap && loadkeys /etc/keymap
101
102    # options for fsck. default is -r, which prompts the user for repairs.
103    optname=fsckopts
104    fsckopts=-p
105    if sysenv $optname >/dev/null
106    then       fsckopts="`sysenv $optname`"
107    fi
108
109    if [ "`sysenv debug_fkeys`" != 0 ]
110    then
111        up -n is -period 5HZ
112    fi
113
114    # Set timezone.
115    export TZ=GMT0
116    if [ -f "$RC_TZ" ]
117    then
118         . "$RC_TZ"
119    fi
120
121    # Start real time clock driver & set system time, otherwise default date.
122    up readclock.drv
123    readclock -q || date 201301010000
124
125    # We are not shutting down.
126    if [ -f /etc/nologin ]
127    then
128        rm -f /etc/nologin
129    fi
130
131    # Use MFS binary only from kernel image?
132    if [ "`sysenv bin_img`" = 1 ]
133    then
134        bin_img="-i "
135    fi
136
137    # fsck + mount using /etc/fstab.
138    fsck -x / $fflag $fsckopts
139    mount -a
140
141    # Unmount and free now defunct ramdisk
142    umount /dev/imgrd > /dev/null || echo "Failed to unmount boot ramdisk"
143    ramdisk 0 /dev/imgrd || echo "Failed to free boot ramdisk"
144
145    # Initialize files.
146    >/var/run/utmp				# /etc/utmp keeps track of logins
147    >/var/run/utmpx				# /etc/utmpx keeps track of logins
148
149    # Edit settings for boot system services
150    if [ "`sysenv skip_boot_config`" != 1 ]
151    then
152	edit rs
153	edit vm
154	edit pm
155	edit sched
156	edit vfs
157	edit ds
158	edit tty
159	edit memory
160	edit pfs
161	edit init
162	#
163	# Keep a copy around to recover the root FS from crashes
164	#
165	rootline=`cat /etc/mtab | grep "on / "`
166	rootfs=fs_`echo "$rootline" | cut -d' ' -f1 | cut -d'/' -f3`
167	roottype=`echo "$rootline" | cut -d' ' -f5`
168	service -c edit /service/$roottype -label $rootfs
169    fi
170
171    if [ "$sflag" ]
172    then
173	echo "Single user. Press ^D to resume multiuser startup."
174	intr sh
175	echo
176    fi
177
178    echo "Multiuser startup in progress ..."
179
180    case "`printroot -r`":$bootcd in
181    /dev/ram:)
182	# Remove boot-only things to make space,
183	# unless booting from CD, in which case we need them.
184	rm -rf /boot
185	# put the compiler on ram
186	cp /usr/lib/em* /usr/lib/cpp* /lib
187    esac
188
189    echo -n "Starting hotplugging infrastructure... "
190    rm -f /var/run/devmand.pid
191    devmand -d /etc/devmand -d /usr/pkg/etc/devmand &
192    echo "done."
193
194    # Things should be alright now.
195    ;;
196down|stop)
197    sync
198    if [ -f /var/run/devmand.pid ]
199    then
200	kill -INT `cat /var/run/devmand.pid`
201	# without this delay the following will
202	# be printed in the console
203	# RS: devman not running?
204	sleep 1
205    fi
206    #
207    # usbd needs to be stopped exactly
208    # at this stage(before stopping devman
209    # and after stopping the services
210    # stated by devmand)
211    if [ -x /usr/pkg/etc/rc.d/usbd ]
212    then
213	/usr/pkg/etc/rc.d/usbd stop
214    fi
215
216    if [ -x /service/usbd ]
217    then
218	service down usbd
219    fi
220
221    # Tell RS server we're going down.
222    service shutdown
223    ;;
224esac
225
226# Further initialization.
227test -f /usr/etc/rc && sh /usr/etc/rc $action
228test -f /usr/local/etc/rc && sh /usr/local/etc/rc $action
229
230# Any messages?
231if [ "$action" = start -o "$action" = autoboot ]
232then	if [ -f /etc/issue ]
233	then	cat /etc/issue
234	fi
235fi
236
237exit 0
238