6 use Test::More 'no_plan';
9 use File::Temp qw(tempdir);
10 use File::Spec::Functions;
12 my $dir = tempdir( CLEANUP => 1 );
15 use_ok('MooseX::Daemonize::Core');
16 use_ok('MooseX::Daemonize::Pid');
19 use constant DEBUG => 0;
21 $ENV{MX_DAEMON_STDOUT} = catfile($dir, 'Out.txt');
22 $ENV{MX_DAEMON_STDERR} = catfile($dir, 'Err.txt');
28 with 'MooseX::Daemonize::Core';
30 has 'daemon_pid' => (is => 'rw', isa => 'MooseX::Daemonize::Pid');
32 # capture the PID from the fork
33 around 'daemon_fork' => sub {
36 if (my $pid = $self->$next(@_)) {
38 MooseX::Daemonize::Pid->new(pid => $pid)
45 # tell it to ignore zombies ...
46 $self->ignore_zombies( 1 );
47 $self->no_double_fork( 1 );
49 return unless $self->is_daemon;
50 # change to our local dir
51 # so that we can debug easier
53 # make it easy to find with ps
56 print "Got INT! Oh Noes!";
60 print "Hello from $$\n";
67 my $d = MyFooDaemon->new;
68 isa_ok($d, 'MyFooDaemon');
69 does_ok($d, 'MooseX::Daemonize::Core');
73 } '... successfully daemonized from (' . $$ . ')';
75 my $p = $d->daemon_pid;
76 isa_ok($p, 'MooseX::Daemonize::Pid');
78 ok($p->is_running, '... the daemon process is running (' . $p->pid . ')');
84 diag `ps -x | grep test-app`;
89 diag "killed $pid" if DEBUG;
94 diag `ps -x | grep test-app`;
97 ok(!$p->is_running, '... the daemon process is no longer running (' . $p->pid . ')');
99 unlink $ENV{MX_DAEMON_STDOUT};
100 unlink $ENV{MX_DAEMON_STDERR};