#!/bin/sh # Copyright (C) 2009 Andy Spencer # See ../COPYING for terms 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 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 while true; do case "$cmd" in boot ) echo echo "mkinit -- booting" if runamk -a "$args" && ! [ "$TEST" ]; then # booted successuflly, redirect input echo "skipping redirect" #pipe=/lib/mkinit/cmd #[ -p pipe ] || mkfifo $pipe #exec 0< $pipe fi ;; halt|reboot|poweroff ) echo "mkinit -- ${cmd}ing" runamk "halt" 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 echo "mkinit -- restarting $args" runamk "stop-$args" runamk "start-$args" fi ;; start|stop|zap|status ) if [ "$args" ]; then echo "mkinit -- ${cmd}ing $args" runamk "${cmd}-$args" fi ;; mk ) if [ "$args" ]; then echo "mkinit -- running mk cmd [$args]" runamk "$args" fi ;; reload ) exec /sbin/mkinit ${TEST:+"-t"} ;; eval ) $args ;; ?* ) echo "unknown command [$cmd $args]" ;; esac read -e -p "mkinit> " cmd args history -s $cmd $args done