Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 839282 Details for
Bug 994250
rhqctl always returns exit code 0
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
Earlier patch rebased to 4.10 master.
994250-rebase-rhq410.patch (text/plain), 73.11 KB, created by
Michael Burman
on 2013-12-19 23:36:13 UTC
(
hide
)
Description:
Earlier patch rebased to 4.10 master.
Filename:
MIME Type:
Creator:
Michael Burman
Created:
2013-12-19 23:36:13 UTC
Size:
73.11 KB
patch
obsolete
>From aa43bf550a0ccb42b3e0774f9b5047e7bf3839c3 Mon Sep 17 00:00:00 2001 >From: burmanm <yak@iki.fi> >Date: Tue, 6 Aug 2013 17:52:38 +0200 >Subject: [PATCH] Fix return codes of the rhqctl command, rebased to the 4.10 > master. > >--- > .../org/rhq/server/control/ControlCommand.java | 14 ++- > .../java/org/rhq/server/control/RHQControl.java | 33 ++++-- > .../server/control/command/AbstractInstall.java | 116 +++++++++++++++------ > .../org/rhq/server/control/command/Console.java | 33 +++--- > .../org/rhq/server/control/command/Install.java | 27 ++--- > .../org/rhq/server/control/command/Remove.java | 55 +++++++--- > .../org/rhq/server/control/command/Restart.java | 6 +- > .../java/org/rhq/server/control/command/Start.java | 53 +++++++--- > .../org/rhq/server/control/command/Status.java | 35 ++++--- > .../java/org/rhq/server/control/command/Stop.java | 57 +++++++--- > .../org/rhq/server/control/command/Upgrade.java | 73 ++++++++----- > 11 files changed, 347 insertions(+), 155 deletions(-) > >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/ControlCommand.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/ControlCommand.java >index db6a0ca..27f8e8f 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/ControlCommand.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/ControlCommand.java >@@ -60,6 +60,7 @@ public abstract class ControlCommand { > public static final String SERVER_OPTION = "server"; > public static final String STORAGE_OPTION = "storage"; > public static final String AGENT_OPTION = "agent"; >+ public static final String RHQ_STORAGE_BASEDIR_PROP = "rhq.storage.basedir"; > public static final String RHQ_AGENT_BASEDIR_PROP = "rhq.agent.basedir"; > > protected static final String STORAGE_BASEDIR_NAME = "rhq-storage"; >@@ -133,6 +134,7 @@ public abstract class ControlCommand { > throw new RHQControlException("Failed to load configuration", e); > } > } >+ > defaultStorageBasedir = new File(getBaseDir(), STORAGE_BASEDIR_NAME); > defaultAgentBasedir = new File(getBaseDir().getParent(), AGENT_BASEDIR_NAME); > } >@@ -143,22 +145,26 @@ public abstract class ControlCommand { > > public abstract Options getOptions(); > >- protected abstract void exec(CommandLine commandLine); >+ protected abstract int exec(CommandLine commandLine); > >- public void exec(String[] args) { >+ public int exec(String[] args) { > Options options = getOptions(); >+ int rValue = RHQControl.EXIT_CODE_OK; > try { > CommandLineParser parser = new PosixParser(); > CommandLine cmdLine = parser.parse(options, args); >- exec(cmdLine); >+ rValue = exec(cmdLine); > > if (rhqctlConfig != null) { > rhqctlConfig.save(); > } > } catch (ParseException e) { > printUsage(); >+ rValue = RHQControl.EXIT_CODE_INVALID_ARGUMENT; > } catch (ConfigurationException e) { > throw new RHQControlException("Failed to update " + getRhqCtlProperties(), e); >+ } finally { >+ return rValue; > } > } > >@@ -386,7 +392,6 @@ public abstract class ControlCommand { > result = new org.apache.commons.exec.CommandLine("cmd.exe"); > result.addArgument("/C"); > result.addArgument(scriptName.replace('/', '\\') + ".bat"); >- > } else { > result = new org.apache.commons.exec.CommandLine("./" + (addShExt ? scriptName + ".sh" : scriptName)); > } >@@ -456,6 +461,7 @@ public abstract class ControlCommand { > PumpStreamHandler streamHandler = new PumpStreamHandler(new NullOutputStream(), new NullOutputStream()); > executor.setStreamHandler(streamHandler); > org.apache.commons.exec.CommandLine commandLine; >+ > commandLine = new org.apache.commons.exec.CommandLine("kill").addArgument(pid); > executor.execute(commandLine); > } >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/RHQControl.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/RHQControl.java >index 24e4995..28a37de 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/RHQControl.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/RHQControl.java >@@ -22,6 +22,7 @@ > * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. > * > */ >+ > package org.rhq.server.control; > > import java.io.Console; >@@ -50,6 +51,19 @@ public class RHQControl { > > private final Log log = LogFactory.getLog(RHQControl.class); > >+ public static final int EXIT_CODE_OK = 0; >+ >+ // These try to follow the LSB specification - status command >+ public static final int EXIT_CODE_STATUS_NOT_RUNNING = 3; >+ public static final int EXIT_CODE_STATUS_UNKNOWN = 4; >+ >+ // These try to follow the LSB specification - other commands >+ public static final int EXIT_CODE_OPERATION_FAILED = 1; >+ public static final int EXIT_CODE_INVALID_ARGUMENT = 2; >+ public static final int EXIT_CODE_NOT_INSTALLED = 5; >+// public static final int EXIT_CODE_OPERATION_NOT_RUNNING = 7; >+ >+ > private Commands commands = new Commands(); > > public void printUsage() { >@@ -63,7 +77,8 @@ public class RHQControl { > helpFormatter.printHelp(syntax, header, commands.getOptions(), footer); > } > >- public void exec(String[] args) { >+ public int exec(String[] args) { >+ int rValue = EXIT_CODE_OK; > ControlCommand command = null; > boolean undo = false; > AbortHook abortHook = new AbortHook(); >@@ -71,6 +86,7 @@ public class RHQControl { > try { > if (args.length == 0) { > printUsage(); >+ rValue = EXIT_CODE_INVALID_ARGUMENT; > } else { > String commandName = findCommand(commands, args); > command = commands.get(commandName); >@@ -84,10 +100,11 @@ public class RHQControl { > Runtime.getRuntime().addShutdownHook(abortHook); > > // run the command >- command.exec(getCommandLine(commandName, args)); >+ rValue = command.exec(getCommandLine(commandName, args)); > } > } catch (UsageException e) { > printUsage(); >+ rValue = EXIT_CODE_INVALID_ARGUMENT; > } catch (RHQControlException e) { > undo = true; > >@@ -98,9 +115,11 @@ public class RHQControl { > } else { > log.error(rootCause.getMessage()); > } >+ rValue = EXIT_CODE_OPERATION_FAILED; > } catch (Throwable t) { > undo = true; > log.error(t); >+ rValue = EXIT_CODE_OPERATION_FAILED; > } finally { > abortHook.setCommand(null); > Runtime.getRuntime().removeShutdownHook(abortHook); >@@ -116,10 +135,11 @@ public class RHQControl { > } catch (Throwable t) { > log.warn("Failed to clean up after the failed installation attempt. " > + "You may have to clean up some things before attempting to install again", t); >+ rValue = EXIT_CODE_OPERATION_FAILED; > } > } > >- return; >+ return rValue; > } > > private void logWarningIfAgentRPMIsInstalled(ControlCommand command) { >@@ -303,9 +323,9 @@ public class RHQControl { > > public static void main(String[] args) throws Exception { > RHQControl control = new RHQControl(); >+ int rValue; > try { >- control.exec(args); >- System.exit(0); >+ rValue = control.exec(args); > } catch (RHQControlException e) { > Throwable rootCause = ThrowableUtil.getRootCause(e); > // Only show the messy stack trace if we're in debug mode. Otherwise keep it cleaner for the user... >@@ -314,8 +334,9 @@ public class RHQControl { > } else { > control.log.error("There was an unexpected error: " + rootCause.getMessage()); > } >- System.exit(1); >+ rValue = EXIT_CODE_OPERATION_FAILED; > } >+ System.exit(rValue); > } > > private class AbortHook extends Thread { >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 eb6cd15..1b3d47b 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 >@@ -43,6 +43,7 @@ import org.apache.commons.cli.CommandLineParser; > import org.apache.commons.cli.PosixParser; > import org.apache.commons.exec.DefaultExecuteResultHandler; > import org.apache.commons.exec.DefaultExecutor; >+import org.apache.commons.exec.ExecuteException; > import org.apache.commons.exec.Executor; > import org.apache.commons.exec.PumpStreamHandler; > >@@ -55,6 +56,7 @@ import org.rhq.core.util.file.FileReverter; > import org.rhq.core.util.file.FileUtil; > import org.rhq.core.util.stream.StreamUtil; > import org.rhq.server.control.ControlCommand; >+import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; > > /** >@@ -79,28 +81,31 @@ public abstract class AbstractInstall extends ControlCommand { > private static final String PREF_RHQ_AGENT_SERVER_BINDPORT = "rhq.agent.server.bind-port"; > private static final String PREF_RHQ_AGENT_SERVER_TRANSPORTPARAMS = "rhq.agent.server.transport-params"; > >- protected void installWindowsService(File workingDir, String batFile, boolean replaceExistingService, boolean start) >+ protected int installWindowsService(File workingDir, String batFile, boolean replaceExistingService, boolean start) > throws Exception { > Executor executor = new DefaultExecutor(); > executor.setWorkingDirectory(workingDir); > executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > >+ int rValue = RHQControl.EXIT_CODE_OK; >+ > if (replaceExistingService) { >- commandLine = getCommandLine(batFile, "stop"); >- executor.execute(commandLine); >+ commandLine = getCommandLine(batFile, "stop"); >+ rValue = Math.max(rValue, executor.execute(commandLine)); > >- commandLine = getCommandLine(batFile, "remove"); >- executor.execute(commandLine); >+ commandLine = getCommandLine(batFile, "remove"); >+ rValue = Math.max(rValue, executor.execute(commandLine)); > } > > commandLine = getCommandLine(batFile, "install"); >- executor.execute(commandLine); >+ rValue = Math.max(rValue, executor.execute(commandLine)); > > if (start) { > commandLine = getCommandLine(batFile, "start"); >- executor.execute(commandLine); >+ rValue = Math.max(rValue, executor.execute(commandLine)); > } >+ return rValue; > } > > protected void validateCustomStorageDataDirectories(CommandLine commandLine, List<String> errors) { >@@ -155,6 +160,31 @@ public abstract class AbstractInstall extends ControlCommand { > > } > >+ protected boolean isUnixPidRunning(String pid) { >+ >+ Executor executor = new DefaultExecutor(); >+ executor.setWorkingDirectory(getBinDir()); >+ executor.setStreamHandler(new PumpStreamHandler()); >+ org.apache.commons.exec.CommandLine commandLine; >+ >+ commandLine = new org.apache.commons.exec.CommandLine("/bin/kill").addArgument("-0").addArgument(pid); >+ >+ try { >+ int code = executor.execute(commandLine); >+ if (code != 0) { >+ return false; >+ } >+ } catch (ExecuteException ee) { >+ if (ee.getExitValue() == 1) { >+ // return code 1 means process does not exist >+ return false; >+ } >+ } catch (IOException e) { >+ log.error("Checking for running process failed: " + e.getMessage()); >+ } >+ return true; >+ } >+ > protected void waitForRHQServerToInitialize() throws Exception { > try { > final long messageInterval = 30000L; >@@ -169,13 +199,13 @@ public abstract class AbstractInstall extends ControlCommand { > long totalWait = (now - timerStart); > > if (totalWait < problemMessageInterval) { >- log.info("Still waiting for server to initialize..."); >+ log.info("Still waiting for server to start..."); > > } else { > long minutes = totalWait / 60000; > log.info("It has been over [" > + minutes >- + "] minutes - you may want to ensure your server initialization is proceeding as expected. You can check the log at [" >+ + "] minutes - you may want to ensure your server startup is proceeding as expected. You can check the log at [" > + new File(getBaseDir(), "logs/server.log").getPath() + "]."); > > timerStart = now; >@@ -196,6 +226,7 @@ public abstract class AbstractInstall extends ControlCommand { > } > } > >+ @SuppressWarnings("resource") > protected boolean isRHQServerInitialized() throws IOException { > > BufferedReader reader = null; >@@ -241,11 +272,13 @@ public abstract class AbstractInstall extends ControlCommand { > } > } > >- protected void updateWindowsAgentService(final File agentBasedir) throws Exception { >+ protected int updateWindowsAgentService(final File agentBasedir) throws Exception { > if (!isWindows()) { >- return; >+ return RHQControl.EXIT_CODE_OK; > } > >+ int rValue = 0; >+ > try { > File agentBinDir = new File(agentBasedir, "bin"); > if (!agentBinDir.exists()) { >@@ -262,7 +295,7 @@ public abstract class AbstractInstall extends ControlCommand { > > commandLine = getCommandLine("rhq-agent-wrapper", "stop"); > try { >- executor.execute(commandLine); >+ rValue = 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); >@@ -270,22 +303,26 @@ public abstract class AbstractInstall extends ControlCommand { > > commandLine = getCommandLine("rhq-agent-wrapper", "remove"); > try { >- executor.execute(commandLine); >+ rValue = Math.max(rValue, 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); >+ rValue = Math.max(rValue, executor.execute(commandLine)); > > } catch (IOException e) { > log.error("An error occurred while updating the agent service: " + e.getMessage()); > throw e; > } >+ >+ return rValue; > } > >- protected void startAgent(final File agentBasedir) throws Exception { >+ protected int startAgent(final File agentBasedir) throws Exception { >+ int rValue; >+ > try { > File agentBinDir = new File(agentBasedir, "bin"); > if (!agentBinDir.exists()) { >@@ -300,7 +337,7 @@ public abstract class AbstractInstall extends ControlCommand { > > // 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); >+ rValue = executor.execute(commandLine); > > // if any errors occur after now, we need to stop the agent > addUndoTask(new ControlCommand.UndoTask("Stopping agent") { >@@ -314,9 +351,10 @@ public abstract class AbstractInstall extends ControlCommand { > log.error("An error occurred while starting the agent: " + e.getMessage()); > throw e; > } >+ return rValue; > } > >- protected void killAgent(File agentBasedir) throws Exception { >+ protected int killAgent(File agentBasedir) throws Exception { > > File agentBinDir = new File(agentBasedir, "bin"); > if (!agentBinDir.exists()) { >@@ -328,25 +366,32 @@ public abstract class AbstractInstall extends ControlCommand { > Executor executor = new DefaultExecutor(); > executor.setWorkingDirectory(agentBinDir); > executor.setStreamHandler(new PumpStreamHandler()); >+ org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-agent-wrapper", "stop"); >+ >+ int rValue = 0; > > if (isWindows()) { > try { >- org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-agent-wrapper", "stop"); >- executor.execute(commandLine); >+ commandLine = getCommandLine("rhq-agent-wrapper", "stop"); >+ rValue = 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); >+ rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } else { > String pid = getAgentPid(); > if (pid != null) { >- org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-agent-wrapper", "kill"); >- executor.execute(commandLine); >+ commandLine = getCommandLine("rhq-agent-wrapper", "kill"); >+ rValue = executor.execute(commandLine); >+ } else { >+ rValue = RHQControl.EXIT_CODE_OK; > } > } >+ return rValue; > } > >- protected void stopServer() throws Exception { >+ protected int stopServer() throws Exception { > > File serverBinDir = getBinDir(); > if (!serverBinDir.exists()) { >@@ -360,16 +405,20 @@ public abstract class AbstractInstall extends ControlCommand { > executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-server", "stop"); > >+ int rValue; >+ > if (isWindows()) { > try { >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); > } catch (Exception e) { > // Ignore, service may not exist or be running, , script returns 1 > log.debug("Failed to stop server service", e); >+ rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } else { >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); > } >+ return rValue; > } > > protected void startRHQServerForInstallation() throws IOException { >@@ -446,7 +495,7 @@ public abstract class AbstractInstall extends ControlCommand { > } > } > >- protected void runRHQServerInstaller() throws IOException { >+ protected int runRHQServerInstaller() throws IOException { > try { > log.info("Installing RHQ server"); > >@@ -467,10 +516,14 @@ public abstract class AbstractInstall extends ControlCommand { > executor.setWorkingDirectory(getBinDir()); > executor.setStreamHandler(new PumpStreamHandler()); > >- executor.execute(commandLine, new DefaultExecuteResultHandler()); >+ DefaultExecuteResultHandler executeHandler = new DefaultExecuteResultHandler(); >+ >+ executor.execute(commandLine, executeHandler); > log.info("The server installer is running"); >- } catch (Exception e) { >+ return executeHandler.getExitValue(); >+ } catch (IOException e) { > log.error("An error occurred while starting the server installer: " + e.getMessage()); >+ return RHQControl.EXIT_CODE_NOT_INSTALLED; > } > } > >@@ -560,6 +613,7 @@ public abstract class AbstractInstall extends ControlCommand { > Executor executor = new DefaultExecutor(); > executor.setWorkingDirectory(getBinDir()); > executor.setStreamHandler(new PumpStreamHandler()); >+ > int exitCode = executor.execute(commandLine); > log.info("The storage node installer has finished with an exit value of " + exitCode); > >@@ -577,13 +631,14 @@ public abstract class AbstractInstall extends ControlCommand { > } > } > >- protected void installAgent(final File agentBasedir, final CommandLine commandLine) throws Exception { >+ protected int installAgent(final File agentBasedir, final CommandLine commandLine) throws Exception { > clearAgentPreferences(); >- installAgent(agentBasedir); >+ int rValue = installAgent(agentBasedir); > configureAgent(agentBasedir, commandLine); >+ return rValue; > } > >- private void installAgent(final File agentBasedir) throws IOException { >+ private int installAgent(final File agentBasedir) throws IOException { > try { > log.info("Installing RHQ agent"); > >@@ -612,6 +667,7 @@ public abstract class AbstractInstall extends ControlCommand { > > int exitValue = executor.execute(commandLine); > log.info("The agent installer finished running with exit value " + exitValue); >+ return exitValue; > } catch (IOException e) { > log.error("An error occurred while running the agent installer: " + e.getMessage()); > throw e; >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Console.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Console.java >index 4139969..6039e9d 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Console.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Console.java >@@ -32,6 +32,7 @@ import org.apache.commons.exec.Executor; > import org.apache.commons.exec.PumpStreamHandler; > > import org.rhq.server.control.ControlCommand; >+import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; > > /** >@@ -70,32 +71,38 @@ public class Console extends ControlCommand { > } > > @Override >- protected void exec(CommandLine commandLine) { >+ protected int exec(CommandLine commandLine) { >+ int rValue = RHQControl.EXIT_CODE_OK; >+ > if (commandLine.getOptions().length != 1) { > printUsage(); >+ rValue = RHQControl.EXIT_CODE_INVALID_ARGUMENT; > } else { > String option = commandLine.getOptions()[0].getLongOpt(); > try { > if (option.equals(STORAGE_OPTION)) { > if (isStorageInstalled()) { >- startStorageInForeground(); >+ rValue = Math.max(rValue, startStorageInForeground()); > } else { > log.warn("It appears that the storage node is not installed. The --" + STORAGE_OPTION > + " option will be ignored."); >+ rValue = RHQControl.EXIT_CODE_INVALID_ARGUMENT; > } > } else if (option.equals(SERVER_OPTION)) { > if (isServerInstalled()) { >- startServerInForeground(); >+ rValue = Math.max(rValue, startServerInForeground()); > } else { > log.warn("It appears that the server is not installed. The --" + SERVER_OPTION > + " option will be ignored."); >+ rValue = RHQControl.EXIT_CODE_INVALID_ARGUMENT; > } > } else if (option.equals(AGENT_OPTION)) { > if (isAgentInstalled()) { >- startAgentInForeground(); >+ rValue = Math.max(rValue, startAgentInForeground()); > } else { > log.warn("It appears that the agent is not installed. The --" + AGENT_OPTION > + " option will be ignored."); >+ rValue = RHQControl.EXIT_CODE_INVALID_ARGUMENT; > } > } else { > throw new IllegalArgumentException(option + " is not a supported option"); >@@ -104,32 +111,33 @@ public class Console extends ControlCommand { > throw new RHQControlException("Failed to execute console command", e); > } > } >+ return rValue; > } > >- private void startStorageInForeground() throws Exception { >+ private int startStorageInForeground() throws Exception { > log.debug("Starting RHQ storage node in foreground"); > > File storageBinDir = new File(getStorageBasedir(), "bin"); > > org.apache.commons.exec.CommandLine commandLine = new org.apache.commons.exec.CommandLine(getCommandLine(false, > "cassandra", "-f")); >- Executor exeuctor = new DefaultExecutor(); >- exeuctor.setWorkingDirectory(storageBinDir); >- exeuctor.setStreamHandler(new PumpStreamHandler()); >- exeuctor.execute(commandLine); >+ Executor executor = new DefaultExecutor(); >+ executor.setWorkingDirectory(storageBinDir); >+ executor.setStreamHandler(new PumpStreamHandler()); >+ return executor.execute(commandLine); > } > >- private void startServerInForeground() throws Exception { >+ private int startServerInForeground() throws Exception { > log.debug("Starting RHQ server in foreground"); > > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-server", "console"); > Executor executor = new DefaultExecutor(); > executor.setWorkingDirectory(getBinDir()); > executor.setStreamHandler(new PumpStreamHandler()); >- executor.execute(commandLine); >+ return executor.execute(commandLine); > } > >- private void startAgentInForeground() throws Exception { >+ private int startAgentInForeground() throws Exception { > log.info("Starting RHQ agent in foreground"); > > File agentHomeDir = getAgentBasedir(); >@@ -165,6 +173,7 @@ public class Console extends ControlCommand { > // agentThread.start(); > // doneSignal.await(); > // agentThread.join(); >+ return RHQControl.EXIT_CODE_OK; > } > > private class AgentInputStreamPipe extends Thread { >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 be76e59..3ab3f00 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 >@@ -33,6 +33,7 @@ import org.apache.commons.cli.Options; > > import org.rhq.core.util.file.FileReverter; > import org.rhq.server.control.ControlCommand; >+import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; > > /** >@@ -95,10 +96,11 @@ public class Install extends AbstractInstall { > } > > @Override >- protected void exec(CommandLine commandLine) { >+ protected int exec(CommandLine commandLine) { > boolean start = commandLine.hasOption(START_OPTION); > boolean startedStorage = false; > boolean startedServer = false; >+ int rValue = RHQControl.EXIT_CODE_OK; > > try { > List<String> errors = validateOptions(commandLine); >@@ -107,7 +109,7 @@ public class Install extends AbstractInstall { > log.error(error); > } > log.error("Exiting due to the previous errors"); >- return; >+ return RHQControl.EXIT_CODE_NOT_INSTALLED; > } > > // If any failures occur, we know we need to reset rhq-server.properties. >@@ -137,10 +139,10 @@ public class Install extends AbstractInstall { > > if (isWindows()) { > log.info("Ensuring the RHQ Storage Windows service exists. Ignore any CreateService failure."); >- installWindowsService(getBinDir(), "rhq-storage", false, false); >+ rValue = Math.max(rValue, installWindowsService(getBinDir(), "rhq-storage", false, false)); > } > } else { >- installStorageNode(getStorageBasedir(), commandLine, false); >+ rValue = Math.max(rValue, installStorageNode(getStorageBasedir(), commandLine, false)); > startStorage = start; > } > } >@@ -148,7 +150,7 @@ public class Install extends AbstractInstall { > if (startStorage || installServer) { > startedStorage = true; > Start startCommand = new Start(); >- startCommand.exec(new String[] { "start", "--storage" }); >+ rValue = Math.max(rValue, startCommand.exec(new String[] { "start", "--storage" })); > } > > if (installServer) { >@@ -157,12 +159,12 @@ public class Install extends AbstractInstall { > > if (isWindows()) { > log.info("Ensuring the RHQ Server Windows service exists. Ignore any CreateService failure."); >- installWindowsService(getBinDir(), "rhq-server", false, false); >+ rValue = Math.max(rValue, installWindowsService(getBinDir(), "rhq-server", false, false)); > } > } else { > startedServer = true; > startRHQServerForInstallation(); >- runRHQServerInstaller(); >+ rValue = Math.max(rValue, runRHQServerInstaller()); > waitForRHQServerToInitialize(); > } > } >@@ -175,7 +177,7 @@ public class Install extends AbstractInstall { > 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); >+ rValue = Math.max(rValue, 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); >@@ -185,10 +187,10 @@ public class Install extends AbstractInstall { > File agentBasedir = getAgentBasedir(); > installAgent(agentBasedir, commandLine); > >- updateWindowsAgentService(agentBasedir); >+ rValue = Math.max(rValue, updateWindowsAgentService(agentBasedir)); > > if (start) { >- startAgent(agentBasedir); >+ rValue = Math.max(rValue, startAgent(agentBasedir)); > } > } > } >@@ -200,13 +202,14 @@ public class Install extends AbstractInstall { > if (!start && (startedStorage || startedServer)) { > Stop stopCommand = new Stop(); > if (startedServer) { >- stopCommand.exec(new String[] { "stop", "--server" }); >+ rValue = Math.max(rValue, stopCommand.exec(new String[] { "stop", "--server" })); > } > if (startedStorage) { >- stopCommand.exec(new String[] { "stop", "--storage" }); >+ rValue = Math.max(rValue, stopCommand.exec(new String[] { "stop", "--storage" })); > } > } > } >+ return rValue; > } > > private List<String> validateOptions(CommandLine commandLine) { >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Remove.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Remove.java >index cb8f43b..1de4250 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Remove.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Remove.java >@@ -34,6 +34,7 @@ import org.apache.commons.exec.Executor; > import org.apache.commons.exec.PumpStreamHandler; > > import org.rhq.server.control.ControlCommand; >+import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; > > /** >@@ -74,52 +75,56 @@ public class Remove extends ControlCommand { > } > > @Override >- protected void exec(CommandLine commandLine) { >+ protected int exec(CommandLine commandLine) { >+ int rValue = RHQControl.EXIT_CODE_OK; > try { > // if no options specified, then stop whatever is installed > if (commandLine.getOptions().length == 0) { > if (isAgentInstalled()) { >- removeAgentService(); >+ rValue = Math.max(rValue, removeAgentService()); > } > > // the server service may be installed even if the full server install fails. The files to execute > // the remove are there after the initial unzip, so just go ahead and try to remove the service. This > // may help clean up a failed install. >- removeServerService(); >+ rValue = Math.max(rValue, removeServerService()); > > if (isStorageInstalled()) { >- removeStorageService(); >+ rValue = Math.max(rValue, removeStorageService()); > } > } else { > if (commandLine.hasOption(AGENT_OPTION)) { > if (isAgentInstalled()) { >- removeAgentService(); >+ rValue = Math.max(rValue, removeAgentService()); > } else { > log.warn("It appears that the agent is not installed. The --" + AGENT_OPTION > + " option will be ignored."); >+ rValue = RHQControl.EXIT_CODE_INVALID_ARGUMENT; > } > } > if (commandLine.hasOption(SERVER_OPTION)) { > // the server service may be installed even if the full server install fails. The files to execute > // the remove are there after the initial unzip, so just go ahead and try to remove the service. This > // may help clean up a failed install. >- removeServerService(); >+ rValue = Math.max(rValue, removeServerService()); > } > if (commandLine.hasOption(STORAGE_OPTION)) { > if (isStorageInstalled()) { >- removeStorageService(); >+ rValue = Math.max(rValue, removeStorageService()); > } else { > log.warn("It appears that the storage node is not installed. The --" + STORAGE_OPTION > + " option will be ignored."); >+ rValue = RHQControl.EXIT_CODE_INVALID_ARGUMENT; > } > } > } > } catch (Exception e) { > throw new RHQControlException("Failed to stop services", e); > } >+ return rValue; > } > >- private void removeStorageService() throws Exception { >+ private int removeStorageService() throws Exception { > log.debug("Stopping RHQ storage node"); > > Executor executor = new DefaultExecutor(); >@@ -127,12 +132,15 @@ public class Remove extends ControlCommand { > executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > >+ int rValue; >+ > if (isWindows()) { > commandLine = getCommandLine("rhq-storage", "remove"); > try { >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); > } catch (Exception e) { > log.debug("Failed to remove storage service", e); >+ rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } else { > String pid = getStoragePid(); >@@ -141,15 +149,18 @@ public class Remove extends ControlCommand { > System.out.println("RHQ storage node (pid=" + pid + ") is stopping..."); > > commandLine = new org.apache.commons.exec.CommandLine("kill").addArgument(pid); >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); > > System.out.println("RHQ storage node has stopped"); >+ } else { >+ rValue = RHQControl.EXIT_CODE_OK; > } > > } >+ return rValue; > } > >- private void removeServerService() throws Exception { >+ private int removeServerService() throws Exception { > log.debug("Stopping RHQ server"); > > Executor executor = new DefaultExecutor(); >@@ -157,25 +168,31 @@ public class Remove extends ControlCommand { > executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > >+ int rValue; >+ > if (isWindows()) { > try { > commandLine = getCommandLine("rhq-server", "remove"); >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); > } catch (Exception e) { > // Ignore, service may not exist or be running, , script returns 1 > log.debug("Failed to remove server service", e); >+ rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } else { > String pid = getServerPid(); > > if (pid != null) { > commandLine = getCommandLine("rhq-server", "stop"); >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); >+ } else { >+ rValue = RHQControl.EXIT_CODE_OK; > } > } >+ return rValue; > } > >- private void removeAgentService() throws Exception { >+ private int removeAgentService() throws Exception { > log.debug("Stopping RHQ agent"); > > File agentBinDir = new File(getAgentBasedir(), "bin"); >@@ -184,21 +201,27 @@ public class Remove extends ControlCommand { > executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > >+ int rValue; >+ > if (isWindows()) { > try { > commandLine = getCommandLine("rhq-agent-wrapper", "remove"); >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); > } catch (Exception e) { > // Ignore, service may not exist, script returns 1 > log.debug("Failed to remove agent service", e); >+ rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } else { > String pid = getAgentPid(); > > if (pid != null) { > commandLine = getCommandLine("rhq-agent-wrapper", "stop"); >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); >+ } else { >+ rValue = RHQControl.EXIT_CODE_OK; > } > } >+ return rValue; > } > } >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Restart.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Restart.java >index fffb769..40d61c6 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Restart.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Restart.java >@@ -64,11 +64,13 @@ public class Restart extends ControlCommand { > } > > @Override >- protected void exec(CommandLine commandLine) { >+ protected int exec(CommandLine commandLine) { > Stop stop = new Stop(); > stop.exec(commandLine); > >+ // If the server isn't stopped.. restart had some LSB rules.. check 'em. >+ > Start start = new Start(); >- start.exec(commandLine); >+ return start.exec(commandLine); > } > } >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 7d621cb..5d540a1 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 >@@ -36,6 +36,7 @@ import org.apache.commons.exec.Executor; > import org.apache.commons.exec.PumpStreamHandler; > > import org.rhq.server.control.ControlCommand; >+import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; > > /** >@@ -72,7 +73,8 @@ public class Start extends ControlCommand { > } > > @Override >- protected void exec(CommandLine commandLine) { >+ protected int exec(CommandLine commandLine) { >+ int rValue = RHQControl.EXIT_CODE_OK; > try { > // if no options specified, then start whatever is installed > if (commandLine.getOptions().length == 0) { >@@ -82,55 +84,62 @@ public class Start extends ControlCommand { > > if (!(storageInstalled || serverInstalled || agentInstalled)) { > log.warn("Nothing to start. No RHQ services are installed."); >+ rValue = RHQControl.EXIT_CODE_NOT_INSTALLED; > } else { > if (storageInstalled) { >- startStorage(); >+ rValue = Math.max(rValue, startStorage()); > } > if (serverInstalled) { >- startRHQServer(); >+ rValue = Math.max(rValue, startRHQServer()); > } > if (agentInstalled) { >- startAgent(); >+ rValue = Math.max(rValue, startAgent()); > } > } > } else { > if (commandLine.hasOption(STORAGE_OPTION)) { > if (isStorageInstalled()) { >- startStorage(); >+ rValue = Math.max(rValue, startStorage()); > } else { > log.warn("It appears that the storage node is not installed. The --" + STORAGE_OPTION > + " option will be ignored."); >+ rValue = RHQControl.EXIT_CODE_NOT_INSTALLED; > } > } > if (commandLine.hasOption(SERVER_OPTION)) { > if (isServerInstalled()) { >- startRHQServer(); >+ rValue = Math.max(rValue, startRHQServer()); > } else { > log.warn("It appears that the server is not installed. The --" + SERVER_OPTION > + " option will be ignored."); >+ rValue = RHQControl.EXIT_CODE_NOT_INSTALLED; > } > } > if (commandLine.hasOption(AGENT_OPTION)) { > if (isAgentInstalled()) { >- startAgent(); >+ rValue = Math.max(rValue, startAgent()); > } else { > log.warn("It appears that the agent is not installed. The --" + AGENT_OPTION > + " option will be ignored."); >+ rValue = RHQControl.EXIT_CODE_NOT_INSTALLED; > } > } > } > } catch (Exception e) { > throw new RHQControlException("Failed to start services", e); > } >+ return rValue; > } > >- private void startStorage() throws Exception { >+ private int startStorage() throws Exception { > log.debug("Starting RHQ storage node"); > > Executor executor = new DefaultExecutor(); > executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > >+ int rValue; >+ > // Cassandra looks for JAVA_HOME or then defaults to PATH. We want it to use the Java > // defined for RHQ, so make sure JAVA_HOME is set, and set to the RHQ Java for the executor > // environment. >@@ -144,11 +153,12 @@ public class Start extends ControlCommand { > executor.setWorkingDirectory(getBinDir()); > commandLine = getCommandLine("rhq-storage", "start"); > try { >- executor.execute(commandLine, env); >+ rValue = executor.execute(commandLine, env); > > } catch (Exception e) { > // Ignore, service may not exist or may already be running, script returns 1 > log.debug("Failed to start storage service", e); >+ rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } else { > File storageBinDir = new File(getStorageBasedir(), "bin"); >@@ -159,16 +169,18 @@ public class Start extends ControlCommand { > if (isStorageRunning()) { > String pid = getStoragePid(); > System.out.println("RHQ storage node (pid " + pid + ") is running"); >+ rValue = RHQControl.EXIT_CODE_OK; > } else { > commandLine = getCommandLine(false, "cassandra", "-p", pidFile.getAbsolutePath()); > executor.setWorkingDirectory(storageBinDir); > >- executor.execute(commandLine, env); >+ rValue = executor.execute(commandLine, env); > } > } >+ return rValue; > } > >- private void startRHQServer() throws Exception { >+ private int startRHQServer() throws Exception { > log.debug("Starting RHQ server"); > > Executor executor = new DefaultExecutor(); >@@ -176,19 +188,23 @@ public class Start extends ControlCommand { > executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-server", "start"); > >+ int rValue; >+ > if (isWindows()) { > try { >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); > } catch (Exception e) { > // Ignore, service may not exist or be running, , script returns 1 > log.debug("Failed to start server service", e); >+ rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } else { >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); > } >+ return rValue; > } > >- private void startAgent() throws Exception { >+ private int startAgent() throws Exception { > log.debug("Starting RHQ agent"); > > File agentBinDir = new File(getAgentBasedir(), "bin"); >@@ -197,16 +213,21 @@ public class Start extends ControlCommand { > executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-agent-wrapper", "start"); > >+ int rValue; >+ > if (isWindows()) { > try { >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); > } catch (Exception e) { > // Ignore, service may not exist or be running, , script returns 1 > log.debug("Failed to start agent service", e); >+ rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } else { >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); > } >+ >+ return rValue; > } > > } >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Status.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Status.java >index 9ba9f60..e52f0a8 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Status.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Status.java >@@ -35,6 +35,7 @@ import org.apache.commons.exec.Executor; > import org.apache.commons.exec.PumpStreamHandler; > > import org.rhq.server.control.ControlCommand; >+import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; > > /** >@@ -71,23 +72,24 @@ public class Status extends ControlCommand { > } > > @Override >- protected void exec(CommandLine commandLine) { >+ protected int exec(CommandLine commandLine) { >+ int rValue = RHQControl.EXIT_CODE_OK; > try { > // if no options specified, then check the status of whatever is installed > if (commandLine.getOptions().length == 0) { > if (isStorageInstalled()) { >- checkStorageStatus(); >+ rValue = Math.max(rValue, checkStorageStatus()); > } > if (isServerInstalled()) { >- checkServerStatus(); >+ rValue = Math.max(rValue, checkServerStatus()); > } > if (isAgentInstalled()) { >- checkAgentStatus(); >+ rValue = Math.max(rValue, checkAgentStatus()); > } > } else { > if (commandLine.hasOption(STORAGE_OPTION)) { > if (isStorageInstalled()) { >- checkStorageStatus(); >+ rValue = Math.max(rValue, checkStorageStatus()); > } else { > log.warn("It appears that the storage node is not installed. The --" + STORAGE_OPTION > + " option will be ignored."); >@@ -95,7 +97,7 @@ public class Status extends ControlCommand { > } > if (commandLine.hasOption(SERVER_OPTION)) { > if (isServerInstalled()) { >- checkServerStatus(); >+ rValue = Math.max(rValue, checkServerStatus()); > } else { > log.warn("It appears that the server is not installed. The --" + SERVER_OPTION > + " option will be ignored."); >@@ -103,7 +105,7 @@ public class Status extends ControlCommand { > } > if (commandLine.hasOption(AGENT_OPTION)) { > if (isAgentInstalled()) { >- checkAgentStatus(); >+ rValue = Math.max(rValue, checkAgentStatus()); > } else { > log.warn("It appears that the agent is not installed. The --" + AGENT_OPTION > + " option will be ignored."); >@@ -113,11 +115,14 @@ public class Status extends ControlCommand { > } catch (Exception e) { > throw new RHQControlException("Failed to check statuses", e); > } >+ return rValue; > } > >- private void checkStorageStatus() throws Exception { >+ private int checkStorageStatus() throws Exception { > log.debug("Checking RHQ storage node status"); > >+ int rValue = RHQControl.EXIT_CODE_OK; >+ > if (isWindows()) { > Executor executor = new DefaultExecutor(); > executor.setStreamHandler(new PumpStreamHandler()); >@@ -125,31 +130,34 @@ public class Status extends ControlCommand { > executor.setWorkingDirectory(getBinDir()); > commandLine = getCommandLine("rhq-storage", "status"); > try { >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); > > } catch (Exception e) { > log.debug("Failed to check storage service status", e); >+ rValue = RHQControl.EXIT_CODE_STATUS_UNKNOWN; > } > } else { > if(isStorageRunning()) { > System.out.println(String.format("%-30s", "RHQ Storage Node") + " (pid " + String.format("%-7s", getStoragePid()) + ") IS running"); > } else { > System.out.println(String.format("%-30s", "RHQ Storage Node") + " (no pid file) IS NOT running"); >+ rValue = RHQControl.EXIT_CODE_STATUS_NOT_RUNNING; > } > } >+ return rValue; > } > >- private void checkServerStatus() throws Exception { >+ private int checkServerStatus() throws Exception { > log.debug("Checking RHQ server status"); > > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-server", "status"); > Executor executor = new DefaultExecutor(); > executor.setWorkingDirectory(getBinDir()); > executor.setStreamHandler(new PumpStreamHandler()); >- executor.execute(commandLine); >+ return executor.execute(commandLine); > } > >- private void checkAgentStatus() throws Exception { >+ private int checkAgentStatus() throws Exception { > log.debug("Checking RHQ agent status"); > > File agentBinDir = new File(getAgentBasedir(), "bin"); >@@ -159,7 +167,7 @@ public class Status extends ControlCommand { > executor.setWorkingDirectory(agentBinDir); > executor.setStreamHandler(new PumpStreamHandler()); > try { >- executor.execute(commandLine); >+ return executor.execute(commandLine); > } catch (ExecuteException e) { > // For windows the JSW exit code for a status check is expected to be a mask value and the agent wrapper > // .bat will return it explicitly. We can ignore it and assume that the logged output is sufficient. >@@ -167,6 +175,7 @@ public class Status extends ControlCommand { > if (!isWindows()) { > throw e; > } >+ return RHQControl.EXIT_CODE_STATUS_UNKNOWN; > } > } > } >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Stop.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Stop.java >index 9b51e28..a3920e0 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Stop.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Stop.java >@@ -33,6 +33,7 @@ import org.apache.commons.exec.DefaultExecutor; > import org.apache.commons.exec.Executor; > import org.apache.commons.exec.PumpStreamHandler; > >+import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; > > /** >@@ -68,29 +69,33 @@ public class Stop extends AbstractInstall { > } > > @Override >- protected void exec(CommandLine commandLine) { >+ protected int exec(CommandLine commandLine) { >+ >+ int rValue = RHQControl.EXIT_CODE_OK; >+ > try { > // if no options specified, then stop whatever is installed > if (commandLine.getOptions().length == 0) { > if (isAgentInstalled()) { >- stopAgent(); >+ rValue = Math.max(rValue, stopAgent()); > } > > // the server service may be installed even if the full server install fails. The files to execute > // the remove are there after the initial unzip, so just go ahead and try to stop the service. This > // may help clean up a failed install. >- stopRHQServer(); >+ rValue = Math.max(rValue, stopRHQServer()); > > if (isStorageInstalled()) { >- stopStorage(); >+ rValue = Math.max(rValue, stopStorage()); > } > } else { > if (commandLine.hasOption(AGENT_OPTION)) { > if (isAgentInstalled()) { >- stopAgent(); >+ rValue = Math.max(rValue, stopAgent()); > } else { > log.warn("It appears that the agent is not installed. The --" + AGENT_OPTION > + " option will be ignored."); >+ rValue = RHQControl.EXIT_CODE_INVALID_ARGUMENT; > } > } > >@@ -98,24 +103,26 @@ public class Stop extends AbstractInstall { > // the server service may be installed even if the full server install fails. The files to execute > // the remove are there after the initial unzip, so just go ahead and try to stop the service. This > // may help clean up a failed install. >- stopRHQServer(); >+ rValue = Math.max(rValue, stopRHQServer()); > } > > if (commandLine.hasOption(STORAGE_OPTION)) { > if (isStorageInstalled()) { >- stopStorage(); >+ rValue = Math.max(rValue, stopStorage()); > } else { > log.warn("It appears that the storage node is not installed. The --" + STORAGE_OPTION > + " option will be ignored."); >+ rValue = RHQControl.EXIT_CODE_INVALID_ARGUMENT; > } > } > } > } catch (Exception e) { > throw new RHQControlException("Failed to stop services", e); > } >+ return rValue; > } > >- private void stopStorage() throws Exception { >+ private int stopStorage() throws Exception { > log.debug("Stopping RHQ storage node"); > > Executor executor = new DefaultExecutor(); >@@ -123,17 +130,21 @@ public class Stop extends AbstractInstall { > executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > >+ int rValue; >+ > if (isWindows()) { > commandLine = getCommandLine("rhq-storage", "stop"); > try { >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); >+ System.out.println("RHQ storage node has stopped"); > > } catch (Exception e) { > // Ignore, service may not exist or be running, script returns 1 > log.debug("Failed to stop storage service", e); >+ rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } else { >- if (isStorageRunning()) { >+ if(isStorageRunning()) { > String pid = getStoragePid(); > > System.out.println("Stopping RHQ storage node..."); >@@ -145,11 +156,13 @@ public class Stop extends AbstractInstall { > > System.out.println("RHQ storage node has stopped"); > } >+ rValue = RHQControl.EXIT_CODE_OK; // If process isn't running, stopping it is considered OK. > > } >+ return rValue; > } > >- private void stopRHQServer() throws Exception { >+ private int stopRHQServer() throws Exception { > log.debug("Stopping RHQ server"); > > Executor executor = new DefaultExecutor(); >@@ -157,23 +170,29 @@ public class Stop extends AbstractInstall { > executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-server", "stop"); > >+ int rValue; >+ > if (isWindows()) { > try { >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); > } catch (Exception e) { > // Ignore, service may not exist or be running, , script returns 1 > log.debug("Failed to stop server service", e); >+ rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } else { > String pid = getServerPid(); > > if (pid != null) { >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); >+ } else { >+ rValue = RHQControl.EXIT_CODE_OK; > } > } >+ return rValue; > } > >- private void stopAgent() throws Exception { >+ private int stopAgent() throws Exception { > log.debug("Stopping RHQ agent"); > > File agentBinDir = new File(getAgentBasedir(), "bin"); >@@ -182,19 +201,25 @@ public class Stop extends AbstractInstall { > executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-agent-wrapper", "stop"); > >+ int rValue; >+ > if (isWindows()) { > try { >- executor.execute(commandLine); >+ rValue = 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); >+ rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } else { > String pid = getAgentPid(); > > if (pid != null) { >- executor.execute(commandLine); >+ rValue = executor.execute(commandLine); >+ } else { >+ rValue = RHQControl.EXIT_CODE_OK; > } > } >+ return rValue; > } > } >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 5a762cd..cc3d8c2 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 >@@ -48,6 +48,7 @@ import org.rhq.core.util.file.FileUtil; > import org.rhq.core.util.file.FileVisitor; > import org.rhq.core.util.stream.StreamUtil; > import org.rhq.server.control.ControlCommand; >+import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; > > /** >@@ -125,7 +126,8 @@ public class Upgrade extends AbstractInstall { > } > > @Override >- protected void exec(CommandLine commandLine) { >+ protected int exec(CommandLine commandLine) { >+ int rValue = RHQControl.EXIT_CODE_OK; > boolean start = commandLine.hasOption(START_OPTION); > > try { >@@ -135,9 +137,13 @@ public class Upgrade extends AbstractInstall { > log.error(error); > } > log.error("Exiting due to the previous errors"); >- return; >+ return RHQControl.EXIT_CODE_OPERATION_FAILED; > } > >+ // Attempt to shutdown any running components. A failure to shutdown a component is not a failure as it >+ // really shouldn't be running anyway. This is just an attempt to avoid upgrade problems. >+ log.info("Stopping any running RHQ components..."); >+ > // If using non-default agent location then save it so it will be applied to all subsequent rhqctl commands. > boolean hasFromAgentOption = commandLine.hasOption(FROM_AGENT_DIR_OPTION); > if (hasFromAgentOption) { >@@ -149,7 +155,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 RHQControl.EXIT_CODE_OPERATION_FAILED; > } > > // Attempt to shutdown any running components. A failure to shutdown a component is not a failure as it >@@ -158,7 +164,7 @@ public class Upgrade extends AbstractInstall { > > // Stop the agent, if running. > if (hasFromAgentOption) { >- killAgent(getFromAgentDir(commandLine)); // this validates the path as well >+ rValue = Math.max(rValue, killAgent(getFromAgentDir(commandLine))); // this validates the path as well > } > > // If rhqctl exists in the old version, use it to stop old components, otherwise, just try and stop the >@@ -177,10 +183,10 @@ public class Upgrade extends AbstractInstall { > } else { > log.error("The old installation components failed to be stopped. Please stop them manually before continuing. exit code=" > + exitValue); >- return; >+ return exitValue; > } > >- // If any failures occur during upgrade, we know we need to reset rhq-server.properties. >+ // If any failures occur during upgrade, we know we need to reset rhq-server.properties. > final FileReverter serverPropFileReverter = new FileReverter(getServerPropertiesFile()); > addUndoTask(new ControlCommand.UndoTask("Reverting server properties file") { > public void performUndoWork() throws Exception { >@@ -193,9 +199,9 @@ public class Upgrade extends AbstractInstall { > }); > > // now upgrade everything >- upgradeStorage(commandLine); >- upgradeServer(commandLine); >- upgradeAgent(commandLine); >+ rValue = Math.max(rValue, upgradeStorage(commandLine)); >+ rValue = Math.max(rValue, upgradeServer(commandLine)); >+ rValue = Math.max(rValue, upgradeAgent(commandLine)); > > File agentDir; > >@@ -208,7 +214,7 @@ public class Upgrade extends AbstractInstall { > updateWindowsAgentService(agentDir); > > if (start) { >- startAgent(agentDir); >+ rValue = Math.max(rValue, startAgent(agentDir)); > } > } catch (Exception e) { > throw new RHQControlException("An error occurred while executing the upgrade command", e); >@@ -218,30 +224,33 @@ public class Upgrade extends AbstractInstall { > Stop stopCommand = new Stop(); > stopCommand.exec(new String[] { "stop", "--server" }); > if (!commandLine.hasOption(RUN_DATA_MIGRATION)) { >- stopCommand.exec(new String[] { "stop", "--storage" }); >+ rValue = Math.max(rValue, stopCommand.exec(new String[] { "stop", "--storage" })); > } > } > } catch (Throwable t) { > log.warn("Unable to stop services: " + t.getMessage()); >+ rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } > > if (!isRhq48OrLater(commandLine) && commandLine.hasOption(RUN_DATA_MIGRATION)) { >- runDataMigration(commandLine); >+ rValue = Math.max(rValue, runDataMigration(commandLine)); > } >- >+ return rValue; > } > >- private void runDataMigration(CommandLine rhqctlCommandLine) { >+ private int runDataMigration(CommandLine rhqctlCommandLine) { > > String migrationOption = rhqctlCommandLine.getOptionValue(RUN_DATA_MIGRATION); > >+ int rValue; >+ > if (migrationOption.equals("none")) { > log.info("No data migration will run"); > if (!isRhq48OrLater(rhqctlCommandLine)) { > printDataMigrationNotice(); > } >- return; >+ return RHQControl.EXIT_CODE_OK; > } > > // We deduct the database parameters from the server properties >@@ -253,23 +262,28 @@ public class Upgrade extends AbstractInstall { > } > > Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(new File(getBaseDir(), "bin")); // data migrator script is not in bin/internal >+ executor.setWorkingDirectory(getBinDir()); > executor.setStreamHandler(new PumpStreamHandler()); > > int exitValue = executor.execute(commandLine); > log.info("The data migrator finished with exit value " + exitValue); >+ rValue = exitValue; > } catch (Exception e) { > log.error("Running the data migrator failed - please try to run it from the command line: " > + e.getMessage()); >+ rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } >+ return rValue; > } > >- private void upgradeStorage(CommandLine rhqctlCommandLine) throws Exception { >+ private int upgradeStorage(CommandLine rhqctlCommandLine) throws Exception { > if (rhqctlCommandLine.hasOption(USE_REMOTE_STORAGE_NODE)) { > log.info("Ignoring storage node upgrade, a remote storage node is configured."); >- return; >+ return RHQControl.EXIT_CODE_OK; > } > >+ int rValue; >+ > // If upgrading from a pre-cassandra then just install an initial storage node. Otherwise, upgrade > if (isRhq48OrLater(rhqctlCommandLine)) { > try { >@@ -293,28 +307,30 @@ public class Upgrade extends AbstractInstall { > > int exitCode = executor.execute(commandLine); > log.info("The storage node upgrade has finished with an exit value of " + exitCode); >- >+ rValue = exitCode; > } catch (IOException e) { > log.error("An error occurred while running the storage node upgrade: " + e.getMessage()); > throw e; > } > > } else { >- installStorageNode(getStorageBasedir(), rhqctlCommandLine, true); >+ rValue = installStorageNode(getStorageBasedir(), rhqctlCommandLine, true); > } >+ return rValue; > } > >- private void upgradeServer(CommandLine commandLine) throws Exception { >+ private int upgradeServer(CommandLine commandLine) throws Exception { > // don't upgrade the server if this is a storage node only install > File oldServerDir = getFromServerDir(commandLine); > if (!(!isRhq48OrLater(commandLine) || isServerInstalled(oldServerDir))) { > log.info("Ignoring server upgrade, this is a storage node only installation."); >- return; >+ return RHQControl.EXIT_CODE_OK; > } > > // copy all the old settings into the new rhq-server.properties file > upgradeServerPropertiesFile(commandLine); > >+ int rValue = RHQControl.EXIT_CODE_OK; > // make sure we retain the oracle driver if one exists > try { > copyOracleDriver(oldServerDir); >@@ -323,6 +339,7 @@ public class Upgrade extends AbstractInstall { > + "The upgrade will continue but your server may not work if connecting to an Oracle database, " > + "in which case you will need to manually install an Oracle driver to your server. " + "Cause: " > + ThrowableUtil.getAllMessages(e)); >+ rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > > // copy over any wrapper.inc that may have been added >@@ -334,10 +351,10 @@ public class Upgrade extends AbstractInstall { > > // start the server, the invoke the installer and wait for the server to be completely installed > startRHQServerForInstallation(); >- runRHQServerInstaller(); >+ rValue = Math.max(rValue, runRHQServerInstaller()); > waitForRHQServerToInitialize(); > >- return; >+ return rValue; > } > > public void copyOracleDriver(File oldServerDir) throws IOException { >@@ -529,7 +546,7 @@ public class Upgrade extends AbstractInstall { > } > > // now merge the old settings in with the default properties from the new server install >- String newServerPropsFilePath = new File(getBaseDir(), "bin/rhq-server.properties").getAbsolutePath(); >+ String newServerPropsFilePath = new File(getBinDir(), "rhq-server.properties").getAbsolutePath(); > PropertiesFileUpdate newServerPropsFile = new PropertiesFileUpdate(newServerPropsFilePath); > newServerPropsFile.update(oldServerProps); > >@@ -606,7 +623,7 @@ public class Upgrade extends AbstractInstall { > return (null != path) ? path.replace('\\', '/') : null; > } > >- private void upgradeAgent(CommandLine rhqctlCommandLine) throws Exception { >+ private int upgradeAgent(CommandLine rhqctlCommandLine) throws Exception { > try { > File oldAgentDir; > if (rhqctlCommandLine.hasOption(FROM_AGENT_DIR_OPTION)) { >@@ -628,8 +645,7 @@ public class Upgrade extends AbstractInstall { > + " option specified and no agent found in the default location [" > + oldAgentDir.getAbsolutePath() > + "]. Installing agent in the default location as part of the upgrade."); >- installAgent(getAgentBasedir(), rhqctlCommandLine); >- return; >+ return installAgent(getAgentBasedir(), rhqctlCommandLine); > } > } > >@@ -687,6 +703,7 @@ public class Upgrade extends AbstractInstall { > }); > > log.info("The agent has been upgraded and placed in: " + agentBasedir); >+ return exitValue; > > } catch (IOException e) { > log.error("An error occurred while upgrading the agent: " + e.getMessage()); >-- >1.8.3.2 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 994250
:
783521
|
839282
|
842792
|
844599
|
844601
|
845114
|
866289