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