simple upstart example
kauer at biplane.com.au
Sat Dec 21 22:26:57 UTC 2013
On Sat, 2013-12-21 at 18:49 +0000, thufir wrote:
> I'm trying to understand upstart:
> For their example above, for job "odd", where do they define what "odd"
> is? Can it be a bash script? I have this script:
"odd" is the upstart job name, so there will be an odd.conf. There is no
necessary relationship between the upstart job name and the name of
whatever program or programs the upstart job runs.
What odd actually does can be anything at all, including a script. Go up
a page or so to section 18.104.22.168 to see an inline script, or see 22.214.171.124
for an example of starting an external program (which can be a script)
> but can't use cron to start that job because if the frequency is too short
> it starts a multitude of processes (a fork bomb?), yet if the frequency is
> too long then it defeats the purpose.
Not sure what you are trying to do here. Do you want to limit the number
of processes started, or the time between each new process starting?
Both these can be done in the script itself. upstart has features to
prevent a spawnstorm. Look at section 6.28, "respawn limit". upstart is
the easiest way to make sure something is always running without
starting a zillion copies.
In the script itself, you can use a lockfile to make sure that extra
copies of your script either wait (not recommended) or exit immediately
if one is already running. Just look for the presence of a certain file
when you start your script and exit silently if it exists. Otherwise
create the file, do your thing, then delete it just before exiting.
There are lots of examples out there; search for e.g. "bash lockfile".
Don't just use "-e" - the check/create has to be atomic.
It's a bit trickier to limit the number of concurrent processes, but it's still basically the same idea.
Karl Auer (kauer at biplane.com.au)
GPG fingerprint: B862 FB15 FE96 4961 BC62 1A40 6239 1208 9865 5F9A
Old fingerprint: AE1D 4868 6420 AD9A A698 5251 1699 7B78 4EEE 6017
More information about the ubuntu-users