1

I have a VM that needs to boot up, perform a specific task, and then shut itself down.

It also needs to be possible to abort the special startup sequence to get the "regular" bootup behaviour, i.e. either before the application run, or before the shutdown.

I've tried to accomplish this using the following in /etc/rc.local:

#!/bin/bash
trap "echo;echo Resuming regular system startup...;exit" SIGINT
echo "Press Ctrl+C within 10 seconds to skip application run..."
sleep 10
su ubuntu -c /home/ubuntu/application.py
echo "Press Ctrl+C within 30 seconds to abort shutdown..."
sleep 30
shutdown -h now

This runs fine and works as expected when I just execute it directly as /etc/rc.local as root, when logged in, but it would appear it doesn't work when it's actually run as a part of system startup. It runs fine, but it doesn't respond to Ctrl+C to actually be abortable.

SSH:ing in during the execution of this script and issuing a killall -INT rc.local also does not seem to stop the execution of the script, killall -9 rc.local does stop it though, and drops the console into login.

It appears this system uses upstart for booting, as determined below:

root@fundie:~# ps 1
  PID TTY      STAT   TIME COMMAND
    1 ?        Ss     0:01 /sbin/init
root@fundie:~# /sbin/init --version
init (upstart 1.12.1)
Copyright (C) 2006-2014 Canonical Ltd., 2011 Scott James Remnant

This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

What am I missing?

1

I managed to work around the issue by using Plymouth, which is the application which provides the graphical "splash" screen when booting and shutting down an Ubuntu system. I was able to use that to get SIGINT sent to the rc.local script in a roundabout way.

It's a bit of a hack, but here's what I ended up doing:

#!/bin/bash
plymouth watch-keystroke --command="kill -INT $$" --keys=' ' &
trap "echo;echo Resuming regular system startup...;exit" SIGINT
for i in `seq 10 -1 1`
do
        echo -ne "\rPress spacebar within $i second(s) to skip application run... "
        sleep 1
done
echo
su ubuntu -c /home/ubuntu/application.py
for i in `seq 30 -1 1`
do
        echo -ne "\rPress spacebar within $i second(s) to abort shutdown... "
        sleep 1
done
echo
shutdown -h now

This will serve sufficiently for my purposes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.