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:
- it handles any existing connections
- does not accept any new ones
- 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......
|