App::Framework::Extension::Daemon


NAME

App::Framework::Daemon - Daemonize an application


SYNOPSIS

use App::Framework qw/Daemon/ ;


DESCRIPTION

App::Framework personality that provides a daemonized program (using Net::Server::Daemonize)

FIELDS

None

CONSTRUCTOR METHODS

new([%args])

Create a new App::Framework::Daemon.

The %args are specified as they would be in the set method, for example:

        'mmap_handler' => $mmap_handler

The full list of possible arguments are :

        'fields'        => Either ARRAY list of valid field names, or HASH of field names with default values

CLASS METHODS

init_class([%args])

Initialises the object class variables.

OBJECT METHODS

<daemon_run()>

Daemonize then run the application's app subroutine inside a loop.


=cut

sub daemon_run { my $this = shift ;

my $use_net=0; if ($use_net) {

print "Calling daemonize()...\n" ; ## Daemonize Net::Server::Daemonize::daemonize( $this->user, # User $this->group, # Group $this->pid, # Path to PID file - optional ); print "Calling application run...\n" ;


        ## call application run
        $this->call_extend_fn('app_fn') ;

}

else { ##my $pid = safe_fork(); print "Calling fork()...\n" ; my $pid = fork; unless( defined $pid ){ die "Couldn't fork: [$!]\n"; }

  ### parent process should do the pid file and exit
  if( $pid ){

print "Killing parent..\n" ; $pid && exit(0);

  ### child process will continue on
  }else{
        
        print "Calling application run...\n" ;
        
        ## call application run
        $this->call_extend_fn('app_fn') ;
  }
}

}

# ============================================================================================ # PRIVATE METHODS # ============================================================================================

# ============================================================================================ # END OF PACKAGE


DIAGNOSTICS

Setting the debug flag to level 1 prints out (to STDOUT) some debug messages, setting it to level 2 prints out more verbose messages.


AUTHOR

Steve Price <sdprice at cpan.org>


BUGS

None that I know of!

 App::Framework::Extension::Daemon