On Fri, Jun 12, 2009 at 6:50 AM, J. Shirley <span dir="ltr">&lt;<a href="mailto:jshirley@gmail.com">jshirley@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="gmail_quote"><div class="im">On Fri, Jun 12, 2009 at 6:19 AM, Stefan Washietl <span dir="ltr">&lt;<a href="mailto:wash@paperpile.org" target="_blank">wash@paperpile.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

I&#39;m developing a desktop application using Catalyst and the brand new Titanium framework (<a href="http://www.appcelerator.com/" target="_blank">http://www.appcelerator.com/</a>).<br>
<br>
I need to start/stop the standalone server programatically. Starting is easy, but stopping the server (and its forks) again is tricky. I&#39;d like a solution without keeping track of the PID and explicitely kill it from outside. I want to have something like<br>


<br>
<a href="http://localhost:3000/kill" target="_blank">http://localhost:3000/kill</a><br>
<br>
that calls something in the controller to shut down. The obvious thing<br>
<br>
exit(0);<br>
<br>
does not work. Any ideas how to do this?<br>
<br>
Stefan<br>
<br>
</blockquote></div><div><br>I just set this up with a combination of HTTP::Prefork and FCGI::Engine::Manager.  I&#39;m still floundering away a bit at a refactor of FCGI::Engine::Manager that is semantically more sound, but it works well enough right now.<br>

<br>You&#39;ll have to grab Catalyst::Engine::HTTP::Prefork out of svn, or prod andyg enough so he releases (HEY ANDY!)<br><a href="http://dev.catalystframework.org/repos/Catalyst/trunk/Catalyst-Engine-HTTP-Prefork/" target="_blank">http://dev.catalystframework.org/repos/Catalyst/trunk/Catalyst-Engine-HTTP-Prefork/</a><br>

<br><br>Here&#39;s all the yummy bits from my setup: <a href="http://gist.github.com/128642" target="_blank">http://gist.github.com/128642</a><br><br>You can just run script/myapp_admin.pl start|stop<br><br>One thing, I copied the script/myapp_server.pl over to script/myapp_prefork.pl and changed the default CATALYST_ENGINE to HTTP::Prefork.<br>

<br>This is because I couldn&#39;t figure out a clean way to set the ENV in FCGI::Engine::Manager::Server classes, but it&#39;s a temporary hack until I wrap that up.<br><br>Hope this helps,<br><br></div></div>
</blockquote></div><br>I forgot to finish this off, you can have the kill action then run the stop command and then everything is going from the same point.  Just executing a system call to kill it means that the current request should finish cleanly, along with everything else.<br>
<br>It may be overkill, but that&#39;s how I&#39;d do it (just so any post-shutdown scripts are always executed, etc)<br><br>-J<br>