Ideally what you would do is set a tag with a known key, such as OwningJenkinsUrl to the Jenkins root URL.
Then a periodic task would run every 15-20 minutes in Jenkins that iterates through all the EC2 resources tagged with that key:value pair. Then use the https://wiki.jenkins-ci.org/display/JENKINS/Node+Iterator+API+Plugin to iterate through all the nodes attached to your Jenkins instance (including those that are not actually defined as Nodes... which is the real purpose of this API... e.g. if somebody has a trick way of turning a slave into a resource, they should be using the Node Iterator API to let people still find it as a slave even if jenkins doesn't see it as such)... any nodes that are not active on Jenkins can be killed. That would give you a nice safe tidy-up of runaway nodes... at least once Jenkins comes back up. On 29 January 2014 14:10, David V <dvena...@allogy.com> wrote: > Hey Kevin. Thanks for your help. What I actually do now is terminate all > my EC2 slaves when we shut down. Now, if an uncontrolled shutdown occurs, > we might lose our slaves again. > > For anybody you comes along with a similar problem, here is the script we > run: > > import jenkins.model.* > jenkins = Jenkins.instance; > for (slave in jenkins.slaves.findAll({s -> s instanceof > hudson.plugins.ec2.EC2OndemandSlave})) { > slave.terminate() > } > > David > > On Thursday, January 23, 2014 8:44:19 AM UTC-6, Kevin Fleming wrote: > >> I think making the EC2Slave.stop() method public would be fine, it should >> be safe enough to call from outside the object itself. At least it's not >> any less safe than most of the existing code in the plugin, which has a >> large number of concurrency issues already :-) >> >> ----- Original Message ----- >> From: jenkins...@googlegroups.com >> To: jenkins...@googlegroups.com >> Cc: Kevin Fleming (BLOOMBERG/ 731 LEXIN) >> At: Jan 21 2014 15:00:01 >> >> What do you think about exposing the stop() method? I found it in the >> source on GitHub, but I've only just begun to take a look at the source >> code for this project. >> >> void stop() { >> try { >> AmazonEC2 ec2 = getCloud().connect(); >> StopInstancesRequest request = new StopInstancesRequest( >> Collections.singletonList(getInstanceId())); >> ec2.stopInstances(request); >> LOGGER.info("EC2 instance stopped: " + getInstanceId()); >> toComputer().disconnect(null); >> } catch (AmazonClientException e) { >> Instance i = getInstance(getInstanceId(), getCloud()); >> LOGGER.log(Level.WARNING, "Failed to terminate EC2 instance: >> "+getInstanceId() + " info: "+((i != null)?i:"") , e); >> } >> } >> >> -- >> 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. >> >> -- > 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-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > -- 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-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.