Determine when restart fails

Michael Barrett loki77 at gmail.com
Wed Mar 5 21:46:56 UTC 2014


Okay, I realize now that my previous question wasn't totally clear about
what I was doing.  My guess is that the situations before that you sent are
only variables sent to the job itself?

What I'm trying to do is write an upstart job that notices when other
upstart jobs start, and then sends an event to my eventing system letting
me know it happened.  The thing is that I don't want to get an event when:

- The daemon was stopped on purpose
- The daemon stopped because the system is shutting down

Right now my upstart job looks like this:

start on stopping JOB!=daemon_stopped
task
script
    echo "[`date`] Received stopping event for JOB: ${JOB}, INSTANCE:
${INSTANCE}"
    exec /usr/bin/emit_event DaemonStoppedEvent daemon_name=$JOB
end script

Currently to handle the system shutdown case I tried to call the runlevel
command, but it seemed to have issues finding utmp at some point in the
shutdown.  Instead my latest idea is to have another upstart job that
starts on 'runlevel [0123456]' and touches a file whenever the current run
level is 0 or 6 (basically when it's shutting down).  Then in the daemon
stop monitor I'd have it check for the existence of that file before
sending off an event.

As far as the purposefully stopping daemon, I'm really not sure how I can
make that happen.

Anyway, if anyone has any suggestions that'd be awesome.  Thanks!


On Wed, Mar 5, 2014 at 12:53 PM, Michael Barrett <loki77 at gmail.com> wrote:

> Awesome, thanks a ton!
>
>
> On Wed, Mar 5, 2014 at 6:53 AM, James Hunt <james.hunt at ubuntu.com> wrote:
>
>> ... forgot to say that I have updated the Cookbook on this topic:
>>
>> - http://upstart.ubuntu.com/cookbook/#respawn
>> - http://upstart.ubuntu.com/cookbook/#respawn-limit
>>
>>
>> 2014-03-05 14:51 GMT+00:00 James Hunt <james.hunt at ubuntu.com>:
>>
>> Hi Michael,
>>>
>>> 2014-03-04 19:26 GMT+00:00 Michael Barrett <loki77 at gmail.com>:
>>>
>>> Is there anyway to tell the difference between these different 'stopped'
>>>> situations:
>>>> - The daemon was stopped by a user command (service <daemon> stop)
>>>>
>>> $UPSTART_EVENTS will not be set in this scenario (since no event caused
>>> the job to stop - an admin intervened).
>>>
>>> - The daemon died, but is has not reached the respawn limit and is
>>>> restarting.
>>>>
>>>   In this scenario, $PROCESS will be set to the name of the job process
>>> that failed (for example 'pre-start', 'main').
>>>
>>>  - The daemon died and is not going to attempt to respawn due to
>>>> whatever reason (no respawn, or reaching the respawn limit)
>>>>
>>>  In this scenario, if the respawn stanzas was specified, $PROCESS will
>>> be set to 'respawn' to denote that the respawn limit was reached.
>>>
>>> If the respawn stanza was not specified, $PROCESS will not be set.
>>> However, in both scenarios upstart will set $EXIT_STATUS or $EXIT_SIGNAL
>>> (whichever is appropriate).
>>>
>>> See stopped(7) and init(5) for further details.
>>>
>>>
>>>> Thanks!
>>>>
>>>> --
>>>> Michael Barrett
>>>>
>>>> --
>>>> upstart-devel mailing list
>>>> upstart-devel at lists.ubuntu.com
>>>> Modify settings or unsubscribe at:
>>>> https://lists.ubuntu.com/mailman/listinfo/upstart-devel
>>>>
>>>>
>>>
>>>
>>> --
>>> Kind regards,
>>>
>>> James.
>>> --
>>> James Hunt
>>> ____________________________________
>>> #upstart on freenode
>>> http://upstart.ubuntu.com/cookbook
>>> https://lists.ubuntu.com/mailman/listinfo/upstart-devel
>>>
>>
>>
>>
>> --
>> Kind regards,
>>
>> James.
>> --
>> James Hunt
>> ____________________________________
>> #upstart on freenode
>> http://upstart.ubuntu.com/cookbook
>> https://lists.ubuntu.com/mailman/listinfo/upstart-devel
>>
>
>
>
> --
> Michael Barrett
>



-- 
Michael Barrett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140305/52583360/attachment-0001.html>


More information about the upstart-devel mailing list