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