FAQ
Attached is a patch to Catalyst::Engine::HTTP (from the 5.49_02 release) to make the self-restarting test server work on Win32.

I've not found a way to get the test server to restart in the existing command window (if anyone knows, I'd like to find out). Instead the patch uses start.exe to restart the server in a new window, then uses Win32::Process::Info to find the pid for the current cmd.exe and to close the existing window. It's fiddly but functional.

This should work on any Windows machine with WMI installed - that is to say 2000/XP/2003 out of the box and older Windows OSes where WMI has been installed retrospectively.

Testing and feedback from any other folks running on Win32 would be appreciated (please reply to the list). So far I have verified that it works correctly on Win2003 (no SP) and WinXP SP2.

Regards

wh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HTTP.pm.patch
Type: application/octet-stream
Size: 1794 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20051031/bf602bd9/HTTP.pm.obj

Search Discussions

  • Andy Grundman at Oct 31, 2005 at 3:18 pm

    Will Hawes wrote:
    Attached is a patch to Catalyst::Engine::HTTP (from the 5.49_02 release) to make the self-restarting test server work on Win32.
    Thanks, this looks like a nice and simple solution. I'll give it a test
    and apply if all goes well. :)

    One question I have, will cmd.exe always be the parent process? What
    will happen if someone starts the server from, say, a batch file in
    Explorer? Probably unlikely that someone will go to the trouble, but we
    wouldn't want to kill something other than cmd.exe.

    -Andy
  • Will Hawes at Oct 31, 2005 at 4:30 pm
    ----- Original Message -----
    From: Andy Grundman <andy@hybridized.org>
    To: The elegant MVC web framework <catalyst@lists.rawmode.org>
    Sent: Mon, 31 Oct 2005 14:23:24 +0000
    Subject: Re: [Catalyst] Self restarting test server for Win32!

    Will Hawes wrote:
    Attached is a patch to Catalyst::Engine::HTTP (from the 5.49_02 release) to
    make the self-restarting test server work on Win32.

    Thanks, this looks like a nice and simple solution. I'll give it a test
    and apply if all goes well. :)

    One question I have, will cmd.exe always be the parent process? What
    will happen if someone starts the server from, say, a batch file in
    Explorer? Probably unlikely that someone will go to the trouble, but we
    wouldn't want to kill something other than cmd.exe.
    That's an interesting point and not something I'd considered. I'm pretty sure that a batch file would be executed by cmd.exe and that the batch file itself wouldn't be considered a process by the OS, but I'll have to check.

    On another note, I've been testing this patch a bit more today and I'm getting some unexpected results. The server restarts and is functional the first time I modify a file. On the second modification, the server restarts but seems not to bind correctly to port 3000. Port 3000 is totally non responsive unless I close the command window and open a new one.

    It's as though sockets are not released properly by Perl when you kill perl.exe or a parent process. I don't know why the restart should work once and then fail and I haven't worked out what to do about it yet.
  • Sascha Kiefer at Nov 1, 2005 at 8:21 pm
    Hi,

    Tested a little bit, and it actually looks good on my machine (WinXP Home,
    AS Perl v5.8.7),
    but maybe it helps to check the returnvalues of bind and listen. It may that
    the new server is
    started before the old server process is terminated. That may result in
    difficulties (...but should
    actually result in zero-returnvalue of accept...)

    Regards,
    --esskar
    -----Original Message-----
    From: catalyst-bounces@lists.rawmode.org
    On Behalf Of Will Hawes
    Sent: Montag, 31. Oktober 2005 16:37
    To: The elegant MVC web framework
    Subject: Re: [Catalyst] Self restarting test server for Win32!
    On another note, I've been testing this patch a bit more
    today and I'm getting some unexpected results. The server
    restarts and is functional the first time I modify a file. On
    the second modification, the server restarts but seems not to
    bind correctly to port 3000. Port 3000 is totally non
    responsive unless I close the command window and open a new one.

    It's as though sockets are not released properly by Perl when
    you kill perl.exe or a parent process. I don't know why the
    restart should work once and then fail and I haven't worked
    out what to do about it yet.
  • Will Hawes at Nov 1, 2005 at 8:41 pm
    ----- Original Message -----
    From: "Kiefer, Sascha" <sk@intertivity.com>
    To: 'The elegant MVC web framework' <catalyst@lists.rawmode.org>
    Sent: Tue, 1 Nov 2005 19:27:13 +0000
    Subject: RE: [Catalyst] Self restarting test server for Win32!
    but maybe it helps to check the returnvalues of bind and listen. It may that
    the new server is
    started before the old server process is terminated.
    I thought that was the cause too - and probably is with the patch I posted. However, in my testing I am now killing the parent process before my call to system() with the same result. I'm pretty certain it's a case of the socket not being released properly when the first server shuts down. This could have something to do with filehandles/sockets being shared when you fork() - I think the use of kill() might mean that there are references to them still hanging around.

    Incidentally (and OT), I think the code in the test server could be simplified somewhat using IO::Socket.

    wh
  • Sascha Kiefer at Nov 1, 2005 at 8:44 pm
    Update: Now, it happens to me also. I checked the return values of bind and
    listen, but they seem to be okay.
    The funny thing is, calling CTRL^C in the new CMD and restarting the server
    by hand does not help either.
    I have to close the CMD, open a new one and then start the server again.

    When I check TCPView to see the connected TCP ports, I see that i have now 2
    perl processes that both listen on port 3000.
    So, we killed the cmd but not the perl.exe. But the process that is also
    listen on port 3000 does no longer exist (checked
    TaskMgr and list for that) and can not be killed by TCPView. It is
    terminated though after i closed the CMD. So it might be
    a problem with fork? under windows?

    Regards,
    --esskar
    Hi,

    Tested a little bit, and it actually looks good on my machine
    (WinXP Home, AS Perl v5.8.7), but maybe it helps to check the
    returnvalues of bind and listen. It may that the new server
    is started before the old server process is terminated. That
    may result in difficulties (...but should
    actually result in zero-returnvalue of accept...)

    Regards,
    --esskar
    -----Original Message-----
    From: catalyst-bounces@lists.rawmode.org
    On Behalf Of Will Hawes
    Sent: Montag, 31. Oktober 2005 16:37
    To: The elegant MVC web framework
    Subject: Re: [Catalyst] Self restarting test server for Win32!
    On another note, I've been testing this patch a bit more today and
    I'm getting some unexpected results. The server restarts and is
    functional the first time I modify a file. On the second
    modification, the server restarts but seems not to bind correctly to
    port 3000. Port 3000 is totally non responsive unless I close the
    command window and open a new one.

    It's as though sockets are not released properly by Perl when you
    kill perl.exe or a parent process. I don't know why the restart
    should work once and then fail and I haven't worked out what to do
    about it yet.

    _______________________________________________
    Catalyst mailing list
    Catalyst@lists.rawmode.org
    http://lists.rawmode.org/mailman/listinfo/catalyst
  • Sascha Kiefer at Nov 2, 2005 at 11:34 am
    It's really not a easy one.
    I suggest to seperate to rewrite the HTTPServer by seperating the work in to
    scripts.
    One that runs the server, the other one that checks:
    1. the server is still runing; if not, restart it
    2. checks whether or not the files have changed

    Regards,
    --esskar
    Update: Now, it happens to me also. I checked the return
    values of bind and listen, but they seem to be okay.
    The funny thing is, calling CTRL^C in the new CMD and
    restarting the server by hand does not help either.
    I have to close the CMD, open a new one and then start the
    server again.

    When I check TCPView to see the connected TCP ports, I see
    that i have now 2 perl processes that both listen on port 3000.
    So, we killed the cmd but not the perl.exe. But the process
    that is also listen on port 3000 does no longer exist (checked
    TaskMgr and list for that) and can not be killed by TCPView.
    It is terminated though after i closed the CMD. So it might
    be a problem with fork? under windows?

    Regards,
    --esskar
    Hi,

    Tested a little bit, and it actually looks good on my
    machine (WinXP
    Home, AS Perl v5.8.7), but maybe it helps to check the
    returnvalues of
    bind and listen. It may that the new server is started
    before the old
    server process is terminated. That may result in
    difficulties (...but
    should actually result in zero-returnvalue of accept...)

    Regards,
    --esskar
    -----Original Message-----
    From: catalyst-bounces@lists.rawmode.org
    On Behalf Of
    Will Hawes
    Sent: Montag, 31. Oktober 2005 16:37
    To: The elegant MVC web framework
    Subject: Re: [Catalyst] Self restarting test server for Win32!
    On another note, I've been testing this patch a bit more today and
    I'm getting some unexpected results. The server restarts and is
    functional the first time I modify a file. On the second
    modification, the server restarts but seems not to bind
    correctly to
    port 3000. Port 3000 is totally non responsive unless I close the
    command window and open a new one.

    It's as though sockets are not released properly by Perl when you
    kill perl.exe or a parent process. I don't know why the restart
    should work once and then fail and I haven't worked out
    what to do
    about it yet.

    _______________________________________________
    Catalyst mailing list
    Catalyst@lists.rawmode.org
    http://lists.rawmode.org/mailman/listinfo/catalyst
  • Will Hawes at Nov 2, 2005 at 11:56 am
    ----- Original Message -----
    From: "Kiefer, Sascha" <sk@intertivity.com>
    To: 'The elegant MVC web framework' <catalyst@lists.rawmode.org>
    Sent: Wed, 2 Nov 2005 10:39:25 +0000
    Subject: RE: [Catalyst] Self restarting test server for Win32!

    It's really not a easy one.
    I suggest to seperate to rewrite the HTTPServer by seperating the work in to
    scripts.
    One that runs the server, the other one that checks:
    1. the server is still runing; if not, restart it
    2. checks whether or not the files have changed
    That's pretty much what we have now, it's just implemented via fork rather than as separate scripts. I'm convinced that the problem here is kill() after fork(), leading the parent process to exit without shutting down its sockets properly. Hence the "phantom" process listening on the server's port.

    The solution to the problem would appear to be having the restarter notify the parent process whenever changes occur, rather than killing it. This would allow the parent to perform a graceful exit and close its sockets properly. I have something in mind to do just this and will post to the list once things have progressed a bit.

    wh
  • Sascha Kiefer at Nov 2, 2005 at 12:16 pm
    Not really.
    On Win32, the fork command does not create another process but creates
    another thread.
    Forking is not possible under Win32.
    You get the PID as a negative representation of the thread id.

    And i think killing yourself is not possible.
    Try the following script

    kill(1, $$);
    print "$_" for (1..10000);
    ^Z

    HTH
    --esskar
    On Behalf Of Will Hawes
    Sent: Mittwoch, 2. November 2005 12:03

    That's pretty much what we have now, it's just implemented
    via fork rather than as separate scripts. I'm convinced that
    the problem here is kill() after fork(), leading the parent
    process to exit without shutting down its sockets properly.
    Hence the "phantom" process listening on the server's port.


    wh
  • Sascha Kiefer at Nov 2, 2005 at 12:23 pm
    I thought about that to.
    A simple solution would be:
    - connect to the http-server
    - setting up a command like KILL / HTTP/1.0
    On the server side, you have to check if the KILL command comes from an
    allowed IP (A mask will help here)
    and then restart.

    --esskar
    -----Original Message-----
    On Behalf Of Will Hawes
    Sent: Mittwoch, 2. November 2005 12:03

    The solution to the problem would appear to be having the
    restarter notify the parent process whenever changes occur,
    rather than killing it. This would allow the parent to
    perform a graceful exit and close its sockets properly. I
    have something in mind to do just this and will post to the
    list once things have progressed a bit.

    wh


    _______________________________________________
    Catalyst mailing list
    Catalyst@lists.rawmode.org
    http://lists.rawmode.org/mailman/listinfo/catalyst
  • Andy Grundman at Nov 2, 2005 at 2:24 pm
    I've refactored the current restarter into a subclass,
    C::E::HTTP::Restarter. The change detection code has also been broken
    out into a separate class. This should make it a bit easier to write a
    win32 restarter, assuming there is a solution to the fork/kill problems.

    http://dev.catalyst.perl.org/changeset/1674

    -Andy
  • Will Hawes at Nov 2, 2005 at 2:35 pm
    ----- Original Message -----
    From: "Kiefer, Sascha" <sk@intertivity.com>
    To: 'The elegant MVC web framework' <catalyst@lists.rawmode.org>
    Sent: Wed, 2 Nov 2005 11:28:38 +0000
    Subject: RE: [Catalyst] Self restarting test server for Win32!

    I thought about that to.
    A simple solution would be:
    - connect to the http-server
    - setting up a command like KILL / HTTP/1.0
    On the server side, you have to check if the KILL command comes from an
    allowed IP (A mask will help here)
    and then restart.

    --esskar
    That's very similar to what I had in mind, although I hadn't thought about triggering the restart over HTTP.

    I have set up a test script that creates two sockets in the main process - one for HTTP traffic and another listening on a different port for restart commands. I then run inside a while(1) loop monitoring the HTTP socket in the same way the current test server does, but I also check the other socket at each iteration. If it receives whatever command is designated as "restart the server" (currently a simple "1"), it closes the server sockets properly and then exits. The restart message is sent from within a forked (or not, as the case may be on Win32) process analogous to $restarter in the current test server.

    This is all working well and should be possible to incorporate in the test server.
  • Matt S Trout at Nov 2, 2005 at 2:56 pm

    On Wed, Nov 02, 2005 at 01:41:36PM +0000, Will Hawes wrote:
    That's very similar to what I had in mind, although I hadn't thought about triggering the restart over HTTP.

    I have set up a test script that creates two sockets in the main process - one for HTTP traffic and another listening on a different port for restart commands. I then run inside a while(1) loop monitoring the HTTP socket in the same way the current test server does, but I also check the other socket at each iteration. If it receives whatever command is designated as "restart the server" (currently a simple "1"), it closes the server sockets properly and then exits. The restart message is sent from within a forked (or not, as the case may be on Win32) process analogous to $restarter in the current test server.

    This is all working well and should be possible to incorporate in the test server.
    I rather like the HTTP approach, given the current server already restarts
    cleanly on SIGHUP - maybe instead of a simple $GOT_HUP variable the Engine
    could have an ->restart_scheduled accessor, then the code becomes

    $SIG{HUP} = sub { $self->restart_scheduled(1); };

    and the restart code changes to

    if ($self->restart_scheduled) { # instead of if ($GOT_HUP)

    then you can simply have an action that sets restart_scheduled for the
    win32 restart - or maybe make the Engine shared into a restarter thread.

    --
    Matt S Trout Specialists in Perl consulting, web development, and
    Technical Director UNIX/Linux systems architecture and automation. Mail
    Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information

    + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
  • Will Hawes at Nov 8, 2005 at 4:26 pm
    Attached are patches to the latest (as of yesterday) Catalyst::Engine::HTTP and Catalyst::Engine::HTTP::Restarter to implement what is hopefully a cross-platform compatible, self-restarting test server.

    It uses sockets and should work on any system that supports them. As far as I am aware that should cover most (all?) Unix derivatives and any Windows from 2000 onwards. Verified on Win2K3, FreeBSD 5.4 and Suse Linux 10.0.

    This approach allows for a more graceful shutdown of the server - it doesn't kill() anything, ensuring that all ports can be released properly.

    I'd appreciate some testing and feedback. Note that you may need to open port 3001 if you are running a firewall on your machine - this is currently hard coded in the patch but can be changed later if all works as intended.

    wh
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: HTTP.pm.diff
    Type: application/octet-stream
    Size: 9139 bytes
    Desc: not available
    Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20051108/dafb429c/HTTP.pm.obj
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: Restarter.pm.diff
    Type: application/octet-stream
    Size: 1837 bytes
    Desc: not available
    Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20051108/dafb429c/Restarter.pm.obj
  • Sascha Kiefer at Nov 8, 2005 at 4:50 pm

    Will Hawes schrieb:
    Attached are patches to the latest (as of yesterday) Catalyst::Engine::HTTP and Catalyst::Engine::HTTP::Restarter to implement what is hopefully a cross-platform compatible, self-restarting test server.

    It uses sockets and should work on any system that supports them. As far as I am aware that should cover most (all?) Unix derivatives and any Windows from 2000 onwards. Verified on Win2K3, FreeBSD 5.4 and Suse Linux 10.0.

    This approach allows for a more graceful shutdown of the server - it doesn't kill() anything, ensuring that all ports can be released properly.

    I'd appreciate some testing and feedback. Note that you may need to open port 3001 if you are running a firewall on your machine - this is currently hard coded in the patch but can be changed later if all works as intended.

    wh

    ------------------------------------------------------------------------

    _______________________________________________
    Catalyst mailing list
    Catalyst@lists.rawmode.org
    http://lists.rawmode.org/mailman/listinfo/catalyst
    Hi.
    good job but i don't like your approach! Why? Well, i have three reasons.
    1. the port (3001) is not configurable (yet)
    2. anybody could send "1" to port 3001; you should check whether or not
    the ip comes from an allowed ip-endpoint using a mask := (ip & mask) ==
    client-ip (may require more configuration)
    3. it uses another TCP listen socket; why not using the HTTP listen
    socket and sending a special HTTP command like KILL / HTTP/1.0 (or
    CATALYST-KILL / HTTP/1.0)

    Regards,
    --esskar
  • Sebastian Riedel at Nov 8, 2005 at 7:07 pm

    Am 08.11.2005 um 16:55 schrieb Sascha Kiefer:

    Will Hawes schrieb:
    Attached are patches to the latest (as of yesterday)
    Catalyst::Engine::HTTP and Catalyst::Engine::HTTP::Restarter to
    implement what is hopefully a cross-platform compatible, self-
    restarting test server.

    It uses sockets and should work on any system that supports them.
    As far as I am aware that should cover most (all?) Unix
    derivatives and any Windows from 2000 onwards. Verified on Win2K3,
    FreeBSD 5.4 and Suse Linux 10.0.

    This approach allows for a more graceful shutdown of the server -
    it doesn't kill() anything, ensuring that all ports can be
    released properly.

    I'd appreciate some testing and feedback. Note that you may need
    to open port 3001 if you are running a firewall on your machine -
    this is currently hard coded in the patch but can be changed later
    if all works as intended.

    wh

    ---------------------------------------------------------------------
    ---

    _______________________________________________
    Catalyst mailing list
    Catalyst@lists.rawmode.org
    http://lists.rawmode.org/mailman/listinfo/catalyst
    Hi.
    good job but i don't like your approach! Why? Well, i have three
    reasons.
    1. the port (3001) is not configurable (yet)
    2. anybody could send "1" to port 3001; you should check whether or
    not the ip comes from an allowed ip-endpoint using a mask := (ip &
    mask) == client-ip (may require more configuration)
    3. it uses another TCP listen socket; why not using the HTTP listen
    socket and sending a special HTTP command like KILL / HTTP/1.0 (or
    CATALYST-KILL / HTTP/1.0)
    I like the KILL idea!
    But hurry if you want this included in 5.5, since we have a feature
    freeze tomorrow.


    --
    sebastian
  • Sascha Kiefer at Nov 8, 2005 at 11:03 pm
    Okay, here we go. :)

    Feel free to test it and add it to 5.5! :)

    Have fun
    --esskar
    -----Original Message-----
    From: catalyst-bounces@lists.rawmode.org
    On Behalf Of
    Sebastian Riedel
    Sent: Dienstag, 8. November 2005 19:16
    To: The elegant MVC web framework
    Subject: Re: [Catalyst] Self restarting test server for Win32!



    Am 08.11.2005 um 16:55 schrieb Sascha Kiefer:
    Will Hawes schrieb:
    Attached are patches to the latest (as of yesterday)
    Catalyst::Engine::HTTP and Catalyst::Engine::HTTP::Restarter to
    implement what is hopefully a cross-platform compatible, self-
    restarting test server.

    It uses sockets and should work on any system that supports them.
    As far as I am aware that should cover most (all?) Unix
    derivatives and any Windows from 2000 onwards. Verified on
    Win2K3,
    FreeBSD 5.4 and Suse Linux 10.0.

    This approach allows for a more graceful shutdown of the server -
    it doesn't kill() anything, ensuring that all ports can be
    released properly.

    I'd appreciate some testing and feedback. Note that you may need
    to open port 3001 if you are running a firewall on your machine -
    this is currently hard coded in the patch but can be
    changed later
    if all works as intended.

    wh
    ---------------------------------------------------------------------
    ---

    _______________________________________________
    Catalyst mailing list
    Catalyst@lists.rawmode.org
    http://lists.rawmode.org/mailman/listinfo/catalyst
    Hi.
    good job but i don't like your approach! Why? Well, i have three
    reasons.
    1. the port (3001) is not configurable (yet)
    2. anybody could send "1" to port 3001; you should check
    whether or
    not the ip comes from an allowed ip-endpoint using a mask := (ip &
    mask) == client-ip (may require more configuration)
    3. it uses another TCP listen socket; why not using the
    HTTP listen
    socket and sending a special HTTP command like KILL / HTTP/1.0 (or
    CATALYST-KILL / HTTP/1.0)
    I like the KILL idea!
    But hurry if you want this included in 5.5, since we have a feature
    freeze tomorrow.


    --
    sebastian


    _______________________________________________
    Catalyst mailing list
    Catalyst@lists.rawmode.org
    http://lists.rawmode.org/mailman/listinfo/catalyst
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: Restarter.pm.diff
    Type: application/octet-stream
    Size: 1908 bytes
    Desc: not available
    Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20051108/81ac9c0a/Restarter.pm-0001.obj
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: HTTP.pm.diff
    Type: application/octet-stream
    Size: 1748 bytes
    Desc: not available
    Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20051108/81ac9c0a/HTTP.pm-0001.obj
  • Sebastian Riedel at Nov 8, 2005 at 11:40 pm

    Am 08.11.2005 um 23:08 schrieb Kiefer, Sascha:

    Okay, here we go. :)

    Feel free to test it and add it to 5.5! :)
    Thanks, applied!

    http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst


    --
    sebastian

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedOct 31, '05 at 10:02a
activeNov 8, '05 at 11:40p
posts18
users5
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase