7 use File::Temp qw(tempdir);
8 use File::Spec::Functions;
10 my $dir = tempdir( CLEANUP => 1 );
13 use_ok('MooseX::Daemonize::Core');
14 use_ok('MooseX::Daemonize::Pid');
17 use constant DEBUG => 0;
19 $ENV{MX_DAEMON_STDOUT} = catfile($dir, 'Out.txt');
20 $ENV{MX_DAEMON_STDERR} = catfile($dir, 'Err.txt');
26 with 'MooseX::Daemonize::Core';
28 has 'daemon_pid' => (is => 'rw', isa => 'MooseX::Daemonize::Pid');
30 # capture the PID from the fork
31 around 'daemon_fork' => sub {
34 if (my $pid = $self->$next(@_)) {
36 MooseX::Daemonize::Pid->new(pid => $pid)
43 # tell it to ignore zombies ...
48 return unless $self->is_daemon;
49 # change to our local dir
50 # so that we can debug easier
52 # make it easy to find with ps
55 print "Got INT! Oh Noes!";
59 print "Hello from $$\n";
66 my $d = MyFooDaemon->new;
67 isa_ok($d, 'MyFooDaemon');
68 does_ok($d, 'MooseX::Daemonize::Core');
71 exception { $d->start },
73 '... 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};