xref: /minix3/etc/rc (revision a5f47c23d5b23ae7b216ed3fb4442881c82c7cb8)
19865aeaaSBen Gras# /etc/rc - System startup script run by init before going multiuser.
29865aeaaSBen Gras
3b6b361a4SBen Grasexec >/dev/log
4b6b361a4SBen Grasexec 2>/dev/log
5b6b361a4SBen Grasexec </dev/null
6b6b361a4SBen Gras
79865aeaaSBen Grasumask 022
8*a5f47c23SLionel Sambuc
9*a5f47c23SLionel Sambuc# Same settings as in the default /etc/profile. We do not source this file
10*a5f47c23SLionel Sambuc# as the system administrator may decide to change those values for his users.
1109a57f88SBen GrasRC_TZ=/etc/rc.timezone
12*a5f47c23SLionel SambucPATH=/usr/local/sbin:/usr/pkg/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/pkg/bin:/usr/bin:/bin
13*a5f47c23SLionel Sambuc
14*a5f47c23SLionel Sambuc# Set TERM to minix if not present.
15*a5f47c23SLionel SambucTERM="${TERM-minix}"
16*a5f47c23SLionel Sambuc
179865aeaaSBen Grasexport TERM PATH
189865aeaaSBen Gras
19*a5f47c23SLionel Sambuc# Local variables
205acaa081SBen GrasARCH="`sysenv arch`"
215acaa081SBen Gras
229865aeaaSBen Grasusage()
239865aeaaSBen Gras{
249865aeaaSBen Gras    echo >&2 "Usage: $0 [-saf] start|stop|down"
259865aeaaSBen Gras    exec intr sh
269865aeaaSBen Gras}
279865aeaaSBen Gras
283de6a807SCristiano Giuffridaup()
2974711a3bSJorrit Herder{
303de6a807SCristiano Giuffrida    # Function to dynamically start a system service
313de6a807SCristiano Giuffrida    opt=""
323de6a807SCristiano Giuffrida    prefix=$(expr "$1 " : '\(-\)')
333de6a807SCristiano Giuffrida    if [ "$prefix" = "-" ];
343de6a807SCristiano Giuffrida    then
3565ef5397SCristiano Giuffrida         opt=$1
3665ef5397SCristiano Giuffrida         shift
373de6a807SCristiano Giuffrida    fi
3874711a3bSJorrit Herder    service=$1
392aac756eSJorrit Herder    shift
4074711a3bSJorrit Herder
4165ef5397SCristiano Giuffrida    service $opt up /sbin/$service "$@"
4274711a3bSJorrit Herder}
4374711a3bSJorrit Herder
443de6a807SCristiano Giuffridaedit()
453de6a807SCristiano Giuffrida{
463de6a807SCristiano Giuffrida    # Function to dynamically edit system service settings
473de6a807SCristiano Giuffrida    opt=""
483de6a807SCristiano Giuffrida    prefix=$(expr "$1 " : '\(-\)')
493de6a807SCristiano Giuffrida    if [ "$prefix" = "-" ];
503de6a807SCristiano Giuffrida    then
513de6a807SCristiano Giuffrida         opt=$1
523de6a807SCristiano Giuffrida         shift
533de6a807SCristiano Giuffrida    fi
543de6a807SCristiano Giuffrida    service=$1
553de6a807SCristiano Giuffrida    shift
563de6a807SCristiano Giuffrida
573de6a807SCristiano Giuffrida    # Assume binaries are always in /usr/sbin
583de6a807SCristiano Giuffrida    service $opt edit /usr/sbin/$service -label $service "$@"
593de6a807SCristiano Giuffrida}
603de6a807SCristiano Giuffrida
619865aeaaSBen Graswhile getopts 'saf' opt
629865aeaaSBen Grasdo
639865aeaaSBen Gras    case $opt in
649865aeaaSBen Gras    s)	sflag=t ;;	# Single user
659865aeaaSBen Gras    a)	aflag=t ;;	# Ask for /usr
66cedeabb3SBen Gras    f)	fflag=-f ;;	# Force a full file system check
679865aeaaSBen Gras    *)	usage
689865aeaaSBen Gras    esac
699865aeaaSBen Grasdone
709865aeaaSBen Grasshift `expr $OPTIND - 1`
719865aeaaSBen Gras
729865aeaaSBen Grascase "$#:$1" in
739865aeaaSBen Gras1:start|1:stop|1:down)
749865aeaaSBen Gras    action=$1
759865aeaaSBen Gras    ;;
769865aeaaSBen Gras*)  usage
779865aeaaSBen Grasesac
789865aeaaSBen Gras
799865aeaaSBen Grascase $action in
809865aeaaSBen Grasstart)
8190b80ad3SJorrit Herder
829865aeaaSBen Gras    # National keyboard?
839865aeaaSBen Gras    test -f /etc/keymap && loadkeys /etc/keymap
849865aeaaSBen Gras
859fd4c2a2SBen Gras    # options for fsck. default is -r, which prompts the user for repairs.
864d4057d8SBen Gras    optname=fsckopts
874d4057d8SBen Gras    fsckopts=-p
884d4057d8SBen Gras    if sysenv $optname >/dev/null
894d4057d8SBen Gras    then       fsckopts="`sysenv $optname`"
909fd4c2a2SBen Gras    fi
919fd4c2a2SBen Gras
92123683d4SDavid van Moolenbroek    if [ "`sysenv debug_fkeys`" != 0 ]
93123683d4SDavid van Moolenbroek    then
943de6a807SCristiano Giuffrida        up -n is -period 5HZ
95123683d4SDavid van Moolenbroek    fi
9674711a3bSJorrit Herder
979865aeaaSBen Gras    # Set timezone.
9809a57f88SBen Gras    export TZ=GMT0
9909a57f88SBen Gras    if [ -f "$RC_TZ" ]
10009a57f88SBen Gras    then . "$RC_TZ"
10109a57f88SBen Gras    fi
1029865aeaaSBen Gras
10309db2a8cSThomas Cort    # Start real time clock driver & set system time, otherwise default date.
10409db2a8cSThomas Cort    up readclock.drv
1057f98bdf0SThomas Cort    readclock -q || date 201301010000
1069865aeaaSBen Gras
1079865aeaaSBen Gras    # Initialize files.
1089865aeaaSBen Gras    >/etc/utmp				# /etc/utmp keeps track of logins
1099865aeaaSBen Gras
110b4748343SThomas Veerman    # Use MFS binary only from kernel image?
111b4748343SThomas Veerman    if [ "`sysenv bin_img`" = 1 ]
112b4748343SThomas Veerman    then
113b4748343SThomas Veerman        bin_img="-i "
114b4748343SThomas Veerman    fi
115b4748343SThomas Veerman
1164c801701SBen Gras    # Are we booting from CD?
1174c801701SBen Gras    bootcd="`/bin/sysenv bootcd`"
1184c801701SBen Gras
119cedeabb3SBen Gras    # If booting from CD, mounting is a special case.
120cedeabb3SBen Gras    # We know what to do - only /usr is mounted and it's readonly.
1214c801701SBen Gras    if [ "$bootcd" = 1 ]
122cedeabb3SBen Gras    then	usrdev="$cddev"p2
123cedeabb3SBen Gras    		echo "/usr on cd is $usrdev"
124cedeabb3SBen Gras		mount -r $usrdev /usr
125cedeabb3SBen Gras    else
126cedeabb3SBen Gras    # If we're not booting from CD, fsck + mount using /etc/fstab.
127*a5f47c23SLionel Sambuc		fsck -x / $fflag $fsckopts
1286759b24cSThomas Veerman		mount -a
1294c801701SBen Gras    fi
130946603a6SBen Gras
131ed1af3c8SBen Gras    # Unmount and free now defunct ramdisk
132ed1af3c8SBen Gras    umount /dev/imgrd > /dev/null || echo "Failed to unmount boot ramdisk"
133ed1af3c8SBen Gras    ramdisk 0 /dev/imgrd || echo "Failed to free boot ramdisk"
134ed1af3c8SBen Gras
1353de6a807SCristiano Giuffrida    # Edit settings for boot system services
136f8a8ea0aSCristiano Giuffrida    if [ "`sysenv skip_boot_config`" != 1 ]
137f8a8ea0aSCristiano Giuffrida    then
1383de6a807SCristiano Giuffrida	edit rs
1393de6a807SCristiano Giuffrida	edit vm
1403de6a807SCristiano Giuffrida	edit pm
1413de6a807SCristiano Giuffrida	edit sched
1423de6a807SCristiano Giuffrida	edit vfs
1433de6a807SCristiano Giuffrida	edit ds
1443de6a807SCristiano Giuffrida	edit tty
1453de6a807SCristiano Giuffrida	edit memory
14636ac0dbcSDavid van Moolenbroek	edit pfs
147f8a8ea0aSCristiano Giuffrida	edit init
148f8a8ea0aSCristiano Giuffrida    fi
1493de6a807SCristiano Giuffrida
150e17ced44SBen Gras    # This file is necessary for above 'shutdown -C' check.
1514e38cf12SBen Gras    # (Silence stderr in case of running from cd.)
152cedeabb3SBen Gras    touch /usr/adm/wtmp /etc/wtmp 2>/dev/null
153e17ced44SBen Gras
1549865aeaaSBen Gras    if [ "$sflag" ]
1559865aeaaSBen Gras    then
1566659ae1fSThomas Veerman	echo "Single user. Press ^D to resume multiuser startup."
1579865aeaaSBen Gras	intr sh
1586659ae1fSThomas Veerman	echo
1599865aeaaSBen Gras    fi
1609865aeaaSBen Gras
1616659ae1fSThomas Veerman    echo "Multiuser startup in progress ..."
1626659ae1fSThomas Veerman
1634c801701SBen Gras    case "`printroot -r`":$bootcd in
1644c801701SBen Gras    /dev/ram:)
1654c801701SBen Gras	# Remove boot-only things to make space,
1664c801701SBen Gras	# unless booting from CD, in which case we need them.
1674c801701SBen Gras	rm -rf /boot
168a4ae9574SBen Gras	# put the compiler on ram
169a4ae9574SBen Gras	cp /usr/lib/em* /usr/lib/cpp* /lib
1709865aeaaSBen Gras    esac
1719865aeaaSBen Gras
1725acaa081SBen Gras    if [ $ARCH = i386 ]
1735acaa081SBen Gras    then
17477506577SKees Jongenburger	echo -n "Starting hotplugging infrastructure... "
17577506577SKees Jongenburger	rm -f /var/run/devmand.pid
17677506577SKees Jongenburger	devmand -d /etc/devmand -d /usr/pkg/etc/devmand &
17777506577SKees Jongenburger	echo "done."
1785acaa081SBen Gras    fi
17977506577SKees Jongenburger
1809865aeaaSBen Gras    # Things should be alright now.
1813e78f1aaSJorrit Herder    ;;
1823e78f1aaSJorrit Herderdown|stop)
1833e78f1aaSJorrit Herder    sync
1845acaa081SBen Gras    if [ $ARCH = i386 ]
1855acaa081SBen Gras    then
18677506577SKees Jongenburger	if [ -f /var/run/devmand.pid ]
18777506577SKees Jongenburger	then
18877506577SKees Jongenburger	    	kill -INT `cat /var/run/devmand.pid`
18977506577SKees Jongenburger		# without this delay the following will
19077506577SKees Jongenburger        	# be printed in the console
19177506577SKees Jongenburger        	# RS: devman not running?
19277506577SKees Jongenburger        	sleep 1
19377506577SKees Jongenburger    	fi
19477506577SKees Jongenburger	#
19577506577SKees Jongenburger	# usbd needs to be stopped exactly
19677506577SKees Jongenburger	# at this stage(before stopping devman
19777506577SKees Jongenburger	# and after stopping the services
19877506577SKees Jongenburger	# stated by devmand)
19977506577SKees Jongenburger	if [ -x /usr/pkg/etc/rc.d/usbd ]
20077506577SKees Jongenburger	then
20177506577SKees Jongenburger    		/usr/pkg/etc/rc.d/usbd stop
20277506577SKees Jongenburger	fi
2035acaa081SBen Gras    fi
2045acaa081SBen Gras
2053e78f1aaSJorrit Herder    # Tell RS server we're going down.
2063e78f1aaSJorrit Herder    service shutdown
2073e78f1aaSJorrit Herder    ;;
2089865aeaaSBen Grasesac
2099865aeaaSBen Gras
2109865aeaaSBen Gras# Further initialization.
2119865aeaaSBen Grastest -f /usr/etc/rc && sh /usr/etc/rc $action
2129865aeaaSBen Grastest -f /usr/local/etc/rc && sh /usr/local/etc/rc $action
2139865aeaaSBen Gras
2149865aeaaSBen Gras# Any messages?
2159865aeaaSBen Grastest "$action" = start -a -f /etc/issue && cat /etc/issue
216e0e9e78dSBen Gras
2179865aeaaSBen Grasexit 0
218