1# /usr/etc/rc - continued system initialization. 2 3RANDOM_FILE=/usr/adm/random.dat 4LOCAL_FILE=/usr/etc/rc.local 5 6ARCH="`sysenv arch`" 7 8if [ ! "$ARCH" ] 9then # Older kernels do not provide an arch sysenv variable. 10 # We assume we are on x86 then, as existing systems with 11 # kernel and userland (i.e. this script) unsynchronized 12 # will be x86. 13 ARCH=i386 14fi 15 16# Get $SERVICES_DIRS 17. /etc/rc.conf 18 19# Directories to find services in 20if [ ! "$SERVICES_DIRS" ] 21then SERVICES_DIRS=/usr/sbin 22fi 23 24# Booting from cd? 25bootcd="`/bin/sysenv bootcd`" 26 27case "$#:$1" in 281:start|1:stop|1:down) 29 action=$1 30 ;; 31*) echo >&2 "Usage: $0 start|stop|down" 32 exit 1 33esac 34 35if [ -f "$LOCAL_FILE" ] 36then . "$LOCAL_FILE" $1 37fi 38 39disabled() 40{ 41 ifs="$IFS"; IFS=, 42 for skip in `sysenv disable` 43 do 44 if [ "$skip" = "$1" ] 45 then 46 IFS="$ifs"; unset ifs 47 return 0 48 fi 49 done 50 IFS="$ifs"; unset ifs 51 return 1 52} 53 54daemonize() 55{ 56 # Function to start a daemon, if it exists. 57 local IFS=':' 58 local name="$1" 59 test "$1" = tcpd && name="$2" 60 61 for dir in $PATH 62 do 63 if [ -f "$dir/$1" ] 64 then 65 66 # check if this service is disabled at the boot monitor. 67 if disabled $name; then return; fi 68 69 echo -n " $name" 70 "$@" & 71 return 72 fi 73 done 74} 75 76up() 77{ 78 # Function to dynamically start a system service 79 opt="" 80 prefix=$(expr "$1 " : '\(-\)') 81 if [ "$prefix" = "-" ]; 82 then 83 opt=$1 84 shift 85 fi 86 service=$1 87 shift 88 89 # First check if this service is disabled at the boot monitor. 90 if disabled $service; then return; fi 91 92 # Service is not disabled. Try to bring it up. 93 found="" 94 for dir in $SERVICES_DIRS 95 do bin=$dir/$service 96 if [ -x $bin -a -z "$found" ] 97 then service $opt up $bin "$@" 98 echo -n " $service" 99 found=yes 100 fi 101 done 102 if [ -z "$found" ] 103 then echo " ($service not found in $SERVICES_DIRS)" 104 fi 105} 106 107get_eth_labels() { 108 # Filter out the non-vlan ethernet entries from inet.conf. 109 # Produce as output a list of "drivername_instancenr"-formatted labels. 110 sed 's/\008/ /g' /etc/inet.conf | \ 111 sed -n 's/^ *eth[0-9][0-9]* *\([^ ][^ ]*\) *\([0-9][0-9]*\).*$/\1_\2/p' | \ 112 grep -v '^vlan_' 113} 114 115DAEMONS=/etc/rc.daemons 116 117case $action in 118start) 119 # Select console font. 120 test -f /etc/font && loadfont /etc/font </dev/console 121 122 # Cleanup. 123 rm -rf /tmp/* /usr/run/* /usr/spool/lpd/* /usr/spool/locks/* 124 125 # Start servers and drivers set at the boot monitor. 126 echo -n "Starting services:" 127 up -n random -dev /dev/random -devstyle STYLE_DEVA -period 3HZ 128 129 # load random number generator 130 if [ -f $RANDOM_FILE ] 131 then 132 cat < $RANDOM_FILE >/dev/random 133 # overwrite $RANDOM_FILE. We don't want to use this data again 134 dd if=/dev/random of=$RANDOM_FILE bs=1024 count=1 2> /dev/null 135 fi 136 137 # start network driver instances for all configured ethernet devices 138 for label in $(get_eth_labels); do 139 driver=$(echo $label | sed 's/\(.*\)_.*/\1/') 140 instance=$(echo $label | sed 's/.*_//') 141 eval arg=\$${label}_arg 142 if [ ! -z "$arg" ]; then arg=" $arg"; fi 143 arg="-args \"instance=$instance$arg\"" 144 eval up $driver -label $label $arg -period 5HZ 145 done 146 if [ X`/bin/sysenv lwip` = Xyes ] 147 then 148 up lwip -script /etc/rs.inet -dev /dev/ip -devstyle STYLE_CLONE_A 149 else 150 up inet -script /etc/rs.inet -dev /dev/ip -devstyle STYLE_CLONE 151 fi 152 153 up -n ipc 154 155 if [ $ARCH = i386 ] 156 then 157 up -n printer -dev /dev/lp -period 10HZ 158 # start VirtualBox time sync driver if the device is there 159 if grep '^[^ ]* [^ ]* 80EE:CAFE ' /proc/pci >/dev/null; then 160 up -n vbox -period 10HZ 161 fi 162 fi 163 164 echo . 165 166 # Network initialization. 167 (: </dev/tcp) 2>/dev/null && net=t # Is there a TCP/IP server? 168 169 echo -n "Starting daemons:" 170 daemonize update 171 172 # Ugly error message when starting cron from CD. 173 # (and cron unnecessary then so..) 174 if [ ! -f /CD ] 175 then daemonize cron 176 else mkdir /tmp/log 177 rm -f /var/log || true 178 ln -s /tmp/log /var/log || true 179 . /etc/rc.cd 180 fi 181 # syslogd has not been started yet 182 rm -f /var/run/syslogd.pid 183 daemonize syslogd 184 echo . 185 186 # i2c only supported on ARM at the moment 187 if [ $ARCH = earm ] 188 then 189 echo -n "Starting i2c subsystem: " 190 for bus in 1 2 3 191 do 192 test -e /dev/i2c-${bus} || (cd /dev && MAKEDEV i2c-${bus}) 193 up i2c -dev /dev/i2c-${bus} -label i2c.${bus} \ 194 -args instance=${bus} 195 done 196 echo . 197 198 BOARD_NAME=`eepromread -i | sed -n 's/^BOARD_NAME : \(.*\)$/\1/p'` 199 case "${BOARD_NAME}" in 200 A335BONE) 201 echo "Detected BeagleBone" 202 echo -n "Starting i2c device drivers: " 203 test -e /dev/eepromb1s50 || (cd /dev && MAKEDEV eepromb1s50) 204 up cat24c256 -dev /dev/eepromb1s50 \ 205 -label cat24c256.1.50 -args 'bus=1 address=0x50' 206 ;; 207 A335BNLT) 208 echo "Detected BeagleBone Black" 209 echo -n "Starting i2c device drivers: " 210 test -e /dev/eepromb1s50 || (cd /dev && MAKEDEV eepromb1s50) 211 up cat24c256 -dev /dev/eepromb1s50 \ 212 -label cat24c256.1.50 -args 'bus=1 address=0x50' 213 ;; 214 UNKNOWN) 215 echo "Unable to detect board -- assuming BeagleBoard-xM" 216 echo -n "Starting i2c device drivers: " 217 ;; 218 esac 219 220 echo . 221 fi 222 223 if [ "$net" ] 224 then 225 if [ -f /etc/rc.net ] 226 then 227 # Let a customized TCP/IP initialization script figure it out. 228 . /etc/rc.net 229 else 230 # Standard network daemons. 231 echo -n "Starting networking:" 232 if grep -s 'psip0.*default' /etc/inet.conf >/dev/null 233 then ifconfig -h 10.0.0.1 234 else 235 if [ X`/bin/sysenv lwip` = Xyes ] 236 then 237 dhcpd --lwip & 238 echo -n " dhcpd" 239 else 240 daemonize dhcpd 241 fi 242 fi 243 daemonize nonamed -L 244 if [ -f "$DAEMONS" ] 245 then . "$DAEMONS" 246 fi 247 # The last daemon has been started, so close the list: 248 echo . 249 fi 250 fi 251 252 if [ "$net" ] 253 then 254 # Get the nodename from the DNS and set it. 255 trap '' 2 256 intr -t 20 hostaddr -h 257 trap 2 258 fi 259 260 # Recover files being edited when the system crashed. 261 test -f /usr/bin/elvprsv && elvprsv /usr/tmp/elv* 262 263 # Run the daily cleanup on systems that are not on at night. 264 test -f /usr/etc/daily && sh /usr/etc/daily boot & 265;; 266stop|down) 267 # Save random data, if /usr is mounted rw. 268 if grep ' \/usr .*rw.*' /etc/mtab >/dev/null 269 then 270 if dd if=/dev/random of=$RANDOM_FILE.new bs=1024 count=1 2>/dev/null 271 then 272 mv $RANDOM_FILE.new $RANDOM_FILE 273 else 274 echo 'Failed to save random data.' 275 fi 276 fi 277esac 278 279d= 280# Let packages run their own scripts 281for d in /usr/local/etc/rc.d /usr/pkg/etc/rc.d 282do 283if [ -d "$d" -a -z "$bootcd" ] 284then ( if cd $d 285 then 286 echo -n "Local packages ($action): " 287 for f in * 288 do 289 if [ -x "$f" ] 290 then echo -n "$f " 291 sh "$f" "$action" 292 fi 293 done 294 echo " done." 295 fi 296 ) 297fi 298done 299