4 use File::Spec::Functions;
9 use File::Temp qw(tempdir);
11 my $dir = tempdir( CLEANUP => 1 );
15 use_ok('MooseX::Daemonize::Core');
18 use constant DEBUG => 0;
20 my $PIDFILE = catfile($dir, 'test-app.pid');
21 $ENV{MX_DAEMON_STDOUT} = catfile($dir, 'Out.txt');
22 $ENV{MX_DAEMON_STDERR} = catfile($dir, 'Err.txt');
28 with 'MooseX::Daemonize::WithPidFile';
31 MooseX::Daemonize::Pid::File->new( file => $PIDFILE )
37 # this tests our bad PID
38 # cleanup functionality.
39 print "Our parent PID is " . $self->pidfile->pid . "\n" if ::DEBUG;
42 return unless $self->is_daemon;
44 # make it easy to find with ps
47 print "Got INT! Oh Noes!";
48 $self->pidfile->remove;
52 print "Hello from $$\n";
59 my $d = MyFooDaemon->new( pidfile => $PIDFILE );
60 isa_ok($d, 'MyFooDaemon');
61 does_ok($d, 'MooseX::Daemonize::Core');
62 does_ok($d, 'MooseX::Daemonize::WithPidFile');
64 ok($d->has_pidfile, '... we have a pidfile value');
68 isa_ok($p, 'MooseX::Daemonize::Pid::File');
72 ok(!(-e $PIDFILE), '... the PID file does not exist yet');
75 exception { $d->start },
77 '... successfully daemonized from (' . $$ . ')',
81 isa_ok($p, 'MooseX::Daemonize::Pid::File');
86 ok($p->does_file_exist, '... the PID file exists');
87 ok($p->is_running, '... the daemon process is running (' . $p->pid . ')');
93 diag `ps -x | grep test-app`;
98 diag "killed $pid" if DEBUG;
103 diag `ps -x | grep test-app`;
106 ok(!$p->is_running, '... the daemon process is no longer running (' . $p->pid . ')');
107 ok(!(-e $PIDFILE), '... the PID file has been removed');
109 unlink $ENV{MX_DAEMON_STDOUT};
110 unlink $ENV{MX_DAEMON_STDERR};