Gearman-Server

 view release on metacpan or  search on metacpan

bin/gearmand  view on Meta::CPAN

handle jobs in the queue.

=item --version

Display the version and exit.

=back

=head1 COPYRIGHT

Copyright 2005-2007, Danga Interactive

You are granted a license to use it under the same terms as Perl itself.

=head1 WARRANTY

This is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.

=head1 AUTHORS

Brad Fitzpatrick <brad@danga.com>

Brad Whitaker <whitaker@danga.com>

=head1 SEE ALSO

L<Gearman::Server>

L<Gearman::Client>

L<Gearman::Worker>

L<Gearman::Client::Async>

=cut

package Gearmand;
use strict;
use warnings;

BEGIN {
    # Provide informative names to anonymous subroutines
    $^P = 0x200;
}

use Gearman::Server;

use Carp;
use Danga::Socket 1.52;
use Gearman::Util;
use Getopt::Long;
use IO::Socket::INET;
use POSIX ();
use Pod::Usage;
use Scalar::Util ();

use vars qw($DEBUG);

$DEBUG = 0;

my ($daemonize, $nokeepalive, $notify_pid, $opt_pidfile, $accept, $wakeup,
    $wakeup_delay, $conf_host,);
my $conf_port = 4730;

Getopt::Long::GetOptions(
    'd|daemonize'    => \$daemonize,
    'p|port=i'       => \$conf_port,
    'listen|L=s'     => \$conf_host,
    'debug=i'        => \$DEBUG,
    'pidfile=s'      => \$opt_pidfile,
    'accept=i'       => \$accept,
    'wakeup=i'       => \$wakeup,
    'wakeup-delay=f' => \$wakeup_delay,
    'version|V'      => sub {
        print "Gearman::Server $Gearman::Server::VERSION$/";
        exit;
    },
    'help|?' => sub {
        pod2usage(-verbose => 1);
        exit;
    },

    # for test suite only.
    'notifypid|n=i' => \$notify_pid,
);

daemonize() if $daemonize;

# true if we've closed listening socket, and we're waiting for a
# convenient place to kill the process
our $graceful_shutdown = 0;

# handled manually
$SIG{'PIPE'} = "IGNORE";
my $server = Gearman::Server->new(
    wakeup       => $wakeup,
    wakeup_delay => $wakeup_delay,
);
my $ssock = $server->create_listening_sock(
    $conf_port,
    accept_per_loop => $accept,
    local_addr      => $conf_host
);

if ($opt_pidfile) {
    open my $fh, '>', $opt_pidfile or die "Could not open $opt_pidfile: $!";
    print $fh "$$\n";
    close $fh;
}

sub shutdown_graceful {
    return if $graceful_shutdown;

    my $ofds = Danga::Socket->OtherFds;
    delete $ofds->{ fileno($ssock) };
    $ssock->close;
    $graceful_shutdown = 1;
    shutdown_if_calm();
} ## end sub shutdown_graceful

sub shutdown_if_calm {



( run in 2.508 seconds using v1.01-cache-2.11-cpan-8f98c5d2c55 )