rename *-daemon apps to be *-backend
Squashed commit of the following: commit39b438aa4bAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:40:11 2017 +0100 add release notes commitca4ea90d35Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:32:06 2017 +0100 update distmeta commit4e35b904b0Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:30:22 2017 +0100 rename files from Daemon to Backend commit86a605ba68Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:26:43 2017 +0100 rename daemon to backend in code commitffe8fc180fAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 16:15:57 2017 +0100 add daemon files which exec to backend equivalents commit53e041594eAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 6 15:32:49 2017 +0100 rename netdisco-daemon to netdisco-backend
This commit is contained in:
109
bin/netdisco-backend-fg
Executable file
109
bin/netdisco-backend-fg
Executable file
@@ -0,0 +1,109 @@
|
||||
#!/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::Backend;
|
||||
use NetAddr::IP::Lite ':lower'; # to quench AF_INET6 symbol errors
|
||||
use Role::Tiny::With;
|
||||
|
||||
# preload all worker modules into shared memory
|
||||
use App::Netdisco::Backend::Job ();
|
||||
use App::Netdisco::Backend::Util ();
|
||||
use App::Netdisco::Backend::Worker::Common ();
|
||||
use App::Netdisco::Backend::Worker::Interactive::DeviceActions ();
|
||||
use App::Netdisco::Backend::Worker::Interactive::PortActions ();
|
||||
use App::Netdisco::Backend::Worker::Manager ();
|
||||
use App::Netdisco::Backend::Worker::Poller::Arpnip ();
|
||||
use App::Netdisco::Backend::Worker::Poller::Common ();
|
||||
use App::Netdisco::Backend::Worker::Poller::Device ();
|
||||
use App::Netdisco::Backend::Worker::Poller::Expiry ();
|
||||
use App::Netdisco::Backend::Worker::Poller::Macsuck ();
|
||||
use App::Netdisco::Backend::Worker::Poller::Nbtstat ();
|
||||
use App::Netdisco::Backend::Worker::Poller ();
|
||||
use App::Netdisco::Backend::Worker::Scheduler ();
|
||||
|
||||
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;
|
||||
|
||||
# process-table text
|
||||
prctl 'netdisco-backend: 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::Util has a limit of ncpu if AUTO is used in max_workers,
|
||||
# so we parse the field ourselves.
|
||||
my $max_workers = parse_max_workers( setting('workers')->{tasks} ) || 0;
|
||||
|
||||
mce_flow {
|
||||
task_name => [qw/ scheduler manager poller /],
|
||||
max_workers => [ 1, 1, $max_workers ],
|
||||
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-backend: 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::Backend::Worker::$role");
|
||||
|
||||
$self->worker_begin if $self->can('worker_begin');
|
||||
$self->worker_body;
|
||||
};
|
||||
}
|
||||
|
||||
=head1 NAME
|
||||
|
||||
netdisco-backend-fg - Job Control for Netdisco
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
L<App::Netdisco>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
Reference in New Issue
Block a user