how to detect stopping reason in post-stop?

Asked by Alex Nekrasov on 2009-02-12

I have something like this:

start on started <dependency>
stop on stopping <dependency>

script
    <do lots of things here, including starting the actual service via a number of layers>
end script

pre-stop script
    <do stuff to kill the service>
end script

post-stop script
    if [ <normal stop> ]
    then
        # this shall be normal stopping on stopped dependency - do nothing
    else
        # this shall be a failed service - reboot the system!
    fi
end script

Is there anything in Upstart that'd help me to detect in post-stop if it was Upstart that stopped me (via explicit stop command or by "stop on stopping" event) or if it was my service panicing and exiting the main script that caused post-stop to run?

I know in pre-start that it's the normal stopping. How can I transfer this knowledge to post-start by means of Upstart?

Question information

Language:
English Edit question
Status:
Solved
For:
upstart Edit question
Assignee:
No assignee Edit question
Solved by:
Scott James Remnant (Canonical)
Solved:
2009-02-13
Last query:
2009-02-13
Last reply:
2009-02-12

This is not supported.

You should respond to the failed server in another job:

  start on stopped <your job> failed
  script
    # reboot the system!
  end script

Alex Nekrasov (ennnot) said : #2

This works for my problem nicely, thanks.

I would imagine situations when I'd need to know in the component's script. I can use external facilities, such as files, but this is sometimes ugly.

Will van der Leij (willvdl) said : #3

What would the "failure" conditions be exactly? i.e. what constitutes a failed event?

- TERM or SIGKILLs?
- exec-uted processes with non-zero return codes?

Also, would a respawning event generate a "fail" event as such?

On Thu, 2009-02-26 at 15:04 +0000, Will van der Leij wrote:

> What would the "failure" conditions be exactly? i.e. what constitutes a
> failed event?
>
> - TERM or SIGKILLs?
> - exec-uted processes with non-zero return codes?
>
Yes.

> Also, would a respawning event generate a "fail" event as such?
>
Yes.

Scott
--
Scott James Remnant
<email address hidden>