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 /sbin/$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 /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 "$@" 63} 64 65while getopts 'saf' opt 66do 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 73done 74shift `expr $OPTIND - 1` 75 76case "$#:$1" in 771:start|1:stop|1:down|1:autoboot) 78 action=$1 79 ;; 80*) usage 81esac 82 83case $action in 84autoboot|start) 85 86 # National keyboard? 87 test -f /etc/keymap && loadkeys /etc/keymap 88 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 95 96 if [ "`sysenv debug_fkeys`" != 0 ] 97 then 98 up -n is -period 5HZ 99 fi 100 101 # Set timezone. 102 export TZ=GMT0 103 if [ -f "$RC_TZ" ] 104 then . "$RC_TZ" 105 fi 106 107 # Start real time clock driver & set system time, otherwise default date. 108 up readclock.drv 109 readclock -q || date 201301010000 110 111 # We are not shutting down. 112 rm -f /etc/nologin 113 114 # Initialize files. 115 >/var/run/utmp # /etc/utmp keeps track of logins 116 >/var/run/utmpx # /etc/utmpx keeps track of logins 117 118 # Use MFS binary only from kernel image? 119 if [ "`sysenv bin_img`" = 1 ] 120 then 121 bin_img="-i " 122 fi 123 124 # Are we booting from CD? 125 bootcd="`/bin/sysenv bootcd`" 126 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 138 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" 142 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 157 158 if [ "$sflag" ] 159 then 160 echo "Single user. Press ^D to resume multiuser startup." 161 intr sh 162 echo 163 fi 164 165 echo "Multiuser startup in progress ..." 166 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 175 176 if [ $ARCH = i386 ] 177 then 178 echo -n "Starting hotplugging infrastructure... " 179 rm -f /var/run/devmand.pid 180 devmand -d /etc/devmand -d /usr/pkg/etc/devmand & 181 echo "done." 182 fi 183 184 # Things should be alright now. 185 ;; 186down|stop) 187 sync 188 if [ $ARCH = i386 ] 189 then 190 if [ -f /var/run/devmand.pid ] 191 then 192 kill -INT `cat /var/run/devmand.pid` 193 # without this delay the following will 194 # be printed in the console 195 # RS: devman not running? 196 sleep 1 197 fi 198 # 199 # usbd needs to be stopped exactly 200 # at this stage(before stopping devman 201 # and after stopping the services 202 # stated by devmand) 203 if [ -x /usr/pkg/etc/rc.d/usbd ] 204 then 205 /usr/pkg/etc/rc.d/usbd stop 206 fi 207 fi 208 209 # Tell RS server we're going down. 210 service shutdown 211 ;; 212esac 213 214# Further initialization. 215test -f /usr/etc/rc && sh /usr/etc/rc $action 216test -f /usr/local/etc/rc && sh /usr/local/etc/rc $action 217 218# Any messages? 219if [ "$action" = start -o "$action" = autoboot ] 220then if [ -f /etc/issue ] 221 then cat /etc/issue 222 fi 223fi 224 225exit 0 226