[pve-devel] [PATCH] PVE:Daemon start/restart with systemd

Alen Grizonic a.grizonic at proxmox.com
Tue Jun 16 15:11:33 CEST 2015


Added some lines which make it possible to start/restart daemons with 
pve scripts,
avoiding the problem of systemd not recognizing the new status of the 
(re)started services.


diff --git a/src/PVE/Daemon.pm b/src/PVE/Daemon.pm
index e051500..16e08c9 100644
--- a/src/PVE/Daemon.pm
@@ -578,6 +578,16 @@ my $read_pid = sub {
      return $pid;
  };

+my $init_ppid = sub {
+    my $ppid = getppid();
+
+    if ($ppid == 1) {
+       return 1;
+    } else {
+       return 0;
+    }
+};
+
  sub running {
      my ($self) = @_;

@@ -654,7 +664,11 @@ sub register_start_command {
         code => sub {
             my ($param) = @_;

-           $self->start($param->{debug});
+            if (&$init_ppid()) {
+                $self->start($param->{debug});
+            } else {
+                PVE::Tools::run_command(['systemctl', 'start', 
$self->{name}]);
+            }

             return undef;
         }});
@@ -666,7 +680,7 @@ my $reload_daemon = sub {
      if ($self->{env_restart_pve_daemon}) {
         $self->start();
      } else {
-       my ($running, $pid) = $self->running();
+       my ($running, $pid) = $self->running();
         if (!$running) {
             $self->start();
         } else {
@@ -700,8 +714,23 @@ sub register_restart_command {
         code => sub {
             my ($param) = @_;

-           &$reload_daemon($self, $use_hup);
-
+           if (&$init_ppid()) {
+               &$reload_daemon($self, $use_hup);
+            } else {
+               my ($running, $pid) = $self->running();
+               if (!$running) {
+                   PVE::Tools::run_command(['systemctl', 'start', 
$self->{name}]);
+               } else {
+                   if ($use_hup) {
+                       syslog('info', "send HUP to $pid");
+                       kill 1, $pid;
+                       PVE::Tools::run_command(['systemctl', 'start', 
$self->{name}]);
+                   } else {
+                       PVE::Tools::run_command(['systemctl', 'restart', 
$self->{name}]);
+                   }
+               }
+           }
+
             return undef;
         }});
  }





More information about the pve-devel mailing list