Skip to content

Commit

Permalink
Merge pull request #4466 from adrianschroeter/sensysrq
Browse files Browse the repository at this point in the history
[api][backend] allow to send sysrq to running jobs for maintainers
  • Loading branch information
adrianschroeter committed Feb 8, 2018
2 parents 5de5680 + 9e34929 commit 20deb57
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 4 deletions.
11 changes: 11 additions & 0 deletions docs/api/api/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,17 @@ Parameters:
see cmd=rebuild


POST /build/<project>?cmd=sendsysrq

Send a single sysrq char to the kernel of a running build
Only a subset of debugging requests a are supported (eg. 9, t or w)

Parameters:

see cmd=rebuild
sysrq: for specifing the sysrq


POST /build/<project>?cmd=wipe

Delete all binary packages from build area
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/build_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def project_index
raise MissingParameterError, "Missing parameter 'cmd'"
end

unless ['wipe', 'restartbuild', 'killbuild', 'abortbuild', 'rebuild', 'unpublish'].include? params[:cmd]
unless ['wipe', 'restartbuild', 'killbuild', 'abortbuild', 'rebuild', 'unpublish', 'sendsysrq'].include? params[:cmd]
render_error status: 400, errorcode: 'illegal_request',
message: "unsupported POST command #{params[:cmd]} to #{request.url}"
return
Expand Down
4 changes: 4 additions & 0 deletions src/api/app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,10 @@ def abort_build(params)
backend_build_command(:abortbuild, params[:project], params.slice(:package, :arch, :repository))
end

def send_sysrq(params)
backend_build_command(:sendsysrq, params[:project], params.slice(:package, :arch, :repository, :sysrq))
end

def release_target_name
# usually used in maintenance incidents
return releasename if releasename
Expand Down
26 changes: 25 additions & 1 deletion src/backend/bs_repserver
Original file line number Diff line number Diff line change
Expand Up @@ -2684,6 +2684,13 @@ sub docommand {
}
BSUtil::ping("$eventdir/$arch/.ping") if -d "$eventdir/$arch";
}
} elsif ($cmd eq 'sendsysrq') {
for my $packid (@packids) {
eval {
sendsysrqtobuild($cgi, $projid, $repoid, $arch, $packid);
};
warn("$@") if $@;
}
} elsif ($cmd eq 'killbuild' || $cmd eq 'abortbuild') {
for my $packid (@packids) {
eval {
Expand Down Expand Up @@ -3070,6 +3077,23 @@ sub abortbuild {
return $BSStdServer::return_ok;
}

sub sendsysrqtobuild {
my ($cgi, $projid, $repoid, $arch, $packid) = @_;

my $job = findjob($projid, $repoid, $arch, $packid);
die("not building\n") unless $job;
local *F;
my $js = BSUtil::lockopenxml(\*F, '<', "$jobsdir/$arch/$job:status", $BSXML::jobstatus);
die("not building\n") if $js->{'code'} ne 'building';
my $req = {
'uri' => "$js->{'uri'}/sysrq",
'timeout' => 30,
};
die("Unsupported sysrq\n") unless $cgi->{'sysrq'} =~ /^[0123456789cltwz ]$/;

This comment has been minimized.

Copy link
@jirislaby

jirislaby Feb 9, 2018

Add 'p' please.

This comment has been minimized.

Copy link
@adrianschroeter

adrianschroeter via email Feb 9, 2018

Author Member
BSRPC::rpc($req, undef, "jobid=$js->{'jobid'}", "sysrq=$cgi->{'sysrq'}");
return $BSStdServer::return_ok;
}

#
# OBSOLETE: qemu shall be installed into the target system
# FIXME3.0: remove this
Expand Down Expand Up @@ -3934,7 +3958,7 @@ my $dispatches = [
'/configuration' => \&getconfiguration,

'/_result $prpa+ oldstate:md5? package* code:* lastbuild:bool? withbinarylist:bool? withstats:bool? summary:bool? withversrel:bool?' => \&getresult,
'POST:/_command $cmd: $prpa+ package* code:*' => \&docommand,
'POST:/_command $cmd: $prpa+ package* code:* sysrq:?' => \&docommand,

'/serverstatus' => \&BSStdServer::serverstatus,
'/ajaxstatus' => \&getajaxstatus,
Expand Down
3 changes: 2 additions & 1 deletion src/backend/bs_srcserver
Original file line number Diff line number Diff line change
Expand Up @@ -3882,6 +3882,7 @@ sub docommand {
push @args, map {"package=$_"} @packids;
push @args, map {"code=$_"} @{$cgi->{'code'} || []};
push @args, map {"wipe=$_"} @{$cgi->{'wipe'} || []};
push @args, "sysrq=$cgi->{'sysrq'}" if $cgi->{'sysrq'};
push @args, "cmd=$cgi->{'cmd'}";
my $param = {
'uri' => "$reposerver/_command",
Expand Down Expand Up @@ -6338,7 +6339,7 @@ my $dispatches = [
'PUT:/build/_dispatchprios' => \&putdispatchprios,
'/build/_dispatchprios' => \&getdispatchprios,
'/build/$project/_availablebinaries url:* path:prp* arch*' => \&getavailablebinaries,
'POST:/build/$project cmd: repository* arch* package* code:* wipe:* comment:?' => \&docommand,
'POST:/build/$project cmd: repository* arch* package* code:* wipe:* comment:? sysrq:?' => \&docommand,
'/build/$project' => \&getrepositorylist,
'/build/$project/_result oldstate:md5? view:resultview* lastbuild:bool? repository* arch* package* code:* multibuild:bool? locallink:bool?' => \&getresult,
'/build/$project/$repository' => \&getarchlist,
Expand Down
27 changes: 27 additions & 0 deletions src/backend/bs_worker
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,24 @@ sub kill_job {
return 1;
}

sub sysrq_job {
my ($sysrq) = @_;
my @args;
if ($vm =~ /(xen|kvm|zvm|emulator|pvm|openstack)/) {
push @args, '--root', "$buildroot/.mount";
push @args, '--vm-type', $vm;
push @args, '--vm-disk', $vm_root;
push @args, '--vm-swap', $vm_swap;
} else {
# can not work for for chroot and container builds
return 1;
}
if (system("$statedir/build/build", @args, "--sysrq", $sysrq)) {
return 0;
}
return 1;
}

sub wipe_all {
my @args;
if ($vm =~ /(xen|kvm|zvm|emulator|pvm|openstack)/) {
Expand Down Expand Up @@ -3263,6 +3281,14 @@ sub discardjob {
return "<status=\"ok\" />\n";
}

sub sysrqjob {
my ($cgi, $jobid) = @_;
my $state = getstate($jobid, 1);
die("could not send sysrq\n") unless sysrq_job($cgi->{'sysrq'});
BSUtil::appendstr("$buildroot/.build.log", "\n\nSend sysrq $cgi->{'sysrq'} to Job\n");
return "<status=\"ok\" />\n";
}

sub startbuild {
my ($cgi, $jobid) = @_;

Expand Down Expand Up @@ -3521,6 +3547,7 @@ my $dispatches = [
'/logfile $jobid:? nostream:? start:? end:? view:?' => \&getlogfile,
'/kill $jobid:?' => \&killjob,
'/discard $jobid:?' => \&discardjob,
'/sysrq $jobid:? sysrq:?' => \&sysrqjob,
'PUT:/build $jobid:? buildcode:? workercode:? port:? registerserver:? nobadhost:? *:?' => \&startbuild,
];

Expand Down

0 comments on commit 20deb57

Please sign in to comment.