Catalyst-Helper-FastCGI-ExternalServer

 view release on metacpan or  search on metacpan

lib/Catalyst/Helper/FastCGI/ExternalServer.pm  view on Meta::CPAN

      specify username of executiong fastcgi
      default is root

    o=[val] logfile=[val] (optional)

      specify logfile path
      default is /dev/null

    M=[val] manager=[val] (optional)

      specify alternate process manager
      (FCGI::ProcManager sub-class)
      or empty string to disable

    e=[key1:val1,key2:val2...] env=[key1:val1,key2:val2...] (optional)

      specify additional environment variables

=head1 DESCRIPTION

This module allows configuration using /etc/sysconfig/myapp.
First make a file called /etc/sysconfig/myapp and then write some variables in it.
The variables that you add to the file will automatically override the environment variables.

=head1 METHODS

=head2 mk_stuff

generate init script

=cut

sub mk_stuff {
    my ( $self, $helper, @args ) = @_;

    my $config = {
        listen    => undef,
        nproc     => 1,
        pidfile   => undef,
        manager   => undef,
        env       => {},
        user      => 'root',
        logfile   => '/dev/null',
        app       => $helper->{app},
        author    => $helper->{author},
        home      => realpath( $helper->{base} ),
        appprefix => Catalyst::Utils::appprefix( $helper->{app} ),
        date      => DateTime->now->ymd,
        version   => __PACKAGE__->VERSION
    };

    $self->_parse_args( $config, @args );

    $config->{script}         = $config->{appprefix} . "_fastcgi_server.sh";
    $config->{fastcgi_script} = $config->{appprefix} . "_fastcgi.pl";

    my $script_file
        = File::Spec->catfile( $helper->{base}, 'script', $config->{script} );

    $helper->render_file( 'script', $script_file, $config );
    chmod 0755, $script_file;
}

sub _parse_args {
    my ( $self, $config, @args ) = @_;

    local @ARGV = ();

    foreach (@args) {
        my ( $key, $value ) = split /=/;
        $key ||= $_;

        push( @ARGV, "--$key" );
        push( @ARGV, $value ) if ( defined $value );
    }

    my $listen = undef;
    my $nproc  = 1;
    my $pidfile
        = File::Spec->catfile( '/var/run', $config->{appprefix} . '.pid' );
    my $manager = undef;
    my $daemon  = undef;
    my $env     = undef;
    my $user    = 'root';
    my $logfile = '/dev/null';

    GetOptions(
        'listen|l=s'  => \$listen,
        'nproc|n=i'   => \$nproc,
        'pidfile|p=s' => \$pidfile,
        'manager|M=s' => \$manager,
        'env|e=s'     => \$env,
        'user|u=s'    => \$user,
        'logfile|o=s' => \$logfile
    );

    $config->{listen}  = realpath($listen)  if ($listen);
    $config->{nproc}   = int $nproc         if ($nproc);
    $config->{pidfile} = realpath($pidfile) if ($pidfile);
    $config->{manager} = $manager           if ($manager);
    $config->{user}    = $user              if ($user);
    $config->{logfile} = realpath($logfile) if ($logfile);
    $config->{env}     = ($env) ? {
        map { split /:/ }
            split /,/ => $env
        }
        : {};

}

=head1 AUTHORS

=over 2

=item Toru Yamaguchi, C<< <zigorou at cpan.org> >>

Making this module.

=item Naoya Sano, C<< <sano at naoya.net> >>

Making init script template for FedoraCore, RedHat.



( run in 0.816 second using v1.01-cache-2.11-cpan-39bf76dae61 )