[pve-devel] [PATCH cluster v5 06/17] use run_command instead of system

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Jan 26 14:25:16 CET 2018


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

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 data/PVE/Cluster.pm | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index afa47a7..bba7d6d 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;
@@ -1710,7 +1710,7 @@ sub assert_joinable {
 	$error->("this host already contains virtual guests");
     }
 
-    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?!");
     }
 
@@ -1782,15 +1782,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;
@@ -1812,9 +1811,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.14.2





More information about the pve-devel mailing list