# 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
# 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/*
# 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
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 &
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
# Copyright (C) 2009 Andy Spencer
# See ../COPYING for terms
-echo
-echo "mkinit -- starting"
+function usage {
+cat - <<EOF
+usage: $0 [options] [command]
+
+Options:
+ -h,--help Print usage information
+ -t,--test Fake all commands
+
+Command:
+ boot Execute boot-up procedures
+ halt Execute shutdown procedures
+ reload Re-execute init process
+ mk <rule> Execute mk rule
+ start|stop|restart|zap|status <service>
+ Start,stop,restart,zap or query status of service
+ eval <cmd> 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
#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
fi
;;
reload )
- exec /sbin/mkinit -n
+ exec /sbin/mkinit ${TEST:+"-t"}
;;
eval )
$args
echo "unknown command [$cmd $args]"
;;
esac
- echo -n "mkinit> "
- read cmd args
+ read -e -p "mkinit> " cmd args
+ history -s $cmd $args
done