6 use Test::More no_plan => 1;
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 ...
50 return unless $self->is_daemon;
51 # change to our local dir
52 # so that we can debug easier
54 # make it easy to find with ps
57 print "Got INT! Oh Noes!";
61 print "Hello from $$\n";
68 my $d = MyFooDaemon->new;
69 isa_ok($d, 'MyFooDaemon');
70 does_ok($d, 'MooseX::Daemonize::Core');
74 } '... successfully daemonized from (' . $$ . ')';
76 my $p = $d->daemon_pid;
77 isa_ok($p, 'MooseX::Daemonize::Pid');
79 ok($p->is_running, '... the daemon process is running (' . $p->pid . ')');
85 diag `ps -x | grep test-app`;
90 diag "killed $pid" if DEBUG;
95 diag `ps -x | grep test-app`;
98 ok(!$p->is_running, '... the daemon process is no longer running (' . $p->pid . ')');
100 unlink $ENV{MX_DAEMON_STDOUT};
101 unlink $ENV{MX_DAEMON_STDERR};