From: Andy Spencer Date: Wed, 14 Oct 2009 14:12:42 +0000 (+0000) Subject: mkinit X-Git-Url: http://pileus.org/git/?p=mkinit;a=commitdiff_plain;h=3928288d9e80e2ff76e7e5d83678b92c4d275c3c mkinit - adding usage message - good parameter parsing - readline (for history, editing) - proper shutdown/halt/reboot init.mk - add rules for utmp, cpufreq --- diff --git a/init.mk b/init.mk index 710acdd..eeeda21 100644 --- a/init.mk +++ b/init.mk @@ -4,7 +4,7 @@ # Config PATH=/lib/mkinit/bin:/bin:/sbin:/usr/bin:/usr/sbin MKSHELL=/usr/lib/plan9/bin/rc -NPROC=8 +NPROC=10 # Example #start-test:VQPservice -u: start-foo @@ -16,21 +16,24 @@ NPROC=8 # service -D $target # Runlevels -default:V: bare +# Make getty wait (for bootchart) +default:V: user -desktop:V: console `{echo start-^(alsa polipo spam sshd)} -console:V: bare `{echo start-^(at cron syslog hddtemp i8k hwclock swap)} -bare:V: `{echo start-^(mounts uevents hostname fsclean getty qingy localhost keymap)} +user:V: system `{echo start-^(alsa keymap polipo spam)} +system:V: bare `{echo start-^(at cron hddtemp hostname hwclock i8k sshd swap syslog)} +bare:V: `{echo start-^(cpufreq fsclean getty localhost modules mounts uevents)} # Initial setup/shutdown for mkinit boot:QVEPservice -u: / echo Starting init $P mount -o remount,rw / + # mount proc here to make bootchart happier + $P mount -t proc proc /proc rm -f /lib/mkinit/state/* service -U $target # Kill all process, then remount and sync -halt:QVE: stop-hwclock stop-alsa +halt:QVE: stop-utmp stop-hwclock stop-alsa echo Stopping init rm -f /lib/mkinit/state/* @@ -50,7 +53,6 @@ halt:QVE: stop-hwclock stop-alsa # Proc, mtab, udev, fstab start-mounts:QVPservice -u: boot echo Starting mounts - $P mount -t proc proc /proc $P cat /proc/mounts > /etc/mtab $P udevd --daemon $P mount -a @@ -77,7 +79,7 @@ start-fsclean:QVPservice -u: boot service -U $target # Spawn gettys for tty[456] -start-getty:QVPservice -u: start-hostname +start-getty:QVPservice -u: start-hostname start-utmp echo Starting getty $P respawn /sbin/agetty 38400 tty4 linux & $P respawn /sbin/agetty 38400 tty5 linux & @@ -85,12 +87,29 @@ start-getty:QVPservice -u: start-hostname service -U $target # Spawn qingys for tty[23] -start-qingy:QVPservice -u: start-hostname start-modules start-uevents +start-qingy:QVPservice -u: start-hostname start-utmp start-modules start-uevents echo Starting qingy $P respawn /sbin/qingy tty2 & $P respawn /sbin/qingy tty3 & service -U $target +# Login records +start-utmp:QVPservice -u: start-fsclean + echo Starting utmp + for (i in /var/run/utmp /var/log/wtmp) { + echo -n > $i + chgrp utmp $i + chmod 0664 $i + } + service -U $target +utmp_stop_cmd=halt -w + +# CPU freq +start-cpufreq:QVPservice -u: start-uevents + echo Starting cpufreq + cpufreq-set -g ondemand + service -U $target + # Keymap (us-cc = us with ctrl-capslock switched) keymap_start_cmd=loadkeys -u us-cc diff --git a/src/mkinit b/src/mkinit index c2b4ec0..581e662 100755 --- a/src/mkinit +++ b/src/mkinit @@ -3,36 +3,65 @@ # Copyright (C) 2009 Andy Spencer # See ../COPYING for terms -echo -echo "mkinit -- starting" +function usage { +cat - < Execute mk rule + start|stop|restart|zap|status + Start,stop,restart,zap or query status of service + eval Execute command in mkinit process +EOF +exit +} function runamk { + [ "$TEST" ] && export P=true /usr/lib/plan9/bin/mk \ -f /etc/init.mk \ -i -k "$@" } # Handle arguments -TEST=false -cmd=boot -case "$1" in --t ) - TEST=true - export P="true" - ;; --n ) - cmd="" - ;; -esac - +TEMP=`getopt -n "$0" \ + --options th \ + --longoptions test,help \ + -- "$@"` +[ $? != 0 ] && usage +eval set -- "$TEMP" +while true; do + [ "$TEST" ] && echo "\$1=$1" + case "$1" in + -h|--help ) usage ;; + -t|--test ) TEST=true; shift ;; + -- ) shift; cmd="$1"; + shift; args="$@"; + break ;; + * ) ;; + esac +done +if [ "$TEST" ]; then + echo "Options" + echo " test=$TEST" + echo " cmd=$cmd" + echo " args=$args" +fi # Main loop -echo "mkinit -- entering main loop" while true; do case "$cmd" in boot ) + echo echo "mkinit -- booting" - if runamk -a && ! $TEST; then + if runamk -a "$args" && ! [ "$TEST" ]; then # booted successuflly, redirect input echo "skipping redirect" #pipe=/lib/mkinit/cmd @@ -40,10 +69,13 @@ while true; do #exec 0< $pipe fi ;; - halt ) - echo "mkinit -- halting" + halt|reboot|poweroff ) + echo "mkinit -- ${cmd}ing" runamk "halt" - # exit + if [ "$args" -o "$cmd" = reboot -o "$cmd" = poweroff ]; then + # mk handles syncing and logging message + ${TEST:+echo} $cmd -ndf $args + fi ;; restart ) if [ "$args" ]; then @@ -65,7 +97,7 @@ while true; do fi ;; reload ) - exec /sbin/mkinit -n + exec /sbin/mkinit ${TEST:+"-t"} ;; eval ) $args @@ -74,6 +106,6 @@ while true; do echo "unknown command [$cmd $args]" ;; esac - echo -n "mkinit> " - read cmd args + read -e -p "mkinit> " cmd args + history -s $cmd $args done