]> git.proxmox.com Git - pmg-api.git/commitdiff
PMG/Utils.pm: new helper service_cmd()
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 20 Feb 2017 06:18:37 +0000 (07:18 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 20 Feb 2017 06:18:37 +0000 (07:18 +0100)
PMG/Utils.pm

index c9d7150d93e6e7d856e4108e790a8526e2622e4e..5da119b5d45877175e828a3d189fa23bc786650d 100644 (file)
@@ -383,4 +383,21 @@ sub find_local_network_for_ip {
     die "unable to detect local network for ip '$ip'\n";
 }
 
+sub service_cmd {
+    my ($service, $cmd) = @_;
+
+    die "unknown service command '$cmd'\n"
+       if $cmd !~ m/^(start|stop|restart|reload)$/;
+
+    if ($service eq 'pmgdaemon' || $service eq 'pmgproxy') {
+       if ($cmd eq 'restart') {
+           # OK
+       } else {
+           die "invalid service cmd '$service $cmd': ERROR";
+       }
+    }
+
+    PVE::Tools::run_command(['systemctl', $cmd, $service]);
+};
+
 1;