Commit | Line | Data |
0ba6e8aa |
1 | package Catalyst::Script::FastCGI; |
cc999ce2 |
2 | use Moose; |
4e45780e |
3 | use MooseX::Types::Moose qw/Str Bool Int/; |
6640e166 |
4 | use Data::OptList; |
2adf69c3 |
5 | use namespace::autoclean; |
cc999ce2 |
6 | |
c821df21 |
7 | sub _plack_engine_name { 'FCGI' } |
8 | |
d3082fac |
9 | with 'Catalyst::ScriptRole'; |
f4dc8d2f |
10 | |
11 | has listen => ( |
ad8b4c91 |
12 | traits => [qw(Getopt)], |
13 | cmd_aliases => 'l', |
14 | isa => Str, |
15 | is => 'ro', |
d3082fac |
16 | documentation => 'Specify a listening port/socket', |
f4dc8d2f |
17 | ); |
18 | |
19 | has pidfile => ( |
ad8b4c91 |
20 | traits => [qw(Getopt)], |
ad08ab75 |
21 | cmd_aliases => [qw/pid p/], |
ad8b4c91 |
22 | isa => Str, |
23 | is => 'ro', |
d3082fac |
24 | documentation => 'Specify a pidfile', |
f4dc8d2f |
25 | ); |
26 | |
ab7eb5a9 |
27 | has daemon => ( |
ad8b4c91 |
28 | traits => [qw(Getopt)], |
29 | isa => Bool, |
30 | is => 'ro', |
7388bcae |
31 | cmd_aliases => [qw/d detach/], # Eww, detach is here as we fucked it up.. Deliberately not documented |
53c6ec79 |
32 | documentation => 'Daemonize (go into the background)', |
f4dc8d2f |
33 | ); |
34 | |
ab7eb5a9 |
35 | has manager => ( |
ad8b4c91 |
36 | traits => [qw(Getopt)], |
37 | isa => Str, |
38 | is => 'ro', |
39 | cmd_aliases => 'M', |
53c6ec79 |
40 | documentation => 'Use a different FastCGI process manager class', |
f4dc8d2f |
41 | ); |
42 | |
53c6ec79 |
43 | has keeperr => ( |
ad8b4c91 |
44 | traits => [qw(Getopt)], |
45 | cmd_aliases => 'e', |
46 | isa => Bool, |
47 | is => 'ro', |
d3082fac |
48 | documentation => 'Log STDERR', |
f4dc8d2f |
49 | ); |
50 | |
51 | has nproc => ( |
ad8b4c91 |
52 | traits => [qw(Getopt)], |
53 | cmd_aliases => 'n', |
54 | isa => Int, |
55 | is => 'ro', |
53c6ec79 |
56 | documentation => 'Specify a number of child processes', |
f4dc8d2f |
57 | ); |
58 | |
8865ee12 |
59 | has proc_title => ( |
9c74923d |
60 | traits => [qw(Getopt)], |
9c74923d |
61 | isa => Str, |
62 | is => 'ro', |
63 | lazy => 1, |
64 | builder => '_build_proc_title', |
65 | documentation => 'Set the process title', |
66 | ); |
67 | |
68 | sub _build_proc_title { |
69 | my ($self) = @_; |
70 | return sprintf 'perl-fcgi-pm [%s]', $self->application_name; |
71 | } |
72 | |
73 | sub BUILD { |
74 | my ($self) = @_; |
182f8b1e |
75 | $self->proc_title; |
9c74923d |
76 | } |
77 | |
f06d7696 |
78 | # Munge the 'listen' arg so that Plack::Handler::FCGI will accept it. |
79 | sub _listen { |
80 | my ($self) = @_; |
81 | |
82 | if (defined (my $listen = $self->listen)) { |
83 | return [ $listen ]; |
84 | } else { |
85 | return undef; |
86 | } |
87 | } |
88 | |
36a53c3a |
89 | sub _plack_loader_args { |
90 | my ($self) = shift; |
f06d7696 |
91 | |
92 | my $opts = Data::OptList::mkopt([ |
fd480b06 |
93 | qw/manager nproc proc_title/, |
94 | pid => [ 'pidfile' ], |
95 | daemonize => [ 'daemon' ], |
f06d7696 |
96 | keep_stderr => [ 'keeperr' ], |
97 | listen => [ '_listen' ], |
98 | ]); |
99 | |
100 | my %args = map { $_->[0] => $self->${ \($_->[1] ? $_->[1]->[0] : $_->[0]) } } @$opts; |
101 | |
102 | # Plack::Handler::FCGI thinks manager => undef means "use no manager". |
103 | delete $args{'manager'} unless defined $args{'manager'}; |
104 | |
105 | return %args; |
36a53c3a |
106 | } |
107 | |
d3082fac |
108 | sub _application_args { |
109 | my ($self) = shift; |
110 | return ( |
cc999ce2 |
111 | $self->listen, |
57dc50b0 |
112 | { |
9c74923d |
113 | nproc => $self->nproc, |
114 | pidfile => $self->pidfile, |
115 | manager => $self->manager, |
116 | detach => $self->daemon, |
53c6ec79 |
117 | keep_stderr => $self->keeperr, |
182f8b1e |
118 | proc_title => $self->proc_title, |
57dc50b0 |
119 | } |
cc999ce2 |
120 | ); |
cc999ce2 |
121 | } |
122 | |
73e4f0f1 |
123 | __PACKAGE__->meta->make_immutable; |
124 | |
d3082fac |
125 | =head1 NAME |
126 | |
127 | Catalyst::Script::FastCGI - The FastCGI Catalyst Script |
128 | |
129 | =head1 SYNOPSIS |
130 | |
53c6ec79 |
131 | myapp_fastcgi.pl [options] |
132 | |
133 | Options: |
8865ee12 |
134 | -? --help display this help and exits |
135 | -l --listen Socket path to listen on |
136 | (defaults to standard input) |
137 | can be HOST:PORT, :PORT or a |
138 | filesystem path |
139 | -n --nproc specify number of processes to keep |
140 | to serve requests (defaults to 1, |
141 | requires -listen) |
142 | -p --pidfile specify filename for pid file |
143 | (requires -listen) |
144 | -d --daemon daemonize (requires -listen) |
145 | -M --manager specify alternate process manager |
146 | (FCGI::ProcManager sub-class) |
147 | or empty string to disable |
148 | -e --keeperr send error messages to STDOUT, not |
149 | to the webserver |
150 | --proc_title set the process title |
d3082fac |
151 | |
152 | =head1 DESCRIPTION |
153 | |
53c6ec79 |
154 | Run a Catalyst application as fastcgi. |
d3082fac |
155 | |
156 | =head1 AUTHORS |
157 | |
158 | Catalyst Contributors, see Catalyst.pm |
159 | |
160 | =head1 COPYRIGHT |
161 | |
162 | This library is free software. You can redistribute it and/or modify it under |
163 | the same terms as Perl itself. |
164 | |
165 | =cut |