# Specific dependencies
build_requires 'Test::More' => 0;
-requires 'Proc::Daemon' => 0;
requires 'MooseX::Getopt' => 0;
requires 'Moose' => 0.20;
# Try SIGINT ... 2s ... SIGTERM ... 2s ... SIGKILL ... 3s ... UNDEAD!
for ( [ 2, $timeout ], [15, $timeout], [9, $timeout * 1.5] ) {
- my ($signal, $timeout) = @$_;
- $timeout = int $timeout;
-
- CORE::kill($signal, $pid);
-
- last unless CORE::kill 0 => $pid or $!{EPERM};
-
- while ($timeout) {
- sleep(1);
+ my ($signal, $timeout) = @$_;
+ $timeout = int $timeout;
+
+ CORE::kill($signal, $pid);
+
last unless CORE::kill 0 => $pid or $!{EPERM};
- $timeout--;
- }
+
+ while ($timeout) {
+ sleep(1);
+ last unless CORE::kill 0 => $pid or $!{EPERM};
+ $timeout--;
+ }
}
return unless ( CORE::kill 0 => $pid or $!{EPERM} );
our $VERSION = 0.01;
-use Proc::Daemon;
+use POSIX ();
has is_daemon => (
isa => 'Bool',
default => sub { 0 },
);
-sub daemon_fork { Proc::Daemon::Fork }
-sub daemon_detach { Proc::Daemon::Init }
+sub daemon_fork { fork }
+sub daemon_detach {
+ # ignore these signals
+ for (qw(TSTP TTIN TTOU PIPE POLL STOP CONT CHLD)) {
+ $SIG{$_} = 'IGNORE' if (exists $SIG{$_});
+ }
+
+ POSIX::setsid; # set session id
+ chdir '/'; # change to root directory
+ umask 0; # clear the file creation mask
+
+ # get the max numnber of possible file descriptors
+ my $openmax = POSIX::sysconf( &POSIX::_SC_OPEN_MAX );
+ $openmax = 64 if !defined($openmax) || $openmax < 0;
+
+ # close them all
+ POSIX::close($_) foreach (0 .. $openmax);
+
+ open(STDIN, "+>/dev/null");
+ open(STDOUT, "+>&STDIN");
+ open(STDERR, "+>&STDIN");
+}
sub daemonize {
my ($self) = @_;