changeset 217:4e1e5e621b84

Add shutdown hook to close db when killing agent process reviewed-by: vanaltj review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-April/000717.html
author Mario Torre <neugens.limasoftware@gmail.com>
date Wed, 11 Apr 2012 19:42:15 +0200
parents c87e8cb1f864
children 6fb6e9890e67
files tools/src/main/java/com/redhat/thermostat/tools/ThermostatService.java
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tools/src/main/java/com/redhat/thermostat/tools/ThermostatService.java	Wed Apr 11 16:31:42 2012 +0200
+++ b/tools/src/main/java/com/redhat/thermostat/tools/ThermostatService.java	Wed Apr 11 19:42:15 2012 +0200
@@ -112,6 +112,16 @@
             // we are only interested in starting the agent if
             // we started the database ourselves
             case START:
+                
+                // set a shutdown hook if the db was started by us
+                Runtime.getRuntime().addShutdownHook(new Thread() {
+                    @Override
+                    public void run() {
+                        String[] args = new String[] { "storage", "--stop" };
+                        Thermostat.main(args);
+                    }
+                });
+                
                 String dbUrl = database.getConfiguration().getDBConnectionString();
                 String[] args = new String[] { "--dbUrl", dbUrl };
                 try {