"Soft" stopping of slaves

247 views
Skip to first unread message

Steffen Breitbach

unread,
May 17, 2013, 7:36:30 AM5/17/13
to jenkins...@googlegroups.com
Hi everyone!

I'd like to prevent our slaves from processing tasks in a given
timeframe to have system ressources free for other tasks (e.g. backup
tasks).

I don't want to shutdown the slaves, I'd rather make them stop
processing jobs and then enable them some time later, much like the
"safe shutdown" for Jenkins itself does.

I thought I might have seen a plug-in that could do the job but I don't
seem to be able to find it any more.

A groovy script might do the job as well, but I couldn't find an example
anywhere.

Do you have any ideas how I might do this?!

Thanks in advance

Steffen

Mandeville, Rob

unread,
May 17, 2013, 8:02:40 AM5/17/13
to jenkins...@googlegroups.com
I have a similar problem, where I need to run maintenance jobs on machines with multiple nodes. I installed the Scriptler plugin and wrote these two scripts; one to disable all nodes on a given label (which lets them finish their current tasks but prevents them from taking on more jobs) and wait for them to finish (you may not need the last part), and the other to enable all nodes on that label. These scripts must be run as Scriptler jobs that are bound to the master node (so that they are in the same address space as the server).

--Rob Mandeville

---BEGIN LABEL SHUTDOWN SCRIPT---
import hudson.model.Hudson
import jenkins.model.Jenkins
import hudson.model.Computer

println "Passed in label $labelName."

label = Jenkins.instance.getLabel(labelName)
if(!label){
println("Could not find label $labelName")
}else{
nodes = label.getNodes()
for(node in nodes){
nodeName = node.getNodeName()
println("Node $nodeName is part of label $labelName")
}
}

nodeToComputer = new HashMap<Node, Computer>()
for(node in nodes){
computer = node.toComputer()
if(null == computer){
println("NO COMPUTER for node $nodeName")
}else{
nodeToComputer.put(node, computer)
}
}

for(node in nodes){
nodeName = node.getNodeName()
computer = nodeToComputer.get(node)

println("We have a computer for node $nodeName")
if(computer.isTemporarilyOffline()){
reason = computer.getOfflineCause()
println("Node $nodeName is already offline: $reason");
}else{
computer.setTemporarilyOffline(true)
println("Node $nodeName is set for offline.")
}
}

for(node in nodes){
nodeName = node.getNodeName()
computer = nodeToComputer.get(node)
print("Waiting for node $nodeName to finish...")
computer.waitUntilOffline()
while(computer.countBusy() != 0){
sleep(1000)
}
println("done");
}

---END LABEL SHUTDOWN SCRIPT---

---BEGIN LABEL STARTUP SCRIPT--
import hudson.model.Hudson
import jenkins.model.Jenkins
import hudson.model.Computer

println "Passed in label $labelName."

label = Jenkins.instance.getLabel(labelName)
if(!label){
println("Could not find label $labelName")
}else{
nodes = label.getNodes()
for(node in nodes){
nodeName = node.getNodeName()
println("Node $nodeName is part of label $labelName")
}
}

nodeToComputer = new HashMap<Node, Computer>()
for(node in nodes){
computer = node.toComputer()
if(null == computer){
println("NO COMPUTER for node $nodeName")
}else{
nodeToComputer.put(node, computer)
}
}

for(node in nodes){
nodeName = node.getNodeName()
computer = nodeToComputer.get(node)

println("We have a computer for node $nodeName")
if(computer.isTemporarilyOffline()){
computer.setTemporarilyOffline(false)
println("Setting Node $nodeName to online");
}else{
println("Node $nodeName is already online.")
}
}

for(node in nodes){
nodeName = node.getNodeName()
computer = nodeToComputer.get(node)
print("Waiting for node $nodeName to finish...")
computer.waitUntilOnline()
println("done");
}

---END LABEL STARTUP SCRIPT---
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


The information in this message is for the intended recipient(s) only and may be the proprietary and/or confidential property of Litle & Co., LLC, and thus protected from disclosure. If you are not the intended recipient(s), or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any use, dissemination, distribution or copying of this communication is prohibited. If you have received this communication in error, please notify Litle & Co. immediately by replying to this message and then promptly deleting it and your reply permanently from your computer.

ogondza

unread,
May 17, 2013, 8:03:14 AM5/17/13
to Steffen Breitbach, jenkins...@googlegroups.com
You can take the save offline for your timeframe. Jobs that are running
will complete but no new jobs will be scheduled before explicitly taken
back online.

Is this what you want?

--
oliver
Reply all
Reply to author
Forward
0 new messages