Squashed commit of the following: commit3284b62509Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 21:17:06 2014 +0100 config defaults tidying commitade7bcd880Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 20:00:01 2014 +0100 high priority jobs are picked first and inserted to prio queue commitd450dfd2bdAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 19:25:21 2014 +0100 better status commitb8a742e5deAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 16:54:03 2014 +0100 update proctitle when worker not running commit0c3675a8f4Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 16:48:58 2014 +0100 remove all trace of SQLite - new lightweight Job object commita13ed25f6aAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 14:45:22 2014 +0100 rename pollers to tasks commit44b50f413fAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 14:13:00 2014 +0100 update docs commit517b1ae4c1Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 13:55:31 2014 +0100 merge interactive and poller worker types commite9043b90e8Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 13:47:41 2014 +0100 only take one job at a time per worker commit2366738d54Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 13:43:31 2014 +0100 auto job priorities commit1fd473fd50Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 13:18:59 2014 +0100 preload all worker modules into shared memory commit9ceb43c0f7Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 13:13:07 2014 +0100 daemon clean commitc817a35537Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Aug 10 12:36:24 2014 +0100 first refactor for MCE::Flow and MCE::Queue
94 lines
2.1 KiB
Perl
Executable File
94 lines
2.1 KiB
Perl
Executable File
#!/usr/bin/env perl
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use FindBin;
|
|
FindBin::again();
|
|
use Path::Class 'dir';
|
|
|
|
# get a segfault if we load this later
|
|
use if $^O eq 'linux', 'Sys::Proctitle';
|
|
|
|
BEGIN {
|
|
# stuff useful locations into @INC
|
|
unshift @INC,
|
|
dir($FindBin::RealBin)->parent->subdir('lib')->stringify,
|
|
dir($FindBin::RealBin, 'lib')->stringify;
|
|
|
|
unshift @INC,
|
|
split m/:/, ($ENV{NETDISCO_INC} || '');
|
|
}
|
|
|
|
use App::Netdisco;
|
|
use Dancer qw/:moose :script/;
|
|
warning sprintf "App::Netdisco %s backend", ($App::Netdisco::VERSION || 'HEAD');
|
|
|
|
use App::Netdisco::Util::Daemon;
|
|
use NetAddr::IP::Lite ':lower'; # to quench AF_INET6 symbol errors
|
|
use Role::Tiny::With;
|
|
|
|
# preload all worker modules into shared memory
|
|
use Module::Find ();
|
|
Module::Find::useall 'App::Netdisco::Daemon';
|
|
|
|
use MCE::Signal '-setpgrp';
|
|
use MCE::Flow Sereal => 1;
|
|
use MCE::Queue;
|
|
|
|
# set temporary MCE files' location in home directory
|
|
my $home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
|
|
my $tmp_dir = ($ENV{NETDISCO_TEMP} || dir($home, 'tmp'));
|
|
mkdir $tmp_dir if ! -d $tmp_dir;
|
|
|
|
setpgrp(0,0); # only portable variety of setpgrp
|
|
prctl 'netdisco-daemon: master';
|
|
|
|
# shared local job queue
|
|
my $queue = MCE::Queue->new;
|
|
|
|
# support a scheduler-only node
|
|
setting('workers')->{'no_manager'} = 1
|
|
if setting('workers')->{tasks} eq '0';
|
|
|
|
mce_flow {
|
|
task_name => [qw/ scheduler manager poller /],
|
|
max_workers => [ 1, 1, setting('workers')->{tasks} ],
|
|
tmp_dir => $tmp_dir,
|
|
on_post_exit => sub { MCE->restart_worker },
|
|
}, _mk_wkr('Scheduler'), _mk_wkr('Manager'), _mk_wkr('Poller');
|
|
|
|
sub _mk_wkr {
|
|
my $role = shift;
|
|
return sub {
|
|
my $self = shift;
|
|
$self->{queue} = $queue;
|
|
|
|
prctl sprintf 'netdisco-daemon: worker #%s %s: init', MCE->wid, lc($role);
|
|
info sprintf 'applying role %s to worker %s', $role, MCE->wid;
|
|
|
|
# post-fork, become manager, scheduler, poller, etc
|
|
Role::Tiny->apply_roles_to_object(
|
|
$self => "App::Netdisco::Daemon::Worker::$role");
|
|
|
|
$self->worker_begin if $self->can('worker_begin');
|
|
$self->worker_body;
|
|
};
|
|
}
|
|
|
|
=head1 NAME
|
|
|
|
netdisco-daemon-fg - Job Control for Netdisco
|
|
|
|
=head1 SEE ALSO
|
|
|
|
=over 4
|
|
|
|
=item *
|
|
|
|
L<App::Netdisco>
|
|
|
|
=back
|
|
|
|
=cut
|