portable setting of proctitle
This commit is contained in:
@@ -3,7 +3,7 @@ package App::Netdisco::Daemon::Worker::Common;
|
||||
use Dancer qw/:moose :syntax :script/;
|
||||
|
||||
use Try::Tiny;
|
||||
use Sys::Proctitle 'setproctitle';
|
||||
use App::Netdisco::Util::Daemon;
|
||||
|
||||
use Role::Tiny;
|
||||
use namespace::clean;
|
||||
@@ -18,7 +18,7 @@ sub worker_body {
|
||||
my $type = $self->worker_type;
|
||||
|
||||
while (1) {
|
||||
setproctitle sprintf 'netdisco-daemon: worker #%s %s: idle', $wid, lc($type);
|
||||
prctl sprintf 'netdisco-daemon: worker #%s %s: idle', $wid, lc($type);
|
||||
my $jobs = jq_take($self->wid, $type);
|
||||
|
||||
foreach my $job (@$jobs) {
|
||||
@@ -26,7 +26,7 @@ sub worker_body {
|
||||
|
||||
try {
|
||||
$job->started(scalar localtime);
|
||||
setproctitle sprintf 'netdisco-daemon: worker #%s %s: working on #%s: %s',
|
||||
prctl 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",
|
||||
$wid, $target, $job->id, $job->started;
|
||||
@@ -51,7 +51,7 @@ sub close_job {
|
||||
my $type = $self->worker_type;
|
||||
my $now = scalar localtime;
|
||||
|
||||
setproctitle sprintf 'netdisco-daemon: worker #%s %s: wrapping up %s #%s: %s',
|
||||
prctl 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",
|
||||
$self->wid, $job->action, $job->id, $job->status, $now;
|
||||
|
||||
@@ -3,7 +3,7 @@ package App::Netdisco::Daemon::Worker::Manager;
|
||||
use Dancer qw/:moose :syntax :script/;
|
||||
|
||||
use List::Util 'sum';
|
||||
use Sys::Proctitle 'setproctitle';
|
||||
use App::Netdisco::Util::Daemon;
|
||||
|
||||
use Role::Tiny;
|
||||
use namespace::clean;
|
||||
@@ -42,7 +42,7 @@ sub worker_body {
|
||||
|
||||
while (1) {
|
||||
debug "mgr ($wid): getting potential jobs for $num_slots workers";
|
||||
setproctitle sprintf 'netdisco-daemon: worker #%s manager: gathering', $wid;
|
||||
prctl sprintf 'netdisco-daemon: worker #%s manager: gathering', $wid;
|
||||
|
||||
# get some pending jobs
|
||||
# TODO also check for stale jobs in Netdisco DB
|
||||
@@ -65,7 +65,7 @@ sub worker_body {
|
||||
}
|
||||
|
||||
debug "mgr ($wid): sleeping now...";
|
||||
setproctitle sprintf 'netdisco-daemon: worker #%s manager: idle', $wid;
|
||||
prctl sprintf 'netdisco-daemon: worker #%s manager: idle', $wid;
|
||||
sleep( setting('workers')->{sleep_time} || 2 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package App::Netdisco::Daemon::Worker::Scheduler;
|
||||
use Dancer qw/:moose :syntax :script/;
|
||||
|
||||
use Algorithm::Cron;
|
||||
use Sys::Proctitle 'setproctitle';
|
||||
use App::Netdisco::Util::Daemon;
|
||||
|
||||
use Role::Tiny;
|
||||
use namespace::clean;
|
||||
@@ -38,11 +38,11 @@ sub worker_body {
|
||||
# sleep until some point in the next minute
|
||||
my $naptime = 60 - (time % 60) + int(rand(45));
|
||||
|
||||
setproctitle sprintf 'netdisco-daemon: worker #%s scheduler: idle', $wid;
|
||||
prctl sprintf 'netdisco-daemon: worker #%s scheduler: idle', $wid;
|
||||
debug "sched ($wid): sleeping for $naptime seconds";
|
||||
|
||||
sleep $naptime;
|
||||
setproctitle sprintf 'netdisco-daemon: worker #%s scheduler: queueing', $wid;
|
||||
prctl sprintf 'netdisco-daemon: worker #%s scheduler: queueing', $wid;
|
||||
|
||||
# NB next_time() returns the next *after* win_start
|
||||
my $win_start = time - (time % 60) - 1;
|
||||
|
||||
21
Netdisco/lib/App/Netdisco/Util/Daemon.pm
Normal file
21
Netdisco/lib/App/Netdisco/Util/Daemon.pm
Normal file
@@ -0,0 +1,21 @@
|
||||
package App::Netdisco::Util::Daemon;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Module::Load ();
|
||||
eval { Module::Load::load 'Sys::Proctitle' };
|
||||
|
||||
use base 'Exporter';
|
||||
our @EXPORT = 'prctl';
|
||||
|
||||
sub prctl {
|
||||
if ($^O eq 'linux') {
|
||||
Sys::Proctitle::setproctitle(shift);
|
||||
}
|
||||
else {
|
||||
$0 = shift;
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user