Process tree updated to show daemon worker status/activity
Squashed commit of the following: commita785b88b43Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Aug 6 21:32:11 2014 +0100 complete daemon pstree updates commitf77bf5361fMerge:f519410fcb8195Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Aug 6 20:45:22 2014 +0100 Merge branch 'master' into og-proctitle commitf51941076fAuthor: Oliver Gorwits <oliver@cpan.org> Date: Tue Aug 5 22:14:58 2014 +0100 set proctitle on daemon
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
* Attempt to keep PID and logfile as netdisco user even when running as root
|
* Attempt to keep PID and logfile as netdisco user even when running as root
|
||||||
* Show netdisco-do docs on options error
|
* Show netdisco-do docs on options error
|
||||||
* Do not leak SNMP community string into debug output (unless SHOW_COMMUNITY=1)
|
* Do not leak SNMP community string into debug output (unless SHOW_COMMUNITY=1)
|
||||||
|
* Process tree updated to show daemon worker status/activity
|
||||||
|
|
||||||
[BUG FIXES]
|
[BUG FIXES]
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ Daemon::Control->new({
|
|||||||
|
|
||||||
sub restarter {
|
sub restarter {
|
||||||
my ($daemon, @program_args) = @_;
|
my ($daemon, @program_args) = @_;
|
||||||
|
$0 = 'netdisco-daemon';
|
||||||
|
|
||||||
my $child = fork_and_start($daemon, @program_args);
|
my $child = fork_and_start($daemon, @program_args);
|
||||||
exit(1) unless $child;
|
exit(1) unless $child;
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ use NetAddr::IP::Lite ':lower';
|
|||||||
use List::Util 'sum';
|
use List::Util 'sum';
|
||||||
use Role::Tiny::With;
|
use Role::Tiny::With;
|
||||||
use MCE::Signal '-setpgrp';
|
use MCE::Signal '-setpgrp';
|
||||||
setpgrp(0,0); # only portable variety of setpgrp
|
|
||||||
use MCE;
|
use MCE;
|
||||||
|
|
||||||
# set temporary MCE files' location in home directory
|
# set temporary MCE files' location in home directory
|
||||||
@@ -37,6 +36,9 @@ my $home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
|
|||||||
my $tmp_dir = ($ENV{NETDISCO_TEMP} || dir($home, 'tmp'));
|
my $tmp_dir = ($ENV{NETDISCO_TEMP} || dir($home, 'tmp'));
|
||||||
mkdir $tmp_dir if ! -d $tmp_dir;
|
mkdir $tmp_dir if ! -d $tmp_dir;
|
||||||
|
|
||||||
|
setpgrp(0,0); # only portable variety of setpgrp
|
||||||
|
$0 = 'netdisco-daemon: master';
|
||||||
|
|
||||||
my $mce = MCE->new(
|
my $mce = MCE->new(
|
||||||
spawn_delay => 0.15,
|
spawn_delay => 0.15,
|
||||||
job_delay => 1.15,
|
job_delay => 1.15,
|
||||||
@@ -92,6 +94,7 @@ sub worker_factory {
|
|||||||
return sub {
|
return sub {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $wid = $self->wid;
|
my $wid = $self->wid;
|
||||||
|
$0 = sprintf 'netdisco-daemon: worker #%s %s: init', $wid, lc($role);
|
||||||
info "applying role $role to worker $wid";
|
info "applying role $role to worker $wid";
|
||||||
|
|
||||||
# $self->sendto('stderr', ">>> worker $wid starting with role $role\n");
|
# $self->sendto('stderr', ">>> worker $wid starting with role $role\n");
|
||||||
|
|||||||
@@ -56,6 +56,23 @@ __PACKAGE__->set_primary_key("job");
|
|||||||
|
|
||||||
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
# You can replace this text with custom code or comments, and it will be preserved on regeneration
|
||||||
|
|
||||||
|
=head1 METHODS
|
||||||
|
|
||||||
|
=head2 summary
|
||||||
|
|
||||||
|
An attempt to make a meaningful statement about the job.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub summary {
|
||||||
|
my $job = shift;
|
||||||
|
return join ' ',
|
||||||
|
$job->action,
|
||||||
|
($job->device || ''),
|
||||||
|
($job->port || ''),
|
||||||
|
($job->subaction ? (q{'}. $job->subaction .q{'}) : '');
|
||||||
|
}
|
||||||
|
|
||||||
=head1 ADDITIONAL COLUMNS
|
=head1 ADDITIONAL COLUMNS
|
||||||
|
|
||||||
=head2 entererd_stamp
|
=head2 entererd_stamp
|
||||||
|
|||||||
@@ -44,8 +44,44 @@ __PACKAGE__->add_columns(
|
|||||||
|
|
||||||
__PACKAGE__->set_primary_key("job");
|
__PACKAGE__->set_primary_key("job");
|
||||||
|
|
||||||
|
=head1 METHODS
|
||||||
|
|
||||||
|
=head2 summary
|
||||||
|
|
||||||
|
An attempt to make a meaningful statement about the job.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub summary {
|
||||||
|
my $job = shift;
|
||||||
|
return join ' ',
|
||||||
|
$job->action,
|
||||||
|
($job->device || ''),
|
||||||
|
($job->port || ''),
|
||||||
|
($job->subaction ? (q{'}. $job->subaction .q{'}) : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
=head1 ADDITIONAL COLUMNS
|
||||||
|
|
||||||
|
=head2 extra
|
||||||
|
|
||||||
|
Alias for the C<subaction> column.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
sub extra { (shift)->subaction }
|
sub extra { (shift)->subaction }
|
||||||
|
|
||||||
|
=head2 entererd_stamp
|
||||||
|
|
||||||
|
Formatted version of the C<entered> field, accurate to the minute.
|
||||||
|
|
||||||
|
The format is somewhat like ISO 8601 or RFC3339 but without the middle C<T>
|
||||||
|
between the date stamp and time stamp. That is:
|
||||||
|
|
||||||
|
2012-02-06 12:49
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
sub entered_stamp {
|
sub entered_stamp {
|
||||||
(my $stamp = (shift)->entered) =~ s/\.\d+$//;
|
(my $stamp = (shift)->entered) =~ s/\.\d+$//;
|
||||||
return $stamp;
|
return $stamp;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ sub worker_body {
|
|||||||
my $type = $self->worker_type;
|
my $type = $self->worker_type;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
$0 = sprintf 'netdisco-daemon: worker #%s %s: idle', $wid, lc($type);
|
||||||
my $jobs = jq_take($self->wid, $type);
|
my $jobs = jq_take($self->wid, $type);
|
||||||
|
|
||||||
foreach my $job (@$jobs) {
|
foreach my $job (@$jobs) {
|
||||||
@@ -23,6 +24,8 @@ sub worker_body {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$job->started(scalar localtime);
|
$job->started(scalar localtime);
|
||||||
|
$0 = sprintf 'netdisco-daemon: worker #%s %s: working on #%s: %s',
|
||||||
|
$wid, lc($type), $job->id, $job->summary;
|
||||||
info sprintf "$tag (%s): starting %s job(%s) at %s",
|
info sprintf "$tag (%s): starting %s job(%s) at %s",
|
||||||
$wid, $target, $job->id, $job->started;
|
$wid, $target, $job->id, $job->started;
|
||||||
my ($status, $log) = $self->$target($job);
|
my ($status, $log) = $self->$target($job);
|
||||||
@@ -42,9 +45,12 @@ sub worker_body {
|
|||||||
|
|
||||||
sub close_job {
|
sub close_job {
|
||||||
my ($self, $job) = @_;
|
my ($self, $job) = @_;
|
||||||
my $tag = $self->worker_tag;
|
my $tag = $self->worker_tag;
|
||||||
my $now = scalar localtime;
|
my $type = $self->worker_type;
|
||||||
|
my $now = scalar localtime;
|
||||||
|
|
||||||
|
$0 = sprintf 'netdisco-daemon: worker #%s %s: wrapping up %s #%s: %s',
|
||||||
|
$self->wid, lc($type), $job->action, $job->id, $job->status;
|
||||||
info sprintf "$tag (%s): wrapping up %s job(%s) - status %s at %s",
|
info sprintf "$tag (%s): wrapping up %s job(%s) - status %s at %s",
|
||||||
$self->wid, $job->action, $job->id, $job->status, $now;
|
$self->wid, $job->action, $job->id, $job->status, $now;
|
||||||
|
|
||||||
|
|||||||
@@ -11,18 +11,19 @@ use App::Netdisco::JobQueue qw/jq_locked jq_getsome jq_lock/;
|
|||||||
sub worker_begin {
|
sub worker_begin {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $wid = $self->wid;
|
my $wid = $self->wid;
|
||||||
debug "entering Manager ($wid) worker_begin()";
|
|
||||||
|
|
||||||
if (setting('workers')->{'no_manager'}) {
|
return debug "mgr ($wid): no need for manager... skip begin"
|
||||||
return debug "mgr ($wid): no need for manager... skip begin";
|
if setting('workers')->{'no_manager'};
|
||||||
}
|
|
||||||
|
debug "entering Manager ($wid) worker_begin()";
|
||||||
|
|
||||||
# requeue jobs locally
|
# requeue jobs locally
|
||||||
debug "mgr ($wid): searching for jobs booked to this processing node";
|
debug "mgr ($wid): searching for jobs booked to this processing node";
|
||||||
my @jobs = jq_locked;
|
my @jobs = jq_locked;
|
||||||
|
|
||||||
if (scalar @jobs) {
|
if (scalar @jobs) {
|
||||||
info sprintf "mgr (%s): found %s jobs booked to this processing node", $wid, scalar @jobs;
|
info sprintf "mgr (%s): found %s jobs booked to this processing node",
|
||||||
|
$wid, scalar @jobs;
|
||||||
$self->do('add_jobs', @jobs);
|
$self->do('add_jobs', @jobs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,6 +40,7 @@ sub worker_body {
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
debug "mgr ($wid): getting potential jobs for $num_slots workers";
|
debug "mgr ($wid): getting potential jobs for $num_slots workers";
|
||||||
|
$0 = sprintf 'netdisco-daemon: worker #%s manager: gathering', $wid;
|
||||||
|
|
||||||
# get some pending jobs
|
# get some pending jobs
|
||||||
# TODO also check for stale jobs in Netdisco DB
|
# TODO also check for stale jobs in Netdisco DB
|
||||||
@@ -47,6 +49,7 @@ sub worker_body {
|
|||||||
# check for available local capacity
|
# check for available local capacity
|
||||||
my $job_type = setting('job_types')->{$job->action};
|
my $job_type = setting('job_types')->{$job->action};
|
||||||
next unless $job_type and $self->do('capacity_for', $job_type);
|
next unless $job_type and $self->do('capacity_for', $job_type);
|
||||||
|
|
||||||
debug sprintf "mgr (%s): processing node has capacity for job %s (%s)",
|
debug sprintf "mgr (%s): processing node has capacity for job %s (%s)",
|
||||||
$wid, $job->id, $job->action;
|
$wid, $job->id, $job->action;
|
||||||
|
|
||||||
@@ -60,6 +63,7 @@ sub worker_body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
debug "mgr ($wid): sleeping now...";
|
debug "mgr ($wid): sleeping now...";
|
||||||
|
$0 = sprintf 'netdisco-daemon: worker #%s manager: idle', $wid;
|
||||||
sleep( setting('workers')->{sleep_time} || 2 );
|
sleep( setting('workers')->{sleep_time} || 2 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,12 @@ sub worker_body {
|
|||||||
while (1) {
|
while (1) {
|
||||||
# sleep until some point in the next minute
|
# sleep until some point in the next minute
|
||||||
my $naptime = 60 - (time % 60) + int(rand(45));
|
my $naptime = 60 - (time % 60) + int(rand(45));
|
||||||
|
|
||||||
|
$0 = sprintf 'netdisco-daemon: worker #%s scheduler: idle', $wid;
|
||||||
debug "sched ($wid): sleeping for $naptime seconds";
|
debug "sched ($wid): sleeping for $naptime seconds";
|
||||||
|
|
||||||
sleep $naptime;
|
sleep $naptime;
|
||||||
|
$0 = sprintf 'netdisco-daemon: worker #%s scheduler: queueing', $wid;
|
||||||
|
|
||||||
# NB next_time() returns the next *after* win_start
|
# NB next_time() returns the next *after* win_start
|
||||||
my $win_start = time - (time % 60) - 1;
|
my $win_start = time - (time % 60) - 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user