1 #!/usr/bin/setsid /bin/bash
3 # Copyright (C) 2009 Andy Spencer
4 # See ../COPYING for terms
16 export PLAN9=/opt/plan9
17 export PATH=/lib/mkinit/bin:/bin:/sbin:/usr/bin:/usr/sbin
21 echo 'usage: '$0' [options] [command]'
24 echo ' -h,--help Print usage information'
25 echo ' -t,--test Fake all commands'
26 echo ' -d,--daemon For spawning stdin listener'
27 echo ' -r,--reload Reload mkinit'
30 echo ' boot Execute boot-up procedures'
31 echo ' halt Execute shutdown procedures'
32 echo ' reload Re-execute init process'
33 echo ' mk <rule> Execute mk rule'
34 echo ' start|stop|restart|zap|status <service>'
35 echo ' Start,stop,restart,zap or query status of service'
36 echo ' eval <cmd> Execute command in mkinit process'
42 TMP=`getopt -n "$0" -o htdr -l help,test,daemon,reload -- "$@"`
48 while [ ! "$1" == "--" ]; do
51 -t|--test ) TESTING=true ;;
52 -d|--daemon ) DAEMON=true ;;
53 -r|--reload ) RELOAD=true ;;
65 echo ' TESTING:' $TESTING 1>&2
66 echo ' DAEMON:' $DAEMON 1>&2
67 echo ' COMMAND:' $COMMAND 1>&2
68 echo ' RELOAD:' $RELAOD 1>&2
72 # Run mk on the init scripts
76 export MKINIT_STATE=/tmp/mkinit_state
77 mkdir -p $MKINIT_STATE
88 echo mkinit -- running "$cmd" "$@"
101 start|stop|zap|status )
111 poweroff|reboot|kexec|halt)
112 ( runamk "$cmd" "$@" & )
126 # Run whatever was requested
128 process "${COMMAND[@]}"
131 # Fork console listener
133 $TESTING || exec 0</dev/tty1 1>/dev/tty1 2>&1
134 while read -ep "mkinit> " line; do
139 echo "Respawning on /dev/tty1"