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

Commit

Permalink
[BZ 1112240] Remove pidfile detection from rhqctl and use rhq-agent-w…
Browse files Browse the repository at this point in the history
…rapper.sh / rhq-server.sh to do the logic of shutting down if necessary

(cherry picked from commit 33a783a)
Signed-off-by: Thomas Segismont <tsegismo@redhat.com>
  • Loading branch information
Michael Burman authored and tsegismont committed Aug 28, 2014
1 parent 3ee07af commit fdc9ed3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,41 +332,6 @@ protected String getStoragePid() throws IOException {
return null;
}

private File getPidFile(String pidFilename, File baseDir, String envVariable) {
File pidFile = null;
if(envVariable != null && envVariable.length() > 0) {
pidFile = new File(envVariable, pidFilename);
} else {
pidFile = new File(baseDir, pidFilename);
}
return pidFile;
}

protected String getServerPid() throws IOException {
String rhqServerPidDir = System.getenv(RHQ_SERVER_PIDFILE_DIR_ENV_VARIABLE);
String pidFilename = "rhq-server.pid";

File pidFile = getPidFile(pidFilename, binDir, rhqServerPidDir);

if (pidFile.exists()) {
return StreamUtil.slurp(new FileReader(pidFile));
}
return null;
}

protected String getAgentPid() throws IOException {
File agentBinDir = new File(getAgentBasedir(), "bin");
String rhqAgentPidDir = System.getenv(RHQ_AGENT_PIDFILE_DIR_ENV_VARIABLE);
String pidFilename = "rhq-agent.pid";

File pidFile = getPidFile(pidFilename, agentBinDir, rhqAgentPidDir);

if (pidFile.exists()) {
return StreamUtil.slurp(new FileReader(pidFile));
}
return null;
}

/**
* Returns a property from the rhqctl.properties file. If that optional file doesn't
* exist, the default value is returned. If the file exists but the key isn't found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,8 @@ protected int killAgent(File agentBasedir) throws Exception {
rValue = RHQControl.EXIT_CODE_OPERATION_FAILED;
}
} else {
String pid = getAgentPid();
if (pid != null) {
commandLine = getCommandLine("rhq-agent-wrapper", "kill");
rValue = Math.max(rValue, ExecutorAssist.execute(agentBinDir, commandLine));
}
commandLine = getCommandLine("rhq-agent-wrapper", "kill");
rValue = Math.max(rValue, ExecutorAssist.execute(agentBinDir, commandLine));
}
return rValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,8 @@ private int removeServerService() throws Exception {
rValue = RHQControl.EXIT_CODE_OPERATION_FAILED;
}
} else {
String pid = getServerPid();

if (pid != null) {
commandLine = getCommandLine("rhq-server", "stop");
rValue = ExecutorAssist.execute(getBinDir(), commandLine);
} else {
rValue = RHQControl.EXIT_CODE_OK;
}
commandLine = getCommandLine("rhq-server", "stop");
rValue = ExecutorAssist.execute(getBinDir(), commandLine);
}
return rValue;
}
Expand All @@ -201,14 +195,8 @@ private int removeAgentService() throws Exception {
rValue = RHQControl.EXIT_CODE_OPERATION_FAILED;
}
} else {
String pid = getAgentPid();

if (pid != null) {
commandLine = getCommandLine("rhq-agent-wrapper", "stop");
rValue = ExecutorAssist.execute(agentBinDir, commandLine);
} else {
rValue = RHQControl.EXIT_CODE_OK;
}
commandLine = getCommandLine("rhq-agent-wrapper", "stop");
rValue = ExecutorAssist.execute(agentBinDir, commandLine);
}
return rValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,9 @@ private int stopRHQServer() throws Exception {

org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-server", "stop");

int rValue;

if (isWindows()) {
rValue = ExecutorAssist.execute(getBinDir(), commandLine);
if(rValue != RHQControl.EXIT_CODE_OK) {
log.debug("Failed to stop server service");
}
} else {
String pid = getServerPid();

if (pid != null) {
rValue = ExecutorAssist.execute(getBinDir(), commandLine);
} else {
rValue = RHQControl.EXIT_CODE_OK;
}
int rValue = ExecutorAssist.execute(getBinDir(), commandLine);
if(rValue != RHQControl.EXIT_CODE_OK) {
log.debug("Failed to stop server service");
}
return rValue;
}
Expand All @@ -183,21 +171,9 @@ private int stopAgent() throws Exception {
File agentBinDir = new File(getAgentBasedir(), "bin");
org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-agent-wrapper", "stop");

int rValue;

if (isWindows()) {
rValue = ExecutorAssist.execute(agentBinDir, commandLine);
if(rValue != RHQControl.EXIT_CODE_OK) {
log.debug("Failed to stop agent service, return value" + rValue);
}
} else {
String pid = getAgentPid();

if (pid != null) {
rValue = ExecutorAssist.execute(agentBinDir, commandLine);
} else {
rValue = RHQControl.EXIT_CODE_OK;
}
int rValue = ExecutorAssist.execute(agentBinDir, commandLine);
if(rValue != RHQControl.EXIT_CODE_OK) {
log.debug("Failed to stop agent service, return value" + rValue);
}
return rValue;
}
Expand Down

0 comments on commit fdc9ed3

Please sign in to comment.