Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
BZ 690957 EWS Tomcat installed from RPM shutdown fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfclere committed Jun 18, 2014
1 parent e9f8a8f commit 7c80101
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public class TomcatDiscoveryComponent implements ResourceDiscoveryComponent, Man
/**
* EWS RPM Install path substrings used to identify EWS tomcat version
*/
public static final String EWS_TOMCAT_8 = "tomcat8";
public static final String EWS_TOMCAT_7 = "tomcat7";
public static final String EWS_TOMCAT_6 = "tomcat6";
public static final String EWS_TOMCAT_5 = "tomcat5";
Expand Down Expand Up @@ -571,18 +572,41 @@ private static boolean isEWS(String catalinaHome) {
public static boolean isEWSTomcat5(String catalinaHome) {
return (isEWS(catalinaHome) && catalinaHome.endsWith(EWS_TOMCAT_5));
}

public static boolean isEWSTomcat6(String catalinaHome) {
return (isEWS(catalinaHome) && catalinaHome.endsWith(EWS_TOMCAT_6));
}
public static boolean isEWSTomcat7(String catalinaHome) {
return (isEWS(catalinaHome) && catalinaHome.endsWith(EWS_TOMCAT_7));
}
public static boolean isEWSTomcat8(String catalinaHome) {
return (isEWS(catalinaHome) && catalinaHome.endsWith(EWS_TOMCAT_8));
}

public static boolean isRPMTomcat5(String catalinaHome) {
return catalinaHome.endsWith(EWS_TOMCAT_5);
}

public static boolean isRPMTomcat6(String catalinaHome) {
return catalinaHome.endsWith(EWS_TOMCAT_6);
}
public static boolean isRPMTomcat7(String catalinaHome) {
return catalinaHome.endsWith(EWS_TOMCAT_7);
}
public static boolean isRPMTomcat8(String catalinaHome) {
return catalinaHome.endsWith(EWS_TOMCAT_8);
}

public static boolean isTomcat5(String catalinaHome) {
return (catalinaHome.endsWith(EWS_TOMCAT_5) || catalinaHome.contains("5.0"));
}
public static boolean isTomcat6(String catalinaHome) {
return (catalinaHome.endsWith(EWS_TOMCAT_6) || catalinaHome.contains("6.0"));
}
public static boolean isTomcat7(String catalinaHome) {
return (catalinaHome.endsWith(EWS_TOMCAT_7) || catalinaHome.contains("7.0"));
}
public static boolean isTomcat8(String catalinaHome) {
return (catalinaHome.endsWith(EWS_TOMCAT_8) || catalinaHome.contains("8.0"));
}

private void populateJMXConfiguration(Configuration configuration, String[] commandLine) {
// null for manual add, properties will already be set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.core.pluginapi.util.ProcessExecutionUtility;
import org.rhq.core.system.OperatingSystemType;
import org.rhq.core.system.ProcessExecution;
import org.rhq.core.system.ProcessExecutionResults;
import org.rhq.core.system.SystemInfo;
Expand Down Expand Up @@ -178,7 +179,7 @@ private String start(PropertyList environment) throws InterruptedException {
Integer exitCode = results.getExitCode();
AvailabilityType avail;

if (startScriptFailed(controlMethod, error, exitCode)) {
if (startScriptFailed(controlMethod, error, exitCode, isWindows())) {
String output = results.getCapturedOutput();
String message = "Script returned error or non-zero exit code while starting the Tomcat instance - exitCode=["
+ ((exitCode != null) ? exitCode : "UNKNOWN") + "], output=[" + output + "].";
Expand All @@ -200,11 +201,11 @@ private String start(PropertyList environment) throws InterruptedException {
}
}

private static boolean startScriptFailed(ControlMethod controlMethod, Throwable error, Integer exitCode) {
private static boolean startScriptFailed(ControlMethod controlMethod, Throwable error, Integer exitCode, boolean isWindows) {
if (error != null || exitCode == null) {
return true;
}
if (controlMethod == ControlMethod.SCRIPT && isWindows()) {
if (controlMethod == ControlMethod.SCRIPT && isWindows) {
// Believe it or not, an exit code of 1 from startup.bat does not indicate an error.
return exitCode != 0 && exitCode != 1;
} else {
Expand Down Expand Up @@ -252,15 +253,23 @@ private ProcessExecution getScriptStart(Configuration pluginConfiguration) {
private ProcessExecution getRpmStart(Configuration pluginConfiguration) {
ProcessExecution processExecution;
String catalinaHome = this.serverComponent.getCatalinaHome().getPath();
String rpm = TomcatDiscoveryComponent.isRPMTomcat6(catalinaHome) ? TomcatDiscoveryComponent.EWS_TOMCAT_6
: TomcatDiscoveryComponent.EWS_TOMCAT_5;

processExecution = new ProcessExecution("service");
// disable the executable existence check because it is a command on the supplied PATH
processExecution.setCheckExecutableExists(false);
processExecution.setArguments(new ArrayList<String>());
processExecution.getArguments().add(rpm);
processExecution.getArguments().add("start");
String rpm = getTomcatServiceNum(catalinaHome);

if (isWindows()) {
processExecution = new ProcessExecution("net");
// disable the executable existence check because it is a command on the supplied PATH
processExecution.setCheckExecutableExists(false);
processExecution.setArguments(new ArrayList<String>());
processExecution.getArguments().add("start");
processExecution.getArguments().add(rpm);
} else {
processExecution = new ProcessExecution("service");
// disable the executable existence check because it is a command on the supplied PATH
processExecution.setCheckExecutableExists(false);
processExecution.setArguments(new ArrayList<String>());
processExecution.getArguments().add(rpm);
processExecution.getArguments().add("start");
}

Map<String, String> envVars = new LinkedHashMap<String, String>(System.getenv());
processExecution.setEnvironmentVariables(envVars);
Expand Down Expand Up @@ -292,6 +301,7 @@ private String shutdown(PropertyList environment) throws InterruptedException {
*/
private String doShutdown(PropertyList environment) {
Configuration pluginConfiguration = this.serverComponent.getPluginConfiguration();
// NOTE: In TomcatDiscoveryComponent.java we set TomcatServerComponent.PLUGIN_CONFIG_SHUTDOWN_SCRIPT (amongst others).
String controlMethod = pluginConfiguration.getSimpleValue(TomcatServerComponent.PLUGIN_CONFIG_CONTROL_METHOD,
ControlMethod.SCRIPT.name());
ProcessExecution processExecution = (ControlMethod.SCRIPT.name().equals(controlMethod)) ? getScriptShutdown(pluginConfiguration)
Expand Down Expand Up @@ -332,18 +342,37 @@ private ProcessExecution getScriptShutdown(Configuration pluginConfiguration) {
return processExecution;
}

private static String getTomcatServiceNum(String catalinaHome) {
String rpm = TomcatDiscoveryComponent.EWS_TOMCAT_8;
if (TomcatDiscoveryComponent.isTomcat7(catalinaHome))
rpm = TomcatDiscoveryComponent.EWS_TOMCAT_7;
if (TomcatDiscoveryComponent.isTomcat6(catalinaHome))
rpm = TomcatDiscoveryComponent.EWS_TOMCAT_6;
if (TomcatDiscoveryComponent.isTomcat5(catalinaHome))
rpm = TomcatDiscoveryComponent.EWS_TOMCAT_5;
return rpm;
}

private ProcessExecution getRpmShutdown() {
ProcessExecution processExecution;
String catalinaHome = this.serverComponent.getCatalinaHome().getPath();
String rpm = TomcatDiscoveryComponent.isRPMTomcat6(catalinaHome) ? TomcatDiscoveryComponent.EWS_TOMCAT_6
: TomcatDiscoveryComponent.EWS_TOMCAT_5;

processExecution = new ProcessExecution("service");
// disable the executable existence check because it is a command on the supplied PATH
processExecution.setCheckExecutableExists(false);
processExecution.setArguments(new ArrayList<String>());
processExecution.getArguments().add(rpm);
processExecution.getArguments().add("stop");
String rpm = getTomcatServiceNum(catalinaHome);

if (isWindows()) {
processExecution = new ProcessExecution("net");
// disable the executable existence check because it is a command on the supplied PATH
processExecution.setCheckExecutableExists(false);
processExecution.setArguments(new ArrayList<String>());
processExecution.getArguments().add("stop");
processExecution.getArguments().add(rpm);
} else {
processExecution = new ProcessExecution("service");
// disable the executable existence check because it is a command on the supplied PATH
processExecution.setCheckExecutableExists(false);
processExecution.setArguments(new ArrayList<String>());
processExecution.getArguments().add(rpm);
processExecution.getArguments().add("stop");
}

Map<String, String> envVars = new LinkedHashMap<String, String>(System.getenv());
log.info("Operation Envs: " + envVars);
Expand Down Expand Up @@ -545,4 +574,4 @@ private static void applyEnvironmentVars(PropertyList environment, ProcessExecut
private static boolean isWindows() {
return File.separatorChar == '\\';
}
}
}

0 comments on commit 7c80101

Please sign in to comment.