.classpath | 1 modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/AbstractInstall.java | 85 ++--- modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Install.java | 165 ++++------ modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Start.java | 1 modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Upgrade.java | 51 +-- 5 files changed, 156 insertions(+), 147 deletions(-)
New commits: commit a632102141b729f6a99c330d6e3d52efae94219b Author: Jay Shaughnessy jshaughn@redhat.com Date: Thu Oct 3 11:42:44 2013 -0400
Bug 1006352 - rhqctl install should only install the server and not start it unless explicitly instructed New behavior in place. The rhqctl install and upgrade commands no longer leave the installed or upgraded services running, by default. In other words, they perform only an install or upgrade.
Each now supports a --start option which will ensure the installed or upgraded services are running when the install or upgrade complates.
Note that for the install command this applies only to service actually installed by that command invocation (i.e. install can not substitute for start).
Note that for upgrade the storage service will always be left running after upgrade if the migrate-data option is specified, to support the migration.
Note that the --agent-auto-start option has been removed from both commands since they are superseded by the --start option.
also: - fixed a recent regression in upgrade, now again aborts if it detects previously upgraded services. - trivial, removed unused imports
diff --git a/.classpath b/.classpath index dfe7c43..c40e481 100644 --- a/.classpath +++ b/.classpath @@ -396,5 +396,6 @@ <classpathentry kind="var" path="M2_REPO/org/apache/commons/commons-math3/3.1.1/commons-math3-3.1.1.jar"/> <classpathentry kind="var" path="M2_REPO/com/fasterxml/jackson/core/jackson-databind/2.1.1/jackson-databind-2.1.1.jar"/> <classpathentry kind="var" path="M2_REPO/com/fasterxml/jackson/core/jackson-core/2.1.1/jackson-core-2.1.1.jar"/> + <classpathentry kind="var" path="M2_REPO/com/codahale/metrics/metrics-core/3.0.1/metrics-core-3.0.1.jar"/> <classpathentry kind="output" path="eclipse-classes"/> </classpath> diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/AbstractInstall.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/AbstractInstall.java index aca83c6..d7c8fd5 100644 --- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/AbstractInstall.java +++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/AbstractInstall.java @@ -150,13 +150,13 @@ public abstract class AbstractInstall extends ControlCommand { long totalWait = (now - timerStart);
if (totalWait < problemMessageInterval) { - log.info("Still waiting for server to start..."); + log.info("Still waiting for server to initialize...");
} else { long minutes = totalWait / 60000; log.info("It has been over [" + minutes - + "] minutes - you may want to ensure your server startup is proceeding as expected. You can check the log at [" + + "] minutes - you may want to ensure your server initialization is proceeding as expected. You can check the log at [" + new File(getBaseDir(), "logs/server.log").getPath() + "].");
timerStart = now; @@ -202,7 +202,7 @@ public abstract class AbstractInstall extends ControlCommand { reader = new BufferedReader(new FileReader(new File(logDir, "server.log"))); String line = reader.readLine(); while (line != null) { - if (line.contains("Server started")) { + if (line.contains("Server initialized")) { return true; } line = reader.readLine(); @@ -228,51 +228,63 @@ public abstract class AbstractInstall extends ControlCommand { } }
- /** - * Same as <pre>startAgent(agentBasedir, false);</pre> - * @param agentBasedir - * @throws Exception - */ - protected void startAgent(File agentBasedir) throws Exception { - startAgent(agentBasedir, false); - } + protected void updateWindowsAgentService(final File agentBasedir) throws Exception { + if (!isWindows()) { + return; + }
- protected void startAgent(final File agentBasedir, boolean updateWindowsService) throws Exception { try { File agentBinDir = new File(agentBasedir, "bin"); if (!agentBinDir.exists()) { throw new IllegalArgumentException("No Agent found for base directory [" + agentBasedir.getPath() + "]"); }
- log.info("Starting RHQ agent..."); + log.info("Updating RHQ Agent Service..."); Executor executor = new DefaultExecutor(); executor.setWorkingDirectory(agentBinDir); executor.setStreamHandler(new PumpStreamHandler()); org.apache.commons.exec.CommandLine commandLine;
- if (isWindows() && updateWindowsService) { - // Ensure the windows service is up to date beFore starting. [re-]install the windows service. - - commandLine = getCommandLine("rhq-agent-wrapper", "stop"); - try { - executor.execute(commandLine); - } catch (Exception e) { - // Ignore, service may not exist or be running, , script returns 1 - log.debug("Failed to stop agent service", e); - } + // Ensure the windows service is up to date. [re-]install the windows service.
- commandLine = getCommandLine("rhq-agent-wrapper", "remove"); - try { - executor.execute(commandLine); - } catch (Exception e) { - // Ignore, service may not exist, script returns 1 - log.debug("Failed to uninstall agent service", e); - } + commandLine = getCommandLine("rhq-agent-wrapper", "stop"); + try { + executor.execute(commandLine); + } catch (Exception e) { + // Ignore, service may not exist or be running, , script returns 1 + log.debug("Failed to stop agent service", e); + }
- commandLine = getCommandLine("rhq-agent-wrapper", "install"); + commandLine = getCommandLine("rhq-agent-wrapper", "remove"); + try { executor.execute(commandLine); + } catch (Exception e) { + // Ignore, service may not exist, script returns 1 + log.debug("Failed to uninstall agent service", e); }
+ commandLine = getCommandLine("rhq-agent-wrapper", "install"); + executor.execute(commandLine); + + } catch (IOException e) { + log.error("An error occurred while updating the agent service: " + e.getMessage()); + throw e; + } + } + + protected void startAgent(final File agentBasedir) throws Exception { + try { + File agentBinDir = new File(agentBasedir, "bin"); + if (!agentBinDir.exists()) { + throw new IllegalArgumentException("No Agent found for base directory [" + agentBasedir.getPath() + "]"); + } + + log.info("Starting RHQ agent..."); + Executor executor = new DefaultExecutor(); + executor.setWorkingDirectory(agentBinDir); + executor.setStreamHandler(new PumpStreamHandler()); + org.apache.commons.exec.CommandLine commandLine; + // For *nix, just start the server in the background, for Win, now that the service is installed, start it commandLine = getCommandLine("rhq-agent-wrapper", "start"); executor.execute(commandLine); @@ -324,11 +336,11 @@ public abstract class AbstractInstall extends ControlCommand { } }
- protected void stopServer(File serverBasedir) throws Exception { + protected void stopServer() throws Exception {
- File serverBinDir = new File(serverBasedir, "bin/internal"); + File serverBinDir = getBinDir(); if (!serverBinDir.exists()) { - throw new IllegalArgumentException("No Server found for base directory [" + serverBasedir.getPath() + "]"); + throw new IllegalArgumentException("No Server found for base directory [" + getBaseDir().getPath() + "]"); }
log.debug("Stopping RHQ server..."); @@ -504,7 +516,8 @@ public abstract class AbstractInstall extends ControlCommand { return storageDataDirs; }
- protected int installStorageNode(final File storageBasedir, CommandLine rhqctlCommandLine) throws IOException { + protected int installStorageNode(final File storageBasedir, CommandLine rhqctlCommandLine, boolean start) + throws IOException { try { log.info("Preparing to install RHQ storage node.");
@@ -513,7 +526,7 @@ public abstract class AbstractInstall extends ControlCommand { final Properties storageProperties = loadStorageProperties();
org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-storage-installer", "--dir", - storageBasedir.getAbsolutePath()); + storageBasedir.getAbsolutePath(), "--start", Boolean.valueOf(start).toString());
if (rhqctlCommandLine.hasOption(STORAGE_DATA_ROOT_DIR)) { StorageDataDirectories dataDirs; diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Install.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Install.java index 88ec433..48e840a 100644 --- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Install.java +++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Install.java @@ -54,7 +54,7 @@ public class Install extends AbstractInstall {
private final String AGENT_CONFIG_OPTION = "agent-config"; private final String AGENT_PREFERENCE = "agent-preference"; - private final String AGENT_AUTOSTART_OPTION = "agent-auto-start"; + private final String START_OPTION = "start";
private Options options;
@@ -88,13 +88,11 @@ public class Install extends AbstractInstall { "An agent preference setting (whose argument is in the form 'name=value') to be set in the agent. More than one of these is allowed.") .addOption( null, - AGENT_AUTOSTART_OPTION, - true, - "If an agent is to be installed it will, by default, also be started. However, if this option is set to false, the agent will not be started after it gets installed.") + START_OPTION, + false, + "If specified then immediately start the services after installation. Note that services may be started and shut down as part of the installation process, but will not be started or left running by default.") .addOption(null, STORAGE_DATA_ROOT_DIR, true, "The root directory under which all storage data directories will be placed."); - - options.getOption(AGENT_AUTOSTART_OPTION).setOptionalArg(true); }
@Override @@ -114,6 +112,10 @@ public class Install extends AbstractInstall {
@Override protected void exec(CommandLine commandLine) { + boolean start = commandLine.hasOption(START_OPTION); + boolean startedStorage = false; + boolean startedServer = false; + try { List<String> errors = validateOptions(commandLine); if (!errors.isEmpty()) { @@ -137,111 +139,92 @@ public class Install extends AbstractInstall { } });
- // if no options specified, then install whatever is not installed yet - if (!(commandLine.hasOption(STORAGE_OPTION) || commandLine.hasOption(SERVER_OPTION) || commandLine - .hasOption(AGENT_OPTION))) { - - if (!isStorageInstalled()) { - installStorageNode(getStorageBasedir(), commandLine); - } else if (isWindows()) { - installWindowsService(getBinDir(), "rhq-storage", false, true); + boolean installAll = (!(commandLine.hasOption(STORAGE_OPTION) || commandLine.hasOption(SERVER_OPTION) || commandLine + .hasOption(AGENT_OPTION))); + boolean installStorage = installAll || commandLine.hasOption(STORAGE_OPTION); + boolean installServer = installAll || commandLine.hasOption(SERVER_OPTION); + boolean installAgent = installAll || commandLine.hasOption(AGENT_OPTION) + || commandLine.hasOption(STORAGE_OPTION); + boolean startStorage = false; + + if (installStorage) { + if (isStorageInstalled()) { + log.info("The RHQ storage node is already installed in [" + new File(getBaseDir(), "storage") + + "]. It will not be installed."); + + if (isWindows()) { + log.info("Ensuring the RHQ Storage Windows service exists. Ignore any CreateService failure."); + installWindowsService(getBinDir(), "rhq-storage", false, false); + } + } else { + installStorageNode(getStorageBasedir(), commandLine, false); + startStorage = start; } + } + + if (startStorage || installServer) { + startedStorage = true; + Start startCommand = new Start(); + startCommand.exec(new String[] { "start", "--storage" }); + }
- if (!isServerInstalled()) { + if (installServer) { + if (isServerInstalled()) { + log.info("The RHQ server is already installed. It will not be installed."); + + if (isWindows()) { + log.info("Ensuring the RHQ Server Windows service exists. Ignore any CreateService failure."); + installWindowsService(getBinDir(), "rhq-server", false, false); + } + } else { + startedServer = true; startRHQServerForInstallation(); runRHQServerInstaller(); waitForRHQServerToInitialize(); - } else if (isWindows()) { - installWindowsService(getBinDir(), "rhq-server", false, true); } + }
- if (!isAgentInstalled()) { + if (installAgent) { + if (isAgentInstalled()) { + log.info("The RHQ agent is already installed in [" + getAgentBasedir() + + "]. It will not be installed."); + + if (isWindows()) { + try { + log.info("Ensuring the RHQ Agent Windows service exists. Ignore any CreateService failure."); + installWindowsService(new File(getAgentBasedir(), "bin"), "rhq-agent-wrapper", false, false); + } catch (Exception e) { + // Ignore, service may already exist or be running, wrapper script returns 1 + log.debug("Failed to stop agent service", e); + } + } + } else { clearAgentPreferences(); File agentBasedir = getAgentBasedir(); installAgent(agentBasedir); configureAgent(agentBasedir, commandLine); - boolean start = Boolean.parseBoolean(commandLine.getOptionValue(AGENT_AUTOSTART_OPTION, "true")); - if (start) { - startAgent(agentBasedir, true); - } else { - log.info("The agent was installed but was told not to start automatically."); - } - } else if (isWindows()) { - boolean start = Boolean.parseBoolean(commandLine.getOptionValue(AGENT_AUTOSTART_OPTION, "true")); - installWindowsService(new File(getAgentBasedir(), "bin"), "rhq-agent-wrapper", false, start); - }
- } else { - if (commandLine.hasOption(STORAGE_OPTION)) { - if (isStorageInstalled()) { - log.info("The RHQ storage node is already installed in " + new File(getBaseDir(), "storage")); - - if (isWindows()) { - installWindowsService(getBinDir(), "rhq-storage", false, true); - } else { - log.info("Skipping storage node installation."); - } - } else { - installStorageNode(getStorageBasedir(), commandLine); - } + updateWindowsAgentService(agentBasedir);
- if (!isAgentInstalled()) { - File agentBasedir = getAgentBasedir(); - clearAgentPreferences(); - installAgent(agentBasedir); - configureAgent(agentBasedir, commandLine); - if (Boolean.parseBoolean(commandLine.getOptionValue(AGENT_AUTOSTART_OPTION, "true"))) { - startAgent(agentBasedir, true); - } else { - log.info("The agent was installed but was told not to start automatically."); - } + if (start) { + startAgent(agentBasedir); } } + }
- if (commandLine.hasOption(SERVER_OPTION)) { - if (isServerInstalled()) { - log.warn("The RHQ server is already installed."); - - if (isWindows()) { - installWindowsService(getBinDir(), "rhq-server", false, true); - } else { - log.info("Skipping server installation."); - } + } catch (Exception e) { + throw new RHQControlException("An error occurred while executing the install command", e);
- } else { - startRHQServerForInstallation(); - runRHQServerInstaller(); - waitForRHQServerToInitialize(); - } + } finally { + if (startedStorage || startedServer) { + Stop stopCommand = new Stop(); + if (startedServer) { + stopCommand.exec(new String[] { "stop", "--server" }); } - - if (commandLine.hasOption(AGENT_OPTION)) { - if (isAgentInstalled() && !commandLine.hasOption(STORAGE_OPTION)) { - log.info("The RHQ agent is already installed in [" + getAgentBasedir() + "]"); - - boolean start = Boolean - .parseBoolean(commandLine.getOptionValue(AGENT_AUTOSTART_OPTION, "true")); - if (isWindows()) { - installWindowsService(new File(getAgentBasedir(), "bin"), "rhq-agent-wrapper", false, start); - } else { - log.info("Skipping agent installation."); - } - - } else { - File agentBasedir = getAgentBasedir(); - clearAgentPreferences(); - installAgent(agentBasedir); - configureAgent(agentBasedir, commandLine); - if (Boolean.parseBoolean(commandLine.getOptionValue(AGENT_AUTOSTART_OPTION, "true"))) { - startAgent(agentBasedir, true); - } else { - log.info("The agent was installed but was told not to start automatically."); - } - } + if (startedStorage) { + stopCommand.exec(new String[] { "stop", "--storage" }); } } - } catch (Exception e) { - throw new RHQControlException("An error occurred while executing the install command", e); } }
diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Start.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Start.java index f15b13e..5d75be4 100644 --- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Start.java +++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Start.java @@ -33,7 +33,6 @@ import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.Executor; import org.apache.commons.exec.PumpStreamHandler;
-import org.rhq.core.util.stream.StreamUtil; import org.rhq.server.control.ControlCommand; import org.rhq.server.control.RHQControlException;
diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Upgrade.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Upgrade.java index 1dc2758..c931dc6 100644 --- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Upgrade.java +++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Upgrade.java @@ -57,7 +57,7 @@ public class Upgrade extends AbstractInstall {
private static final String FROM_AGENT_DIR_OPTION = "from-agent-dir"; private static final String FROM_SERVER_DIR_OPTION = "from-server-dir"; - private static final String AGENT_AUTOSTART_OPTION = "agent-auto-start"; + private static final String START_OPTION = "start"; private static final String USE_REMOTE_STORAGE_NODE = "use-remote-storage-node"; private static final String STORAGE_DATA_ROOT_DIR = "storage-data-root-dir"; private static final String RUN_DATA_MIGRATION = "run-data-migrator"; @@ -76,10 +76,9 @@ public class Upgrade extends AbstractInstall { "Full path to install directory of the RHQ Server to be upgraded. Required.") .addOption( null, - AGENT_AUTOSTART_OPTION, - true, - "If an agent is to be upgraded it will, by default, also be started. However, if this option is set to " - + "false, the agent will not be started after it gets upgraded.") + START_OPTION, + false, + "If specified then immediately start the services after upgrade. Note that services may be started and shut down as part of the upgrade process, but will not be started or left running by default.") .addOption( null, USE_REMOTE_STORAGE_NODE, @@ -102,8 +101,6 @@ public class Upgrade extends AbstractInstall { + "to have fine control over the process, please run the migrator on the command line. Options are none (do " + "nothing), estimate (estimate the migration time only), print-command (print the command line for a manual run), " + "do-it (run the migration)"); - - options.getOption(AGENT_AUTOSTART_OPTION).setOptionalArg(true); }
@Override @@ -123,6 +120,8 @@ public class Upgrade extends AbstractInstall {
@Override protected void exec(CommandLine commandLine) { + boolean start = commandLine.hasOption(START_OPTION); + try { List<String> errors = validateOptions(commandLine); if (!errors.isEmpty()) { @@ -148,7 +147,7 @@ public class Upgrade extends AbstractInstall { // if the agent already exists in the default location, it may be there from a prior install. if (isStorageInstalled() || isServerInstalled()) { log.warn("RHQ is already installed so upgrade can not be performed."); - //return; + return; }
// Stop the agent, if running. @@ -187,26 +186,40 @@ public class Upgrade extends AbstractInstall { } });
- // now upgrade everything and start them up again + // now upgrade everything upgradeStorage(commandLine); upgradeServer(commandLine); upgradeAgent(commandLine);
- if (!Boolean.parseBoolean(commandLine.getOptionValue(AGENT_AUTOSTART_OPTION, "true"))) { - log.info("The agent was upgraded but was told not to start automatically."); + File agentDir; + + if (commandLine.hasOption(FROM_AGENT_DIR_OPTION)) { + agentDir = new File(commandLine.getOptionValue(FROM_AGENT_DIR_OPTION)); } else { - File agentDir; + agentDir = getAgentBasedir(); + }
- if (commandLine.hasOption(FROM_AGENT_DIR_OPTION)) { - agentDir = new File(commandLine.getOptionValue(FROM_AGENT_DIR_OPTION)); - } else { - agentDir = getAgentBasedir(); - } - startAgent(agentDir, true); + updateWindowsAgentService(agentDir); + + if (start) { + startAgent(agentDir); } } catch (Exception e) { throw new RHQControlException("An error occurred while executing the upgrade command", e); + } finally { + try { + if (!start) { + Stop stopCommand = new Stop(); + stopCommand.exec(new String[] { "stop", "--server" }); + if (!commandLine.hasOption(RUN_DATA_MIGRATION)) { + stopCommand.exec(new String[] { "stop", "--storage" }); + } + } + } catch (Throwable t) { + log.warn("Unable to stop services: " + t.getMessage()); + } } + if (!isRhq48OrLater(commandLine) && commandLine.hasOption(RUN_DATA_MIGRATION)) { runDataMigration(commandLine); } @@ -279,7 +292,7 @@ public class Upgrade extends AbstractInstall { }
} else { - installStorageNode(getStorageBasedir(), rhqctlCommandLine); + installStorageNode(getStorageBasedir(), rhqctlCommandLine, true); } }
rhq-commits@lists.fedorahosted.org