17.16. Restarting a Server on DemandProblem
You want your server to shutdown and restart when it receives a HUP signal, just like Solution
Catch the $SELF = "/usr/local/libexec/myd"; # which program I am @ARGS = qw(-l /var/log/myd -d); # program arguments $SIG{HUP} = \&phoenix; sub phoenix { # close all your connections, kill your children, and # generally prepare to be reincarnated with dignity. exec($SELF, @ARGS) or die "Couldn't restart: $!\n"; } Discussion
It sure looks simple ("when I get a HUP signal, restart") but it's tricky. You must know your own program name, and that isn't easy to find out. You could use
Be sure and install your signal handler
after
you define Some servers don't want restart on receiving a SIGHUP - they just want to reread their configuration file. $CONFIG_FILE = "/usr/local/etc/myprog/server_conf.pl"; $SIG{HUP} = \&read_config; sub read_config { do $CONFIG_FILE; } Some clever servers even autoload their configuration files when they notice that those files have been updated. That way you don't have to go out of your way to signal them. See Also
The
|
|