ty (Fri 12/07/07 14:57): > I was looking to turn some of the servers I have written in POE into > daemons that would be run as non-root users because I do not have root > permissions on the machine they will run on. Could anyone share their > experience of creating daemons with POE? How have you handled > ensuring the server is always running? How do you recover from a > crash? Have you added any logging to your daemon?
We run several different daemons using POE. For the daemon I've always used Net::Server::Daemonize. Very stable and easy to use: daemonize(user => group => /path/to/pid); # daemon code below If you search the list you'll find that some have experienced buggy behavior using Proc::Daemon and POE. For logs I use Logfile::Rotate. Whichever event does the logging also checks if it's time to rotate, e.g. at midnight: # check if it's time to rotate the log first if( (exists $h->{last_hour}) && ($hr < $h->{last_hour})){ if(close $h->{log}){ my $log = new Logfile::Rotate( File => $h->{log_file}, Gzip => '/bin/gzip', Dir => $h->{log_dir}, Flock => 'yes', Persist => 'yes'); $log->rotate; } else{ $k->post(@{$h->{error_session}}, "Failed to close log file $h->{log_file} for rotation: $!") } } $h->{last_hour} = $hr; # open if necessary and print your log message Ensuring that it's running would be done the same way that you make sure any other daemon, e.g. apache, sendmail, etc., are running. All of ours have standard start up scripts. We monitor them indirectly via what tasks they're supposed to be doing. There are certainly more sophisticated ways of monitoring status but this suffices. Recovering from a crash depends entirely on what your daemon is doing. It's possible you'll only need to restart it, or it may be a bit more complicated than that. For example, we have a daemon that recovers jobs it was running after a crash. Cheers, Zach