[pve-devel] [PATCH cluster v3 04/14] use run_command instead of system

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Dec 19 12:52:29 CET 2017


perls system wants to open /dev/tty which is not available in forked
workers. Use our run_command instead.
---

new in v3

 data/PVE/Cluster.pm | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index 2dc616c..fc173af 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -11,7 +11,7 @@ use MIME::Base64;
 use Digest::SHA;
 use Digest::HMAC_SHA1;
 use Net::SSLeay;
-use PVE::Tools;
+use PVE::Tools qw(run_command);
 use PVE::INotify;
 use PVE::IPCC;
 use PVE::SafeSyslog;
@@ -1695,7 +1695,7 @@ sub assert_joinable {
 	}
     };
 
-    if (!$param->{force}) {
+    if (!$force) {
 
 	if (-f $authfile) {
 	    $error->("authentication key '$authfile' already exists", $force);
@@ -1710,7 +1710,7 @@ sub assert_joinable {
 	    $error->("this host already contains virtual guests", $force);
 	}
 
-	if (system("corosync-quorumtool -l >/dev/null 2>&1") == 0) {
+	if (run_command(['corosync-quorumtool', '-l'], noerr => 1, quiet => 1) == 0) {
 	    $error->("corosync is already running, is this node already in a cluster?!", $force);
 	}
     }
@@ -1781,15 +1781,14 @@ sub finish_join {
     PVE::Tools::file_set_contents($localclusterconf, $corosync_conf);
 
     print "stopping pve-cluster service\n";
-
-    system("umount $basedir -f >/dev/null 2>&1");
-    die "can't stop pve-cluster service\n" if system("systemctl stop pve-cluster") != 0;
+    my $cmd = ['systemctl', 'stop', 'pve-cluster'];
+    run_command($cmd, errmsg => "can't stop pve-cluster service");
 
     $backup_cfs_database->($dbfile);
     unlink $dbfile;
 
-    system("systemctl start pve-cluster") == 0 || die "starting pve-cluster failed\n";
-    system("systemctl start corosync");
+    $cmd = ['systemctl', 'start', 'corosync', 'pve-cluster'];
+    run_command($cmd, errmsg => "starting pve-cluster failed");
 
     # wait for quorum
     my $printqmsg = 1;
@@ -1811,9 +1810,8 @@ sub finish_join {
     print "merge known_hosts file\n";
     PVE::Cluster::ssh_merge_known_hosts($nodename, $local_ip_address, 1);
 
-    print "restart services\n";
-    # restart pvedaemon and pveproxy (changed certs)
-    system("systemctl restart pvedaemon pveproxy");
+    print "node certificate changed, restart pveproxy and pvedaemon services\n";
+    run_command(['systemctl', 'reload-or-restart', 'pvedaemon', 'pveproxy']);
 
     print "successfully added node '$nodename' to cluster.\n";
 }
-- 
2.11.0





More information about the pve-devel mailing list