Commit aeacfe40 authored by Dietmar Maurer's avatar Dietmar Maurer

use backgroud tasks for service actions

parent 72a74d5d
...@@ -705,13 +705,9 @@ __PACKAGE__->register_method({ ...@@ -705,13 +705,9 @@ __PACKAGE__->register_method({
my $cmd = ['vzctl', 'start', $vmid]; my $cmd = ['vzctl', 'start', $vmid];
PVE::Tools::run_command($cmd); PVE::Tools::run_command($cmd);
return;
}; };
my $upid = $rpcenv->fork_worker('vzstart', $vmid, $user, $realcmd); return $rpcenv->fork_worker('vzstart', $vmid, $user, $realcmd);
return $upid;
}}); }});
__PACKAGE__->register_method({ __PACKAGE__->register_method({
......
...@@ -25,9 +25,16 @@ my $service_list = { ...@@ -25,9 +25,16 @@ my $service_list = {
cron => { name => 'CRON', desc => 'Daemon to execute scheduled commands' }, cron => { name => 'CRON', desc => 'Daemon to execute scheduled commands' },
pvedaemon => { name => 'NodeManager', desc => 'PVE node manager daemon' }, pvedaemon => { name => 'NodeManager', desc => 'PVE node manager daemon' },
corosync => { name => 'CMan', desc => 'CMan/Corosync cluster daemon' }, corosync => { name => 'CMan', desc => 'CMan/Corosync cluster daemon' },
clvm => { name => 'CLVM', desc => 'LVM cluster locking daemon' },
pvecluster => { name => 'PVECluster', desc => 'Proxmox VE cluster file system' }, pvecluster => { name => 'PVECluster', desc => 'Proxmox VE cluster file system' },
}; };
my $service_prop_desc = {
description => "Service ID",
type => 'string',
enum => [ keys %{$service_list} ],
};
my $service_cmd = sub { my $service_cmd = sub {
my ($service, $cmd) = @_; my ($service, $cmd) = @_;
...@@ -36,8 +43,6 @@ my $service_cmd = sub { ...@@ -36,8 +43,6 @@ my $service_cmd = sub {
die "unknown service command '$cmd'\n" die "unknown service command '$cmd'\n"
if $cmd !~ m/^(start|stop|restart|reload)$/; if $cmd !~ m/^(start|stop|restart|reload)$/;
$cmd = $1; # untaint
if ($service eq 'postfix') { if ($service eq 'postfix') {
$initd_cmd = '/etc/init.d/postfix'; $initd_cmd = '/etc/init.d/postfix';
} elsif ($service eq 'pvecluster') { } elsif ($service eq 'pvecluster') {
...@@ -54,6 +59,7 @@ my $service_cmd = sub { ...@@ -54,6 +59,7 @@ my $service_cmd = sub {
} }
} elsif ($service eq 'apache') { } elsif ($service eq 'apache') {
if ($cmd eq 'restart') { if ($cmd eq 'restart') {
print "graceful apache restart\n";
$initd_cmd = '/usr/sbin/apache2ctl'; $initd_cmd = '/usr/sbin/apache2ctl';
$cmd = 'graceful'; $cmd = 'graceful';
} else { } else {
...@@ -80,8 +86,11 @@ my $service_cmd = sub { ...@@ -80,8 +86,11 @@ my $service_cmd = sub {
} elsif ($service eq 'cron') { } elsif ($service eq 'cron') {
$initd_cmd = '/etc/init.d/cron'; $initd_cmd = '/etc/init.d/cron';
} elsif ($service eq 'corosync') { } elsif ($service eq 'corosync') {
$cmd = 'start' if $cmd eq 'restart';
$initd_cmd = '/etc/init.d/cman'; $initd_cmd = '/etc/init.d/cman';
} elsif ($service eq 'sshd') { } elsif ($service eq 'clvm') {
$initd_cmd = '/etc/init.d/clvm';
} elsif ($service eq 'sshd') {
$initd_cmd = '/etc/init.d/ssh'; $initd_cmd = '/etc/init.d/ssh';
} else { } else {
die "unknown service '$service': ERROR"; die "unknown service '$service': ERROR";
...@@ -111,6 +120,8 @@ my $service_state = sub { ...@@ -111,6 +120,8 @@ my $service_state = sub {
$pid_file = '/var/run/crond.pid'; $pid_file = '/var/run/crond.pid';
} elsif ($service eq 'corosync') { } elsif ($service eq 'corosync') {
$pid_file = '/var/run/corosync.pid'; $pid_file = '/var/run/corosync.pid';
} elsif ($service eq 'clvm') {
$pid_file = '/var/run/clvmd.pid';
} elsif ($service eq 'syslog') { } elsif ($service eq 'syslog') {
$pid_file = '/var/run/rsyslogd.pid'; $pid_file = '/var/run/rsyslogd.pid';
} else { } else {
...@@ -174,10 +185,46 @@ __PACKAGE__->register_method ({ ...@@ -174,10 +185,46 @@ __PACKAGE__->register_method ({
return $res; return $res;
}}); }});
__PACKAGE__->register_method ({ __PACKAGE__->register_method({
name => 'state', name => 'srvcmdidx',
path => '{service}', path => '{service}',
method => 'GET', method => 'GET',
description => "Directory index",
parameters => {
additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
service => $service_prop_desc,
},
},
returns => {
type => 'array',
items => {
type => "object",
properties => {
subdir => { type => 'string' },
},
},
links => [ { rel => 'child', href => "{subdir}" } ],
},
code => sub {
my ($param) = @_;
my $res = [
{ subdir => 'state' },
{ subdir => 'start' },
{ subdir => 'stop' },
{ subdir => 'restart' },
{ subdir => 'reload' },
];
return $res;
}});
__PACKAGE__->register_method ({
name => 'service_state',
path => '{service}/state',
method => 'GET',
permissions => { permissions => {
path => '/nodes/{node}', path => '/nodes/{node}',
privs => [ 'Sys.Audit' ], privs => [ 'Sys.Audit' ],
...@@ -189,11 +236,7 @@ __PACKAGE__->register_method ({ ...@@ -189,11 +236,7 @@ __PACKAGE__->register_method ({
additionalProperties => 0, additionalProperties => 0,
properties => { properties => {
node => get_standard_option('pve-node'), node => get_standard_option('pve-node'),
service => { service => $service_prop_desc,
description => "Service ID",
type => 'string',
enum => [ keys %{$service_list} ],
},
}, },
}, },
returns => { returns => {
...@@ -213,34 +256,153 @@ __PACKAGE__->register_method ({ ...@@ -213,34 +256,153 @@ __PACKAGE__->register_method ({
}}); }});
__PACKAGE__->register_method ({ __PACKAGE__->register_method ({
name => 'cmd', name => 'service_start',
path => '{service}', path => '{service}/start',
method => 'PUT', method => 'POST',
description => "Execute service commands.", description => "Start service.",
proxyto => 'node', proxyto => 'node',
protected => 1, protected => 1,
parameters => { parameters => {
additionalProperties => 0, additionalProperties => 0,
properties => { properties => {
node => get_standard_option('pve-node'), node => get_standard_option('pve-node'),
service => { service => $service_prop_desc,
description => "Service ID", },
type => 'string', },
enum => [ keys %{$service_list} ], returns => {
}, type => 'string',
command => { },
description => "The command to execute. The only valid command for service 'apache' and 'pvedaemon' is 'restart', because both services are required by this API.", code => sub {
type => 'string', my ($param) = @_;
enum => [qw(start stop restart reload)],
}, my $rpcenv = PVE::RPCEnvironment::get();
my $user = $rpcenv->get_user();
my $si = $service_list->{$param->{service}};
my $realcmd = sub {
my $upid = shift;
syslog('info', "starting service $param->{service}: $upid\n");
&$service_cmd($param->{service}, 'start');
};
return $rpcenv->fork_worker('srvstart', $param->{service}, $user, $realcmd);
}});
__PACKAGE__->register_method ({
name => 'service_stop',
path => '{service}/stop',
method => 'POST',
description => "Stop service.",
proxyto => 'node',
protected => 1,
parameters => {
additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
service => $service_prop_desc,
},
},
returns => {
type => 'string',
},
code => sub {
my ($param) = @_;
my $rpcenv = PVE::RPCEnvironment::get();
my $user = $rpcenv->get_user();
my $si = $service_list->{$param->{service}};
my $realcmd = sub {
my $upid = shift;
syslog('info', "stoping service $param->{service}: $upid\n");
&$service_cmd($param->{service}, 'stop');
};
return $rpcenv->fork_worker('srvstop', $param->{service}, $user, $realcmd);
}});
__PACKAGE__->register_method ({
name => 'service_restart',
path => '{service}/restart',
method => 'POST',
description => "Restart service.",
proxyto => 'node',
protected => 1,
parameters => {
additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
service => $service_prop_desc,
}, },
}, },
returns => { type => 'null'}, returns => {
type => 'string',
},
code => sub { code => sub {
my ($param) = @_; my ($param) = @_;
my $rpcenv = PVE::RPCEnvironment::get();
my $user = $rpcenv->get_user();
my $si = $service_list->{$param->{service}}; my $si = $service_list->{$param->{service}};
&$service_cmd($param->{service}, $param->{command});
return undef; my $realcmd = sub {
my $upid = shift;
syslog('info', "re-starting service $param->{service}: $upid\n");
&$service_cmd($param->{service}, 'restart');
};
return $rpcenv->fork_worker('srvrestart', $param->{service}, $user, $realcmd);
}});
__PACKAGE__->register_method ({
name => 'service_reload',
path => '{service}/reload',
method => 'POST',
description => "Reload service.",
proxyto => 'node',
protected => 1,
parameters => {
additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
service => $service_prop_desc,
},
},
returns => {
type => 'string',
},
code => sub {
my ($param) = @_;
my $rpcenv = PVE::RPCEnvironment::get();
my $user = $rpcenv->get_user();
my $si = $service_list->{$param->{service}};
my $realcmd = sub {
my $upid = shift;
syslog('info', "reloading service $param->{service}: $upid\n");
&$service_cmd($param->{service}, 'reload');
};
return $rpcenv->fork_worker('srvreload', $param->{service}, $user, $realcmd);
}}); }});
...@@ -27,15 +27,20 @@ Ext.define('PVE.node.ServiceView', { ...@@ -27,15 +27,20 @@ Ext.define('PVE.node.ServiceView', {
var sm = me.getSelectionModel(); var sm = me.getSelectionModel();
var rec = sm.getSelection()[0]; var rec = sm.getSelection()[0];
PVE.Utils.API2Request({ PVE.Utils.API2Request({
url: "/nodes/" + nodename + "/services/" + rec.data.service, url: "/nodes/" + nodename + "/services/" + rec.data.service + "/" + cmd,
params: { command: cmd }, method: 'POST',
method: 'PUT',
failure: function(response, opts) { failure: function(response, opts) {
Ext.Msg.alert('Error', response.htmlStatus); Ext.Msg.alert('Error', response.htmlStatus);
me.loading = true; me.loading = true;
}, },
success: function(response, opts) { success: function(response, opts) {
rstore.startUpdate(); rstore.startUpdate();
var upid = response.result.data;
var win = Ext.create('PVE.window.TaskViewer', {
upid: upid
});
win.show();
} }
}); });
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment