Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Killing the standalone perl server programatically

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


wash at paperpile

Jun 12, 2009, 6:19 AM

Post #1 of 8 (763 views)
Permalink
Killing the standalone perl server programatically

I'm developing a desktop application using Catalyst and the brand new
Titanium framework (http://www.appcelerator.com/).

I need to start/stop the standalone server programatically. Starting is
easy, but stopping the server (and its forks) again is tricky. I'd like
a solution without keeping track of the PID and explicitely kill it from
outside. I want to have something like

http://localhost:3000/kill

that calls something in the controller to shut down. The obvious thing

exit(0);

does not work. Any ideas how to do this?

Stefan

_______________________________________________
List: Catalyst[at]lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


kieren at diment

Jun 12, 2009, 6:36 AM

Post #2 of 8 (720 views)
Permalink
Re: Killing the standalone perl server programatically [In reply to]

sub quit : Local {
exit 1;
}

and <a href="[% c.uri_for('quit') %]" onClick="return confirm('This
will terminate your session. Are you sure?')">Quit</a>

both worked fine for me when I did this the other day.

But that was using a desktop OS (Windows and OS X fwiw), not a mobile
platform.



On 12/06/2009, at 11:19 PM, Stefan Washietl wrote:

> I'm developing a desktop application using Catalyst and the brand
> new Titanium framework (http://www.appcelerator.com/).
>
> I need to start/stop the standalone server programatically. Starting
> is easy, but stopping the server (and its forks) again is tricky.
> I'd like a solution without keeping track of the PID and explicitely
> kill it from outside. I want to have something like
>
> http://localhost:3000/kill
>
> that calls something in the controller to shut down. The obvious thing
>
> exit(0);
>
> does not work. Any ideas how to do this?
>
> Stefan
>
> _______________________________________________
> List: Catalyst[at]lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/



_______________________________________________
List: Catalyst[at]lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


hdp.perl.catalyst.users at weftsoar

Jun 12, 2009, 6:47 AM

Post #3 of 8 (722 views)
Permalink
Re: Killing the standalone perl server programatically [In reply to]

On Fri, Jun 12, 2009 at 02:19:19PM +0100, Stefan Washietl wrote:
> The obvious thing
>
> exit(0);
>
> does not work. Any ideas how to do this?

<purl> Look buddy, doesn't work is a strong statement. Does it sit on the
couch all day? Is it making faces at you? Does it want more money? Is
it sleeping with your girlfriend? Please be specific!

You will get much more useful help if you tell us exactly what code you wrote,
what you expected, and what happened instead, including error messages (if
any), instead of summing it all up as "exit(0) does not work".

You mentioned "the standalone server (and its forks)", but by default the
standalone server doesn't fork, so you should also be more specific about how
you're running it.

hdp.

_______________________________________________
List: Catalyst[at]lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


jshirley at gmail

Jun 12, 2009, 6:50 AM

Post #4 of 8 (720 views)
Permalink
Re: Killing the standalone perl server programatically [In reply to]

On Fri, Jun 12, 2009 at 6:19 AM, Stefan Washietl <wash[at]paperpile.org> wrote:

> I'm developing a desktop application using Catalyst and the brand new
> Titanium framework (http://www.appcelerator.com/).
>
> I need to start/stop the standalone server programatically. Starting is
> easy, but stopping the server (and its forks) again is tricky. I'd like a
> solution without keeping track of the PID and explicitely kill it from
> outside. I want to have something like
>
> http://localhost:3000/kill
>
> that calls something in the controller to shut down. The obvious thing
>
> exit(0);
>
> does not work. Any ideas how to do this?
>
> Stefan
>
>
I just set this up with a combination of HTTP::Prefork and
FCGI::Engine::Manager. I'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.

You'll have to grab Catalyst::Engine::HTTP::Prefork out of svn, or prod
andyg enough so he releases (HEY ANDY!)
http://dev.catalystframework.org/repos/Catalyst/trunk/Catalyst-Engine-HTTP-Prefork/


Here's all the yummy bits from my setup: http://gist.github.com/128642

You can just run script/myapp_admin.pl start|stop

One thing, I copied the script/myapp_server.pl over to
script/myapp_prefork.pl and changed the default CATALYST_ENGINE to
HTTP::Prefork.

This is because I couldn't figure out a clean way to set the ENV in
FCGI::Engine::Manager::Server classes, but it's a temporary hack until I
wrap that up.

Hope this helps,

-J


jshirley at gmail

Jun 12, 2009, 6:52 AM

Post #5 of 8 (723 views)
Permalink
Re: Killing the standalone perl server programatically [In reply to]

On Fri, Jun 12, 2009 at 6:50 AM, J. Shirley <jshirley[at]gmail.com> wrote:

> On Fri, Jun 12, 2009 at 6:19 AM, Stefan Washietl <wash[at]paperpile.org>wrote:
>
>> I'm developing a desktop application using Catalyst and the brand new
>> Titanium framework (http://www.appcelerator.com/).
>>
>> I need to start/stop the standalone server programatically. Starting is
>> easy, but stopping the server (and its forks) again is tricky. I'd like a
>> solution without keeping track of the PID and explicitely kill it from
>> outside. I want to have something like
>>
>> http://localhost:3000/kill
>>
>> that calls something in the controller to shut down. The obvious thing
>>
>> exit(0);
>>
>> does not work. Any ideas how to do this?
>>
>> Stefan
>>
>>
> I just set this up with a combination of HTTP::Prefork and
> FCGI::Engine::Manager. I'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.
>
> You'll have to grab Catalyst::Engine::HTTP::Prefork out of svn, or prod
> andyg enough so he releases (HEY ANDY!)
>
> http://dev.catalystframework.org/repos/Catalyst/trunk/Catalyst-Engine-HTTP-Prefork/
>
>
> Here's all the yummy bits from my setup: http://gist.github.com/128642
>
> You can just run script/myapp_admin.pl start|stop
>
> One thing, I copied the script/myapp_server.pl over to
> script/myapp_prefork.pl and changed the default CATALYST_ENGINE to
> HTTP::Prefork.
>
> This is because I couldn't figure out a clean way to set the ENV in
> FCGI::Engine::Manager::Server classes, but it's a temporary hack until I
> wrap that up.
>
> Hope this helps,
>
>
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.

It may be overkill, but that's how I'd do it (just so any post-shutdown
scripts are always executed, etc)

-J


wash at paperpile

Jun 12, 2009, 7:22 AM

Post #6 of 8 (719 views)
Permalink
Re: Killing the standalone perl server programatically [In reply to]

> On Fri, Jun 12, 2009 at 6:50 AM, J. Shirley <jshirley[at]gmail.com
> <mailto:jshirley[at]gmail.com>> wrote:
> ou'll have to grab Catalyst::Engine::HTTP::Prefork out of svn, or
> prod andyg enough so he releases (HEY ANDY!)
> http://dev.catalystframework.org/repos/Catalyst/trunk/Catalyst-Engine-HTTP-Prefork/

Thank you. I'll have a look at this solution. It is probably a good idea
to use Engine::HTTP::Prefork anyway instead of the simple
test/development-server.


J. Shirley wrote:
> On Fri, Jun 12, 2009 at 6:50 AM, J. Shirley <jshirley[at]gmail.com
> <mailto:jshirley[at]gmail.com>> wrote:
>
> On Fri, Jun 12, 2009 at 6:19 AM, Stefan Washietl <wash[at]paperpile.org
> <mailto:wash[at]paperpile.org>> wrote:
>
> I'm developing a desktop application using Catalyst and the
> brand new Titanium framework (http://www.appcelerator.com/).
>
> I need to start/stop the standalone server programatically.
> Starting is easy, but stopping the server (and its forks) again
> is tricky. I'd like a solution without keeping track of the PID
> and explicitely kill it from outside. I want to have something like
>
> http://localhost:3000/kill
>
> that calls something in the controller to shut down. The obvious
> thing
>
> exit(0);
>
> does not work. Any ideas how to do this?
>
> Stefan
>
>
> I just set this up with a combination of HTTP::Prefork and
> FCGI::Engine::Manager. I'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.
>
> You'll have to grab Catalyst::Engine::HTTP::Prefork out of svn, or
> prod andyg enough so he releases (HEY ANDY!)
> http://dev.catalystframework.org/repos/Catalyst/trunk/Catalyst-Engine-HTTP-Prefork/
>
>
> Here's all the yummy bits from my setup: http://gist.github.com/128642
>
> You can just run script/myapp_admin.pl start|stop
>
> One thing, I copied the script/myapp_server.pl over to
> script/myapp_prefork.pl and changed the default CATALYST_ENGINE to
> HTTP::Prefork.
>
> This is because I couldn't figure out a clean way to set the ENV in
> FCGI::Engine::Manager::Server classes, but it's a temporary hack
> until I wrap that up.
>
> Hope this helps,
>
>
> 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.
>
> It may be overkill, but that's how I'd do it (just so any post-shutdown
> scripts are always executed, etc)
>
> -J
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> List: Catalyst[at]lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/

_______________________________________________
List: Catalyst[at]lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


wash at paperpile

Jun 12, 2009, 7:31 AM

Post #7 of 8 (722 views)
Permalink
Re: Killing the standalone perl server programatically [In reply to]

Kieren Diment wrote:
> sub quit : Local {
> exit 1;
> }
>

This is exactly what I tried and would be the prefered solution.

Sorry if I only implicitely mentioned that I use the -fork option. In
that case it does not work, or more specifically, does not shut down the
server as I had expected.

In fact nothing happens, I don't get any feedback in the debug output
and and I get an empty response from the server.

_______________________________________________
List: Catalyst[at]lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


ton.voon at opsera

Jun 15, 2009, 2:12 PM

Post #8 of 8 (666 views)
Permalink
Re: Killing the standalone perl server programatically [In reply to]

On 12 Jun 2009, at 15:31, Stefan Washietl wrote:

> Kieren Diment wrote:
> > sub quit : Local {
> > exit 1;
> > }
> >
>
> This is exactly what I tried and would be the prefered solution.
>
> Sorry if I only implicitely mentioned that I use the -fork option.
> In that case it does not work, or more specifically, does not shut
> down the server as I had expected.
>
> In fact nothing happens, I don't get any feedback in the debug
> output and and I get an empty response from the server.

You've set the fork option. That means every request to the dev server
is forked. So the exit statement means the forked process is finished.
The main one, listening on port 3000, is still running.

It is possible to set a method to do a RESTART on the main process
(see the C::E::HTTP.pm code), so I guess a new method of EXIT might do
the trick here. You would want to limit which clients can send this
method though.

Ton


_______________________________________________
List: Catalyst[at]lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.