<div dir="ltr">Hi James,<div><br></div><div>Thanks for your answer! Your answer definitely brought me a step towards my goal. I reduced my example to this:</div><div><br></div><div>----------------------------------------------</div>

<div># /etc/init/jens.conf</div><div><br></div><div><div>description "jens"</div><div>start on runlevel [2345]</div><div>stop on runlevel [!2345]</div><div><br></div><div>exec /bin/sleep 30</div><div><br></div>
<div>
post-start script</div><div>   /bin/sleep 5</div><div>   stop</div><div>   exit 1</div><div>end script</div></div><div>----------------------------------------------<br></div><div><br></div><div>My script now ends with</div>

<div><br></div><div>$ start jens</div><div><div>jens stop/post-start, process 25605</div><div><span class="" style="white-space:pre">   </span>post-start process 25606</div></div><div>$ status jens</div><div>jens stop/waiting<br>

</div><div><br></div><div>It it possible to make "start" tell me that an error occurred?</div><div><br></div><div>Thanks,<br>Jens</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 24, 2014 at 3:35 PM, James Hunt <span dir="ltr"><<a href="mailto:james.hunt@ubuntu.com" target="_blank">james.hunt@ubuntu.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">Hi Jens,</div><div class="gmail_extra"><br><div class="gmail_quote">2014-03-20 17:41 GMT+00:00 Jens Rantil <span dir="ltr"><<a href="mailto:jens.rantil@tink.se" target="_blank">jens.rantil@tink.se</a>></span>:<div class="">

<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">Hi,</span><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">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.</div>





<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">I've been trying to use</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div>





<div style="font-family:arial,sans-serif;font-size:13px">post-start script</div><div style="font-family:arial,sans-serif;font-size:13px">  /bin/my-healthcheck --max-wait 60</div><div style="font-family:arial,sans-serif;font-size:13px">





  if [ $? -ne 0 ]; then</div><div style="font-family:arial,sans-serif;font-size:13px">    stop</div><div style="font-family:arial,sans-serif;font-size:13px">    exit 1</div><div style="font-family:arial,sans-serif;font-size:13px">





  fi</div><div style="font-family:arial,sans-serif;font-size:13px">end script</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">But "stop; exit 1" doesn't seem to stop my service.</div>



</div></blockquote></div><div>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.</div>



<div><br></div><div>See:</div><div><br></div><div>- Behaviour of 'set -e' in sh(1).</div><div>- <a href="http://upstart.ubuntu.com/cookbook/#develop-scripts-using-bin-sh" target="_blank">http://upstart.ubuntu.com/cookbook/#develop-scripts-using-bin-sh</a><br>



</div><div><br></div><div>To handle this, you could do something like:</div><div><br></div><div><div>post-start script</div><div>  /bin/my-healthcheck --max-wait 60 || { stop; exit 1; }</div><div>end script<br></div></div>



<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div dir="ltr">

<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">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?</div>





<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Thanks,</div><div style="font-family:arial,sans-serif;font-size:13px">Jens</div><div style="font-family:arial,sans-serif;font-size:13px">





<br></div><div style="font-family:arial,sans-serif;font-size:13px">PS. I've cross posted my question here: <a href="https://serverfault.com/questions/583426/why-is-this-upstart-script-not-stopping-my-process" target="_blank">https://serverfault.com/questions/583426/why-is-this-upstart-script-not-stopping-my-process</a></div>





</div>
<br></div>--<br>
upstart-devel mailing list<br>
<a href="mailto:upstart-devel@lists.ubuntu.com" target="_blank">upstart-devel@lists.ubuntu.com</a><br>
Modify settings or unsubscribe at: <a href="https://lists.ubuntu.com/mailman/listinfo/upstart-devel" target="_blank">https://lists.ubuntu.com/mailman/listinfo/upstart-devel</a></blockquote><div><br></div><div><br></div><div>


Kind regards,</div><div><br></div><div>James.</div><div>--</div><div>James Hunt</div><div>____________________________________</div><div>#upstart on freenode</div><div><a href="http://upstart.ubuntu.com/cookbook" target="_blank">http://upstart.ubuntu.com/cookbook</a></div>


<div><a href="https://lists.ubuntu.com/mailman/listinfo/upstart-devel" target="_blank">https://lists.ubuntu.com/mailman/listinfo/upstart-devel</a></div></div>

</div></div>
</blockquote></div><br></div>