I'm new to upstart, and I would like to know if there's a way to tell upstart to execute a specific command only at system startup, and not when the application is subsequently restarted from the command line. For example, I have the following upstart configuration:
#!upstart
description "Hello World"
author "me"
start on (local-filesystems and net-device-up)
stop on shutdown
script
export HOME="/root"
echo $$ > /var/run/hello-world.pid
exec /usr/local/bin/hello-world
end script
pre-start script
# Date format same as (new Date()).toISOString() for consistency
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] Hello World Starting" >> /var/log/hello-world.sys.log
end script
pre-stop script
rm /var/run/hello-world.pid
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] Hello World Stopping" >> /var/log/hello-world.sys.log
end script
That successfully starts the application on startup. If I execute:
/sbin/start hello-world
This starts the application again: I would like to execute a specific command only when the system is started up, and not when the application is started up, like:
First execution:
- The system starts up
- Upstart is executed
- A specific system startup script is executed
- The application, hello-world, is executed
Second execution using /sbin/start hello-world
:
- Only execute application without executing the specific startup script
Is there a way for doing this?
I've got one solution, but it's butt ugly.
So..
/proc/uptime
contains the number of seconds since startup.The first number is number of seconds on, the second number is number of idle seconds..
SO..
Would run the pre-run script if the system has just booted (or hasn't been working for 300s). You could tune the 300s down to the actual time your system takes to get ready.
It's dirty as hell, but worth a try, right?
Use a 'cookie-file' below
/var/run
*. Execute the specific startup script only if the cookie-file does not exist and create it after successful execution.*) Filesystem Hierarchy Standard 2.3