Issues with post-start stopping

Jens Rantil jens.rantil at tink.se
Mon Mar 24 16:23:08 UTC 2014


Hi James,

Thanks for your answer! Your answer definitely brought me a step towards my
goal. I reduced my example to this:

----------------------------------------------
# /etc/init/jens.conf

description "jens"
start on runlevel [2345]
stop on runlevel [!2345]

exec /bin/sleep 30

post-start script
   /bin/sleep 5
   stop
   exit 1
end script
----------------------------------------------

My script now ends with

$ start jens
jens stop/post-start, process 25605
post-start process 25606
$ status jens
jens stop/waiting

It it possible to make "start" tell me that an error occurred?

Thanks,
Jens


On Mon, Mar 24, 2014 at 3:35 PM, James Hunt <james.hunt at ubuntu.com> wrote:

> Hi Jens,
>
> 2014-03-20 17:41 GMT+00:00 Jens Rantil <jens.rantil at tink.se>:
>
>  Hi,
>>
>> I have an HTTP server daemon process that I start using upstart. When I
>> start it I'd like it to wait for at most 60 seconds for an HTTP check to
>> return 200. If it doesn't return within 60 I'd like to fail "start myapp",
>> otherwise I'd like to return "start myapp" as soon as I get a correct HTTP
>> response.
>>
>> I've been trying to use
>>
>> post-start script
>>   /bin/my-healthcheck --max-wait 60
>>   if [ $? -ne 0 ]; then
>>     stop
>>     exit 1
>>   fi
>> end script
>>
>> But "stop; exit 1" doesn't seem to stop my service.
>>
> Your script is subtly incorrect; Upstart uses '/bin/sh -e' to run all
> script sections so if my-healthcheck fails, that post-start script shell
> will *immediately* exit 1, and stop will never be called.
>
> See:
>
> - Behaviour of 'set -e' in sh(1).
> - http://upstart.ubuntu.com/cookbook/#develop-scripts-using-bin-sh
>
> To handle this, you could do something like:
>
> post-start script
>   /bin/my-healthcheck --max-wait 60 || { stop; exit 1; }
> end script
>
>
>>
>> Can this be done using upstart? Or will I need to `exec myservice_safe`
>> that initiates a check and my main script? Or use events?
>>
>> Thanks,
>> Jens
>>
>> PS. I've cross posted my question here:
>> https://serverfault.com/questions/583426/why-is-this-upstart-script-not-stopping-my-process
>>
>> --
>> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20140324/efbc4f9b/attachment.html>


More information about the upstart-devel mailing list