I have a service named manager, which sometimes updates itself (from some network location). If something wrong happens during this update, like a system shutdown, I want to replace the bad executable with a known-working one. This resulted in me having two Upstart jobs.

The main job file:

exec /usr/local/bin/manager
start on startup

The watchdog job file:

start on stopping manager PROCESS="respawn"
    cp /usr/local/var/"$WATCHED".bk $EXE
    chmod +x $EXE
    start $WATCHED
end script

2 questions:

  • Is this a fine approach... can it be improved?

  • Is there a way to do all this in just one job file?

  • First thing that pops out is this: You're replacing the binary whenever the manager job goes down, instead of after n failures (like the title implies). If you're doing that, why not use a post-stop/pre-start combo? – muru Nov 13 '14 at 8:02
  • No, it only gets replaced after n failures. Thats what PROCESS="respawn" does. – tshepang Nov 13 '14 at 8:03
  • Ah, didn't know about PROCESS="respawn". Still, why not use pre-start instead? Something like: pre-start script if [ "$PROCESS" = "respawn" ]; then blah; fi end script? -- Scratch that. Looking at the cookbook, I think your current way is right. – muru Nov 13 '14 at 8:23
  • Am curious: if I were to use pre-start, would that live in the watchdog job file? – tshepang Nov 13 '14 at 8:38

Your Answer

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

Browse other questions tagged or ask your own question.