Server-Control

 view release on metacpan or  search on metacpan

lib/Server/Control/Starman.pm  view on Meta::CPAN

}
use File::Slurp qw(read_file);
use File::Which qw(which);
use Log::Any qw($log);
use Moose;
use strict;
use warnings;

extends 'Server::Control';

has '+binary_name'   => ( is => 'ro', isa => 'Str', default => 'starman' );
has 'app_psgi'       => ( is => 'ro', required => 1 );
has 'options'        => ( is => 'ro', required => 1, isa => 'HashRef' );
has 'options_string' => ( is => 'ro', init_arg => undef, lazy_build => 1 );

sub BUILD {
    my ( $self, $params ) = @_;

    $self->{params} = $params;
}

lib/Server/Control/Starman.pm  view on Meta::CPAN


sub do_start {
    my $self = shift;

    $self->run_system_command(
        sprintf( '%s %s %s',
            $self->binary_path, $self->options_string, $self->app_psgi )
    );
}

# HACK - starman does not show up in Proc::ProcessTable on Linux for some reason!
# Fall back to using /proc directly.
#
sub _find_process {
    my ( $self, $pid ) = @_;

    if ( $^O eq 'linux' ) {
        my $procdir = "/proc/$pid";
        if ( -d $procdir ) {
            my $proc = bless( { pid => $pid, uid => ( stat($procdir) )[4] },
                'Proc::ProcessTable::Process' );

lib/Server/Control/Starman.pm  view on Meta::CPAN

Server::Control::Starman -- Control Starman

=head1 VERSION

version 0.20

=head1 SYNOPSIS

    use Server::Control::Starman;

    my $starman = Server::Control::Starman->new(
        binary_path => '/usr/local/bin/starman'
        options => {
            port      => 123,
            error_log => '/path/to/error.log',
            pid       => '/path/to/starman.pid'
        },
    );
    if ( !$starman->is_running() ) {
        $starman->start();
    }

=head1 DESCRIPTION

Server::Control::Starman is a subclass of L<Server::Control|Server::Control>
for L<Starman|Starman> processes.

=head1 CONSTRUCTOR

In addition to the constructor options described in
L<Server::Control|Server::Control>:

=over

=item app_psgi

Path to app.psgi; required.

=item options

Options to pass to the starman binary; required. Possible keys include:
C<listen>, C<host>, C<port>, C<workers>, C<backlog>, C<max_requests>, C<user>,
C<group>, C<pid>, and C<error_log>. Underscores are converted to dashes before
passing to starman.

C<--daemonize> and C<--preload-app> are automatically passed to starman; the
only current way to change this is by subclassing and overriding
C<_build_options_string>.

In addition, the C<error_log>, C<pid>, and C<port> options, if given, will be
used to populate the corresponding Server::Control parameters
(L<error_log|Server::Control/error_log>, L<pid_file|Server::Control/pid_file>,
and L<port|Server::Control/port>).

e.g. this

    options => {
        port      => 123,
        error_log => '/path/to/error.log',
        max_requests => 100,
        pid       => '/path/to/starman.pid'
    }

will result in command line options

    --port 123 --error-log /path/to/error.log --max-requests 100
    --pid /path/to/starman.pid --daemonize --preload-app

=back

=head1 SEE ALSO

L<Server::Control|Server::Control>, L<Starman|Starman>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Jonathan Swartz.

lib/Server/Control/t/Starman.pm  view on Meta::CPAN


    my $app_psgi = "$temp_dir/app.psgi";
    write_file( $app_psgi, $app_psgi_content );

    return Server::Control::Starman->new(
        %extra_params,
        app_psgi => $app_psgi,
        options  => {
            port      => $port,
            workers   => 2,
            pid       => "$temp_dir/starman.pid",
            error_log => "$temp_dir/error.log"
        }
    );
}

1;



( run in 0.315 second using v1.01-cache-2.11-cpan-e93a5daba3e )