Merge branch 'master' into psgi
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Script / FastCGI.pm
CommitLineData
0ba6e8aa 1package Catalyst::Script::FastCGI;
cc999ce2 2use Moose;
4e45780e 3use MooseX::Types::Moose qw/Str Bool Int/;
6640e166 4use Data::OptList;
2adf69c3 5use namespace::autoclean;
cc999ce2 6
c821df21 7sub _plack_engine_name { 'FCGI' }
8
d3082fac 9with 'Catalyst::ScriptRole';
f4dc8d2f 10
11has 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
19has 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 27has 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 35has 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 43has keeperr => (
ad8b4c91 44 traits => [qw(Getopt)],
45 cmd_aliases => 'e',
46 isa => Bool,
47 is => 'ro',
d3082fac 48 documentation => 'Log STDERR',
f4dc8d2f 49);
50
51has 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
9c74923d 59has title => (
60 traits => [qw(Getopt)],
61 cmd_aliases => 't',
62 isa => Str,
63 is => 'ro',
64 lazy => 1,
65 builder => '_build_proc_title',
66 documentation => 'Set the process title',
67);
68
69sub _build_proc_title {
70 my ($self) = @_;
71 return sprintf 'perl-fcgi-pm [%s]', $self->application_name;
72}
73
74sub BUILD {
75 my ($self) = @_;
76 $self->title;
77}
78
36a53c3a 79sub _plack_loader_args {
80 my ($self) = shift;
81 return (
6640e166 82 map { $_->[0] => $self->${ \($_->[1] ? $_->[1]->[0] : $_->[0]) } }
83 Data::OptList::mkopt([
84 qw/pidfile listen manager nproc keep_stderr/,
9c74923d 85 detach => [ 'daemon' ],
86 proc_title => [ 'title' ],
6640e166 87 ])
36a53c3a 88 );
89}
90
d3082fac 91sub _application_args {
92 my ($self) = shift;
93 return (
cc999ce2 94 $self->listen,
57dc50b0 95 {
9c74923d 96 nproc => $self->nproc,
97 pidfile => $self->pidfile,
98 manager => $self->manager,
99 detach => $self->daemon,
53c6ec79 100 keep_stderr => $self->keeperr,
9c74923d 101 title => $self->title,
57dc50b0 102 }
cc999ce2 103 );
cc999ce2 104}
105
73e4f0f1 106__PACKAGE__->meta->make_immutable;
107
d3082fac 108=head1 NAME
109
110Catalyst::Script::FastCGI - The FastCGI Catalyst Script
111
112=head1 SYNOPSIS
113
53c6ec79 114 myapp_fastcgi.pl [options]
115
116 Options:
ad8b4c91 117 -? --help display this help and exits
118 -l --listen Socket path to listen on
119 (defaults to standard input)
120 can be HOST:PORT, :PORT or a
121 filesystem path
122 -n --nproc specify number of processes to keep
123 to serve requests (defaults to 1,
124 requires -listen)
125 -p --pidfile specify filename for pid file
126 (requires -listen)
127 -d --daemon daemonize (requires -listen)
128 -M --manager specify alternate process manager
129 (FCGI::ProcManager sub-class)
130 or empty string to disable
131 -e --keeperr send error messages to STDOUT, not
132 to the webserver
9c74923d 133 -t --title set the process title
d3082fac 134
135=head1 DESCRIPTION
136
53c6ec79 137Run a Catalyst application as fastcgi.
d3082fac 138
139=head1 AUTHORS
140
141Catalyst Contributors, see Catalyst.pm
142
143=head1 COPYRIGHT
144
145This library is free software. You can redistribute it and/or modify it under
146the same terms as Perl itself.
147
148=cut