6 use File::Spec::Functions;
8 use Test::More tests => 9;
11 use constant DEBUG => 0;
14 my $FILENAME = "$CWD/im_alive";
15 $ENV{MX_DAEMON_STDOUT} = catfile($CWD, 'Out.txt');
16 $ENV{MX_DAEMON_STDERR} = catfile($CWD, 'Err.txt');
22 with qw(MooseX::Daemonize);
24 has filename => ( isa => 'Str', is => 'ro' );
28 if ($self->is_daemon) {
29 $self->create_file( $self->filename );
34 my ( $self, $file ) = @_;
35 open( my $FILE, ">$file" ) || die $!;
40 my $app = FileMaker->new(
42 filename => $FILENAME,
45 ok(!$app->status, '... the daemon is running');
49 ok($app->start, '... daemon started');
50 sleep(1); # give it a second ...
52 ok($app->status, '... the daemon is running');
54 my $pid = $app->pidfile->pid;
55 isnt($pid, $$, '... the pid in our pidfile is correct (and not us)');
59 diag "Status is: " . $app->status_message;
62 ok( -e $app->filename, "file exists" );
63 ok($app->status, '... the daemon is still running');
67 diag "Status is: " . $app->status_message;
70 ok( $app->stop, 'app stopped' );
71 ok(!$app->status, '... the daemon is no longer running');
75 diag "Status is: " . $app->status_message;
78 ok( not(-e $app->pidfile->file) , 'pidfile gone' );
81 unlink $ENV{MX_DAEMON_STDOUT};
82 unlink $ENV{MX_DAEMON_STDERR};