| 1 | package FCGI::Engine::Manager::Server; | ||
| 2 | use Moose; | ||
| 3 | |||
| 4 | use MooseX::Daemonize::Pid::File; | ||
| 5 | use FCGI::Engine::Types; | ||
| 6 | use Config; | ||
| 7 | |||
| 8 | our $VERSION = '0.22'; | ||
| 9 | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 10 | |||
| 11 | has 'name' => ( | ||
| 12 | is => 'ro', | ||
| 13 | isa => 'Str', | ||
| 14 | lazy => 1, | ||
| 15 | default => sub { | ||
| 16 | ((shift)->scriptname . '.server') | ||
| 17 | } | ||
| 18 | ); | ||
| 19 | |||
| 20 | has 'socket' => ( | ||
| 21 | is => 'ro', | ||
| 22 | isa => 'FCGI::Engine::Listener', | ||
| 23 | coerce => 1, | ||
| 24 | required => 1, | ||
| 25 | ); | ||
| 26 | |||
| 27 | has $_ => ( | ||
| 28 | is => 'ro', | ||
| 29 | isa => 'Path::Class::File', | ||
| 30 | coerce => 1, | ||
| 31 | required => 1, | ||
| 32 | ) for qw[ | ||
| 33 | scriptname | ||
| 34 | pidfile | ||
| 35 | ]; | ||
| 36 | |||
| 37 | has 'nproc' => ( | ||
| 38 | is => 'ro', | ||
| 39 | isa => 'Int', | ||
| 40 | default => sub { 1 } | ||
| 41 | ); | ||
| 42 | |||
| 43 | has 'additional_args' => ( | ||
| 44 | is => 'ro', | ||
| 45 | isa => 'ArrayRef', | ||
| 46 | auto_deref => 1, | ||
| 47 | predicate => 'has_additional_args' | ||
| 48 | ); | ||
| 49 | |||
| 50 | ## ... internal attributes | ||
| 51 | |||
| 52 | has 'pid_obj' => ( | ||
| 53 | is => 'ro', | ||
| 54 | isa => 'MooseX::Daemonize::Pid::File', | ||
| 55 | lazy => 1, | ||
| 56 | default => sub { | ||
| 57 | MooseX::Daemonize::Pid::File->new(file => (shift)->pidfile) | ||
| 58 | }, | ||
| 59 | clearer => 'remove_pid_obj', | ||
| 60 | ); | ||
| 61 | |||
| 62 | ## methods ... | ||
| 63 | |||
| 64 | sub construct_command_line { | ||
| 65 | my $self = shift; | ||
| 66 | my $perl = $Config{perlpath}; | ||
| 67 | $perl .= $Config{_exe} if $^O ne 'VMS' and $perl !~ /$Config{_exe}$/i; | ||
| 68 | return ($perl, | ||
| 69 | ($self->has_additional_args | ||
| 70 | ? $self->additional_args | ||
| 71 | : ()), | ||
| 72 | $self->scriptname, | ||
| 73 | "--nproc", | ||
| 74 | $self->nproc, | ||
| 75 | "--pidfile", | ||
| 76 | $self->pidfile, | ||
| 77 | "--listen", | ||
| 78 | $self->socket, | ||
| 79 | "--daemon"); | ||
| 80 | } | ||
| 81 | |||
| 82 | # NOTE: | ||
| 83 | # perhaps the server status information | ||
| 84 | # should also go in here, so that we can | ||
| 85 | # keep it all in one place. | ||
| 86 | # - SL | ||
| 87 | |||
| 88 | 1; | ||
| 89 | |||
| 90 | __END__ |