Daemon - Start an Application as a Daemon
use HTTP::Server::Daemon qw(check_pid become_daemon); my $child_num = 0; my $quit = 1; my $pidfile = become_daemon(__FILE__); $SIG{CHLD} = sub { while(waitpid(-1,WNOHANG)>0){ $child_num--; } }; $SIG{TERM} = $SIG{INT} = sub { unlink $pidfile; $quit--; }; while ($quit){ #do your things; }
Help running an application as a daemon.
Prefork a net server listen on the given port.
Fork a child listen the port. (Internal methods).
Let the proccess listen on given port using protocol 'TCP'.
Send msg to sock using protocol 'PON'(Perl Object Notation).
Receive msg from sock using protocol 'PON'(Perl Object Notation).
Return ($peer_port, $peer_ip).
Enable white list net filter. Allow only ip list in 'conf/allowip.conf' access, return 0. Others return 'deny'.
Deal with pid file things. Can be used independently.
Let the proccess become a daemon. Can be used independently.
Written by ChenGang, yikuyiku.com@gmail.com
http://blog.yikuyiku.com/
Copyright (c) 2011 ChenGang. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Parallel::Prefork, Daemon::Generic
To install HTTP::Server::Encrypt, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::Server::Encrypt
CPAN shell
perl -MCPAN -e shell install HTTP::Server::Encrypt
For more information on module installation, please visit the detailed CPAN module installation guide.