Show
Ignore:
Timestamp:
06/18/08 18:02:28 (5 months ago)
Author:
tokuhirom
Message:

use MooseX::Daemonize.

Location:
lang/perl/App-Nakanobu/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/App-Nakanobu/trunk/Makefile.PL

    r14195 r14214  
    55requires 'JSON::RPC::Common'   => 0.03; 
    66requires 'Moose'               => 0.50; 
     7requires 'MooseX::Daemonize'   => 0.05; 
    78requires 'MooseX::Plaggerize'  => 0.04; 
    89requires 'POE'                 => 1.0002; 
  • lang/perl/App-Nakanobu/trunk/lib/App/Nakanobu.pm

    r14195 r14214  
    33use 5.00800; 
    44our $VERSION = '0.01'; 
    5 with 'MooseX::Plaggerize'; 
     5with 'MooseX::Plaggerize', 'MooseX::Daemonize'; 
    66use POE; 
     7use YAML; 
     8use File::Spec; 
     9use FindBin; 
     10use MooseX::Types::Path::Class; 
     11 
     12has conffile => ( 
     13    cmd_aliases => 'c', 
     14    metaclass   => 'Getopt', 
     15    is          => 'ro', 
     16    isa         => 'Path::Class::File', 
     17    default     => sub { 
     18        Path::Class::File->new( $FindBin::Bin, 'config.yaml' ); 
     19    }, 
     20); 
    721 
    822has config => ( 
    9     is => 'ro', 
    10     isa => 'HashRef', 
     23    is      => 'rw', 
     24    isa     => 'HashRef', 
     25    lazy    => 1, 
     26    default => sub { 
     27        my $self = shift; 
     28        YAML::LoadFile( $self->conffile ) 
     29    }, 
    1130); 
    1231 
     
    1433sub context { $context } 
    1534 
    16 sub run { 
     35after 'start' => sub { 
    1736    my ($self, ) = @_; 
     37    return unless $self->is_daemon; 
     38 
     39    $self->config; # evaluate lazy attribute 
     40    $self->_load_plugins(); 
    1841    $context = $self; 
    19     $self->_load_plugins(); 
    2042    $self->run_hook('run_component'); 
    2143    $SIG{INT} = sub { POE::Kernel->stop }; 
    2244    POE::Kernel->run(); 
    23 } 
     45}; 
    2446 
    2547sub _load_plugins { 
  • lang/perl/App-Nakanobu/trunk/nakanobu.pl

    r14195 r14214  
    66use lib catfile($FindBin::Bin, 'lib'); 
    77use App::Nakanobu; 
    8 use YAML; 
    98 
    10 my $conf = YAML::LoadFile(catfile($FindBin::Bin, 'config.yaml')); 
    11 my $nakanobu = App::Nakanobu->new(config => $conf); 
    12 $nakanobu->run(); 
     9my $daemon = App::Nakanobu->new_with_options(); 
    1310 
     11my ($command) = @{$daemon->extra_argv}; 
     12defined $command || die "No command specified"; 
     13 
     14$daemon->start   if $command eq 'start'; 
     15$daemon->status  if $command eq 'status'; 
     16$daemon->restart if $command eq 'restart'; 
     17$daemon->stop    if $command eq 'stop'; 
     18 
     19warn($daemon->status_message); 
     20exit($daemon->exit_code); 
     21