From 8634689f5dcb3d2ab2b748aeb9d8401a0889a443 Mon Sep 17 00:00:00 2001
From: Dirk Koopman <djk@tobit.co.uk>
Date: Thu, 18 Aug 2016 18:34:39 +0100
Subject: [PATCH] fix backgrounding of mrtg

and new cron commands: spawn_cmd which will background any dxspider cmd
---
 cmd/mrtg.pl    |  4 +++-
 perl/DXCron.pm | 23 +++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

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
 {
-- 
2.43.0