#!/sbin/runscript # Jacob Joseph (4/26/04) # User mode linux init script # will source /etc/conf.d/$0 # portions taken from James Neal's umlazi depend() { need net.bridge0 } parse_machine() { if [ "${myservice%%.*}" = "uml" -a "${myservice##*.}" != "${myservice}" ] then MACHINE="${myservice##*.}" else MACHINE= fi } die() { eerror $1 eend 1 exit 1 } check_config() { [ -n "$UMLDIR" ] || die "UMLDIR is null" if [ -z "$MEMORY" ]; then ewarn "MEMORY is null. 32MB will be used"; \ MEMORY="32MB" fi [ -n "$USER" ] || die "USER is null" [ -n "$NET" ] || die "NETWORK is null" [ -d "$UMLDIR/$MACHINE" ] || die "'$UMLDIR/$MACHINE does not exist or is not a directory" [ -f "$UMLDIR/$MACHINE/root.loop" ] || die "'$UMLDIR/$MACHINE/root.loop' not found" [ -f "$UMLDIR/$MACHINE/swap.loop" ] || die "'$UMLDIR/$MACHINE/swap.loop' not found" [ -f "$UMLDIR/$MACHINE/linux" ] || die "'$UMLDIR/$MACHINE/linux' not found" } # sends cad to UML. Should have shutdown -h in /etc/inittab send_cad() { #/usr/bin/uml_mconsole $CONSOLE cad >/dev/null 2>&1 /usr/bin/uml_mconsole "$CONSOLE" cad >/dev/null 2>&1 maxtime=60 while [ $(is_running) != 0 ] && [ $maxtime -gt 0 ]; do sleep 1 maxtime=$(( $maxtime - 1 )) done } send_halt() { # sync filesystems /usr/bin/uml_mconsole $CONSOLE sysrq s > /dev/null 2>&1 sleep 5 # remount read-only /usr/bin/uml_mconsole $CONSOLE sysrq u > /dev/null 2>&1 sleep 5 # sync again /usr/bin/uml_mconsole $CONSOLE sysrq s > /dev/null 2>&1 sleep 5 # halt immediately /usr/bin/uml_mconsole $CONSOLE halt >/dev/null 2>&1 sleep 5 } get_pid() { if [ -e "$PIDFILE" ]; then cat $PIDFILE else echo 0 fi } is_running() { local PID=$(get_pid) if /bin/ps -fp $PID > /dev/null 2>&1; then echo 1 else echo 0 fi } setup_env() { parse_machine check_config USERDIR=$(eval echo "~$USER") CONSOLE="$USERDIR/.uml/$MACHINE/mconsole" PIDFILE="$USERDIR/.uml/$MACHINE/pid" } start() { setup_env einfo "MEMORY: $MEMORY" ebegin "Starting UML: $MACHINE" [ $(is_running) != 0 ] && die "UML: $MACHINE already running" pushd $UMLDIR/$MACHINE >/dev/null 2>&1 [ $? != 0 ] && die "pushd to $UMLDIR/$MACHINE failed" start-stop-daemon --start --pidfile $PIDFILE \ --chuid "$USER" --startas \ /usr/bin/screen -- -S $MACHINE -L -d -m \ ./linux \ ubd0=root.loop \ ubd1=swap.loop \ umid=$MACHINE \ mem=$MEMORY \ eth0=tuntap,$NET \ con=null con0=fd:0,fd:1 eend $? popd > /dev/null 2>&1 } status() { setup_env [ $(is_running) != 0 ] && \ einfo "UML: $MACHINE running as $(cat $PIDFILE)" } stop() { setup_env ebegin "Stopping UML: $MACHINE" einfo "Sending cad to shutdown...wait 60s" send_cad if [ $(is_running) != 0 ]; then eend 1 ewarn "Forcing halt...wait 20s" send_halt else eend 0 fi if [ $(is_running) != 0 ]; then eend 1 eerror "Still running. I don't know what to do. Aborting." else eend 0 fi }