$haenv->log('err', "crm command error - no such service: $cmd");
}
+ } elsif ($cmd =~ m/^stop\s+(\S+)\s+(\S+)$/) {
+ my ($sid, $timeout) = ($1, $2);
+ if (my $sd = $ss->{$sid}) {
+ $haenv->log('info', "got crm command: $cmd");
+ $ss->{$sid}->{cmd} = [ 'stop', $timeout ];
+ } else {
+ $haenv->log('err', "crm command error - no such service: $cmd");
+ }
} else {
$haenv->log('err', "unable to parse crm command: $cmd");
}
}
if ($sd->{cmd}) {
- my ($cmd, $target) = @{$sd->{cmd}};
- delete $sd->{cmd};
+ my $cmd = shift @{$sd->{cmd}};
if ($cmd eq 'migrate' || $cmd eq 'relocate') {
+ my $target = shift @{$sd->{cmd}};
if (!$ns->node_is_online($target)) {
$haenv->log('err', "ignore service '$sid' $cmd request - node '$target' not online");
} elsif ($sd->{node} eq $target) {
target => $target);
return;
}
+ } elsif ($cmd eq 'stop') {
+ $haenv->log('info', "ignore service '$sid' $cmd request - service already stopped");
} else {
$haenv->log('err', "unknown command '$cmd' for service '$sid'");
}
+ delete $sd->{cmd};
}
if ($cd->{state} eq 'disabled') {
if ($cd->{state} eq 'started') {
if ($sd->{cmd}) {
- my ($cmd, $target) = @{$sd->{cmd}};
- delete $sd->{cmd};
+ my $cmd = shift @{$sd->{cmd}};
if ($cmd eq 'migrate' || $cmd eq 'relocate') {
+ my $target = shift @{$sd->{cmd}};
if (!$ns->node_is_online($target)) {
$haenv->log('err', "ignore service '$sid' $cmd request - node '$target' not online");
} elsif ($sd->{node} eq $target) {
$haenv->log('info', "$cmd service '$sid' to node '$target'");
&$change_service_state($self, $sid, $cmd, node => $sd->{node}, target => $target);
}
+ } elsif ($cmd eq 'stop') {
+ my $timeout = shift @{$sd->{cmd}};
+ $haenv->log('info', "$cmd service with timeout '$timeout'");
+ &$change_service_state($self, $sid, 'request_stop', timeout => $timeout);
+ $haenv->update_service_config($sid, {'state' => 'stopped'});
} else {
$haenv->log('err', "unknown command '$cmd' for service '$sid'");
}
+
+ delete $sd->{cmd};
+
} else {
my $try_next = 0;
# restart-lrm <node>
# service <sid> <started|disabled|stopped|ignored>
# service <sid> <migrate|relocate> <target>
+# service <sid> stop <timeout>
# service <sid> lock/unlock [lockname]
sub sim_hardware_cmd {
$self->queue_crm_commands_nolock("$action $sid $param");
+ } elsif ($action eq 'stop') {
+
+ die "sim_hardware_cmd: missing timeout for '$action' command"
+ if !defined($param);
+
+ $self->queue_crm_commands_nolock("$action $sid $param");
+
} elsif ($action eq 'add') {
$self->add_service($sid, {state => 'started', node => $param});
--- /dev/null
+Test the stop command with different timeouts
+and what happens with a failed service.
--- /dev/null
+[
+ [ "power node1 on", "power node2 on", "power node3 on" ],
+ [ "service vm:101 stop 0" ],
+ [ "service vm:101 stop 1" ],
+ [ "service vm:102 stop 37" ],
+ [ "service vm:103 stop 60" ],
+ [ "service fa:1001 stop 0" ]
+]
--- /dev/null
+{
+ "node1": { "power": "off", "network": "off" },
+ "node2": { "power": "off", "network": "off" },
+ "node3": { "power": "off", "network": "off" }
+}
--- /dev/null
+info 0 hardware: starting simulation
+info 20 cmdlist: execute power node1 on
+info 20 node1/crm: status change startup => wait_for_quorum
+info 20 node1/lrm: status change startup => wait_for_agent_lock
+info 20 cmdlist: execute power node2 on
+info 20 node2/crm: status change startup => wait_for_quorum
+info 20 node2/lrm: status change startup => wait_for_agent_lock
+info 20 cmdlist: execute power node3 on
+info 20 node3/crm: status change startup => wait_for_quorum
+info 20 node3/lrm: status change startup => wait_for_agent_lock
+info 20 node1/crm: got lock 'ha_manager_lock'
+info 20 node1/crm: status change wait_for_quorum => master
+info 20 node1/crm: node 'node1': state changed from 'unknown' => 'online'
+info 20 node1/crm: node 'node2': state changed from 'unknown' => 'online'
+info 20 node1/crm: node 'node3': state changed from 'unknown' => 'online'
+info 20 node1/crm: adding new service 'fa:1001' on node 'node3'
+info 20 node1/crm: adding new service 'vm:101' on node 'node1'
+info 20 node1/crm: adding new service 'vm:102' on node 'node2'
+info 20 node1/crm: adding new service 'vm:103' on node 'node3'
+info 21 node1/lrm: got lock 'ha_agent_node1_lock'
+info 21 node1/lrm: status change wait_for_agent_lock => active
+info 21 node1/lrm: starting service vm:101
+info 21 node1/lrm: service status vm:101 started
+info 22 node2/crm: status change wait_for_quorum => slave
+info 23 node2/lrm: got lock 'ha_agent_node2_lock'
+info 23 node2/lrm: status change wait_for_agent_lock => active
+info 23 node2/lrm: starting service vm:102
+info 23 node2/lrm: service status vm:102 started
+info 24 node3/crm: status change wait_for_quorum => slave
+info 25 node3/lrm: got lock 'ha_agent_node3_lock'
+info 25 node3/lrm: status change wait_for_agent_lock => active
+info 25 node3/lrm: starting service fa:1001
+info 25 node3/lrm: service status fa:1001 started
+info 25 node3/lrm: starting service vm:103
+info 25 node3/lrm: service status vm:103 started
+info 120 cmdlist: execute service vm:101 stop 0
+info 120 node1/crm: got crm command: stop vm:101 0
+info 120 node1/crm: stop service with timeout '0'
+info 120 node1/crm: service 'vm:101': state changed from 'started' to 'request_stop' (timeout = 0)
+info 121 node1/lrm: stopping service vm:101 (timeout=0)
+info 121 node1/lrm: service status vm:101 stopped
+info 140 node1/crm: service 'vm:101': state changed from 'request_stop' to 'stopped'
+info 220 cmdlist: execute service vm:101 stop 1
+info 220 node1/crm: got crm command: stop vm:101 1
+info 220 node1/crm: ignore service 'vm:101' stop request - service already stopped
+info 320 cmdlist: execute service vm:102 stop 37
+info 320 node1/crm: got crm command: stop vm:102 37
+info 320 node1/crm: stop service with timeout '37'
+info 320 node1/crm: service 'vm:102': state changed from 'started' to 'request_stop' (timeout = 37)
+info 323 node2/lrm: stopping service vm:102 (timeout=37)
+info 323 node2/lrm: service status vm:102 stopped
+info 340 node1/crm: service 'vm:102': state changed from 'request_stop' to 'stopped'
+info 420 cmdlist: execute service vm:103 stop 60
+info 420 node1/crm: got crm command: stop vm:103 60
+info 420 node1/crm: stop service with timeout '60'
+info 420 node1/crm: service 'vm:103': state changed from 'started' to 'request_stop' (timeout = 60)
+info 425 node3/lrm: stopping service vm:103 (timeout=60)
+info 425 node3/lrm: service status vm:103 stopped
+info 440 node1/crm: service 'vm:103': state changed from 'request_stop' to 'stopped'
+info 520 cmdlist: execute service fa:1001 stop 0
+info 520 node1/crm: got crm command: stop fa:1001 0
+info 520 node1/crm: stop service with timeout '0'
+info 520 node1/crm: service 'fa:1001': state changed from 'started' to 'request_stop' (timeout = 0)
+info 525 node3/lrm: stopping service fa:1001 (timeout=0)
+info 525 node3/lrm: unable to stop stop service fa:1001 (still running)
+err 540 node1/crm: service 'fa:1001' stop failed (exit code 1)
+info 540 node1/crm: service 'fa:1001': state changed from 'request_stop' to 'error'
+err 545 node3/lrm: service fa:1001 is in an error state and needs manual intervention. Look up 'ERROR RECOVERY' in the documentation.
+info 1120 hardware: exit simulation - done
--- /dev/null
+{}
\ No newline at end of file
--- /dev/null
+{
+ "vm:101": { "node": "node1", "state": "started" },
+ "vm:102": { "node": "node2", "state": "started" },
+ "vm:103": { "node": "node3", "state": "started" },
+ "fa:1001": { "node": "node3", "state": "started" }
+}