changeset 898:5a2d3c43b551

Remove stale mongo PID file and start storage. I can't think of a reason why removing a stale pid file and starting mongo afterwards would do us any harm. Previously thermostat was refusing to start storage if a stale pid file was present. This makes integration tests consistently fail on mongodb 2.2.2. Seems to be a bug in mongodb 2.2.2. Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-January/005040.html
author Severin Gehwolf <sgehwolf@redhat.com>
date Tue, 08 Jan 2013 19:22:32 +0100
parents 72638d2844fa
children 40be72a1345c
files agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/MongoProcessRunner.java agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/StalePidFileException.java agent/cli/src/main/resources/com/redhat/thermostat/agent/cli/impl/strings.properties
diffstat 3 files changed, 11 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/MongoProcessRunner.java	Tue Jan 08 10:39:19 2013 -0500
+++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/MongoProcessRunner.java	Tue Jan 08 19:22:32 2013 +0100
@@ -140,17 +140,21 @@
         String pid = getPid();
         if (pid != null) {
             String message = null;
-            ApplicationException ex = null;
             if (!checkExistingProcess()) {
                 message = translator.localize(LocaleResources.STALE_PID_FILE_NO_MATCHING_PROCESS, configuration.getPidFile().toString(), MONGO_PROCESS);
-                ex = new StalePidFileException(configuration.getPidFile());
+                // Mongo didn't remove its PID file? Work around the issue. Log
+                // the event, remove the stale pid file and continue.
+                logger.log(Level.WARNING, message);
+                try {
+                    Files.delete(configuration.getPidFile().toPath());
+                } catch (IOException benign) {
+                    // ignore this benign error
+                }
             } else {
                 message = translator.localize(LocaleResources.STORAGE_ALREADY_RUNNING_WITH_PID, String.valueOf(pid));
-                ex = new StorageAlreadyRunningException(Integer.valueOf(pid), message);
+                display(message);
+                throw new StorageAlreadyRunningException(Integer.valueOf(pid), message);
             }
-            
-            display(message);
-            throw ex;
         }
         
         List<String> commands = new ArrayList<>(Arrays.asList(MONGO_BASIC_ARGS));
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/db/StalePidFileException.java	Tue Jan 08 10:39:19 2013 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc.
- *
- * This file is part of Thermostat.
- *
- * Thermostat is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- *
- * Thermostat is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Thermostat; see the file COPYING.  If not see
- * <http://www.gnu.org/licenses/>.
- *
- * Linking this code with other modules is making a combined work
- * based on this code.  Thus, the terms and conditions of the GNU
- * General Public License cover the whole combination.
- *
- * As a special exception, the copyright holders of this code give
- * you permission to link this code with independent modules to
- * produce an executable, regardless of the license terms of these
- * independent modules, and to copy and distribute the resulting
- * executable under terms of your choice, provided that you also
- * meet, for each linked independent module, the terms and conditions
- * of the license of that module.  An independent module is a module
- * which is not derived from or based on this code.  If you modify
- * this code, you may extend this exception to your version of the
- * library, but you are not obligated to do so.  If you do not wish
- * to do so, delete this exception statement from your version.
- */
-package com.redhat.thermostat.agent.cli.db;
-
-import java.io.File;
-
-import com.redhat.thermostat.agent.cli.impl.locale.LocaleResources;
-import com.redhat.thermostat.common.locale.Translate;
-import com.redhat.thermostat.common.tools.ApplicationException;
-
-public class StalePidFileException extends ApplicationException {
-
-    private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer();
-
-    private final File pidFile;
-
-    public StalePidFileException(File pidFile) {
-        super(translator.localize(LocaleResources.STALE_PID_FILE, pidFile.toString()));
-        this.pidFile = pidFile;
-    }
-
-    public File getPidFile() {
-        return pidFile;
-    }
-
-}
--- a/agent/cli/src/main/resources/com/redhat/thermostat/agent/cli/impl/strings.properties	Tue Jan 08 10:39:19 2013 -0500
+++ b/agent/cli/src/main/resources/com/redhat/thermostat/agent/cli/impl/strings.properties	Tue Jan 08 19:22:32 2013 +0100
@@ -10,7 +10,7 @@
 CANNOT_START_SERVER = cannot start server {0}, exit status: {1}. Please check that your configuration is valid
 CANNOT_SHUTDOWN_SERVER = cannot shutdown server {0}, exit status: {1}. Please check that your configuration is valid
 STALE_PID_FILE = stale pid file: {0}
-STALE_PID_FILE_NO_MATCHING_PROCESS = A stale pid file ({0}) is present but there is no matching {1} process. Please remove the file if it has been shut down
+STALE_PID_FILE_NO_MATCHING_PROCESS = A stale pid file ({0}) is present but there is no matching {1} process. Removing stale pid file.
 STARTING_STORAGE_SERVER = starting storage server...
 CANNOT_EXECUTE_PROCESS = can not execute {0} process. is it installed?
 SERVER_LISTENING_ON = server listening on ip: {0}