From: Dirk Koopman Date: Thu, 18 Aug 2016 17:34:39 +0000 (+0100) Subject: fix backgrounding of mrtg X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?p=spider.git;a=commitdiff_plain;h=8634689f5dcb3d2ab2b748aeb9d8401a0889a443 fix backgrounding of mrtg and new cron commands: spawn_cmd which will background any dxspider cmd --- diff --git a/cmd/mrtg.pl b/cmd/mrtg.pl index db2d2e11..466d6113 100644 --- a/cmd/mrtg.pl +++ b/cmd/mrtg.pl @@ -32,6 +32,8 @@ sub handle { my ($self, $line) = @_; + + $DB::single = 1; # create the arg list my %want; @@ -40,7 +42,7 @@ sub handle return (1, "MRTG not installed") unless $want{nomrtg} || -e '/usr/bin/mrtg' || -e '/usr/local/bin/mrtg'; - my @out = $self->spawn_cmd("mrtg $line", \&do_it, args=>[%want]); + my @out = do_it(%want); return (1, @out); } diff --git a/perl/DXCron.pm b/perl/DXCron.pm index f9a4f07e..757ec61c 100644 --- a/perl/DXCron.pm +++ b/perl/DXCron.pm @@ -263,6 +263,29 @@ sub spawn ); } +sub spawn_cmd +{ + my $line = shift; + + dbg("spawn_cmd run: $line") if isdbg('cron'); + my $fc = Mojo::IOLoop::ForkCall->new; + $fc->run( + sub {my @res = DXCommandmode::run_cmd($main::me, $line); return @res}, + [], + sub { + my ($fc, $err, @res) = @_; + if (defined $err) { + my $s = "spawn_cmd: error $err"; + dbg($s); + } + for (@res) { + chomp; + dbg("spawn_cmd: $_") if isdbg("cron"); + } + } + ); +} + # do an rcmd to another cluster from the crontab sub rcmd {