You can't KILL a script, start a new instance of that script and pass open TCP socket connections from the deceased script to the new process easily. You can fork of course but all that gives you is a copy of the existing process running at the same point so it does not solve your issue.

You say reload the script completely but you don't seem to want that. You want to reinitialize some stuff but keep some stuff in the running code. You can start a brand new script (mutating the running one into it) with exec() but I doubt this is what you want.

If the issue is maintaining a login state then use some sort of persistent session arrangement, almost everyone has written one ;-) but there are lots of good ones on CPAN depending on context.

An alternative would still be to use the HUP signal but arrange it so that when a process recieves the HUP:

  1. it handles any existing connections
  2. does not accept any new ones
  3. exits when done

You can then start a new process which will handle new connections while the old process handles the existing ones. This is the basis of the apache graceful command. The major issue you will probably have is that the old process may be bound to a particular listen port and thus prevent the new process from starting......

cheers

tachyon


In reply to Re: Re: Restarting a script without dropping clients by tachyon
in thread Restarting a script without dropping clients by Ahbeyra

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.