]> git.proxmox.com Git - pve-manager-legacy.git/commitdiff
api/services: improve essential service check, allow reload and start
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 24 Jul 2020 11:48:42 +0000 (13:48 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 24 Jul 2020 13:24:02 +0000 (15:24 +0200)
reload is actually preferred, and even if most of the time this even
won't reach the API, allowing to start them is still definitively
fine!

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Services.pm

index a504dcd589cd4fda8f352a2006e2cf52efdd659b..e5b3c3da3b29296932363d17aa857fc9681cf036 100644 (file)
@@ -34,6 +34,11 @@ my $service_name_list = [
     'ksmtuned',
     'systemd-timesyncd',
 ];
+my $essential_services = {
+    pveproxy => 1,
+    pvedaemon => 1,
+    'pve-cluster' => 1,
+};
 
 # since postfix package 3.1.0-3.1 the postfix unit is only here to
 # manage subinstances, of which the  default is called "-".
@@ -92,17 +97,12 @@ my $service_cmd = sub {
 
     my $initd_cmd;
 
-    die "unknown service command '$cmd'\n"
-       if $cmd !~ m/^(start|stop|restart|reload)$/;
+    die "unknown service command '$cmd'\n" if $cmd !~ m/^(start|stop|restart|reload|try-reload-or-restart)$/;
 
-    if ($service eq 'pvecluster' || $service eq 'pvedaemon' || $service eq 'pveproxy') {
-       if ($cmd eq 'restart') {    
-           # OK
-       } else {
-           die "invalid service cmd '$service $cmd': ERROR";
-       }
+    if ($essential_services->{$service} && $cmd eq 'stop') {
+       die "invalid service cmd '$service $cmd': refusing to stop essential service!\n";
     }
-    
+
     PVE::Tools::run_command(['systemctl', $cmd, $service]);
 };