Mercurial > hg > release > thermostat-1.2
changeset 650:46e6a130d0e7
Handle SIGTERM in addition to SIGINT in agent.
This patch is a fix for PR1179 where the agent did not cleanly shut down on a
regular termination request (SIGTERM). It now shuts down in the same way as
on CTRL+C.
Reviewed-by: omajid
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-September/003466.html
author | Severin Gehwolf <sgehwolf@redhat.com> |
---|---|
date | Fri, 28 Sep 2012 15:23:01 +0200 |
parents | 424a8a822bff |
children | 24606d0665fd |
files | agent/cli/src/main/java/com/redhat/thermostat/agent/cli/AgentApplication.java |
diffstat | 1 files changed, 29 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/AgentApplication.java Fri Sep 28 11:35:11 2012 -0400 +++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/AgentApplication.java Fri Sep 28 15:23:01 2012 +0200 @@ -180,15 +180,11 @@ logger.fine("Agent id: " + agent.getId()); final CountDownLatch shutdownLatch = new CountDownLatch(1); - Signal.handle(new Signal("INT"), new SignalHandler() { - public void handle(sun.misc.Signal sig) { - configServer.stopListening(); - agent.stop(); - logger.fine("Agent stopped."); - shutdownLatch.countDown(); - } - }); + SignalHandler handler = new CustomSignalHandler(agent, configServer, logger, shutdownLatch); + Signal.handle(new Signal("INT"), handler); + Signal.handle(new Signal("TERM"), handler); try { + // Wait for either SIGINT or SIGTERM shutdownLatch.await(); logger.fine("terminating agent cmd"); } catch (InterruptedException e) { @@ -248,5 +244,30 @@ public Collection<ArgumentSpec> getAcceptedArguments() { return AgentOptionParser.getAcceptedArguments(); } + + // Does not need a reference of the enclosing type so lets declare this class static + private static class CustomSignalHandler implements SignalHandler { + + private Agent agent; + private ConfigurationServer configServer; + private Logger logger; + private CountDownLatch shutdownLatch; + + CustomSignalHandler(Agent agent, ConfigurationServer configServer, Logger logger, CountDownLatch latch) { + this.agent = agent; + this.configServer = configServer; + this.logger = logger; + this.shutdownLatch = latch; + } + + @Override + public void handle(Signal arg0) { + configServer.stopListening(); + agent.stop(); + logger.fine("Agent stopped."); + shutdownLatch.countDown(); + } + + } }