Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.11' into 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
philipmarzullo64 committed Jun 16, 2020
2 parents b088243 + b5578bd commit cf72ebe
Showing 1 changed file with 19 additions and 17 deletions.
Expand Up @@ -88,7 +88,7 @@ private boolean isSystemdRunning() {
}

private void installSystemd() {
String runFile = SYSTEMD_INSTALL_DIR + "/" + config.getName() + ".service";
String runFile = getSystemdScriptFile();
try(FileWriter writer = new FileWriter(runFile);
BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(
"/symmetricds.systemd"))))
Expand All @@ -110,6 +110,14 @@ private void installSystemd() {
runServiceCommand(getSystemdCommand(SYSTEMD_SCRIPT_ENABLE, config.getName()));
}

private String getSystemdScriptFile() {
return SYSTEMD_INSTALL_DIR + "/" + config.getName() + ".service";
}

private String getInitdRunFile() {
return INITD_DIR + "/" + config.getName();
}

private String getWrapperPidFile() throws IOException {
// Make location absolute (starting with / )
return (config.getWrapperPidFile() != null && config.getWrapperPidFile().startsWith("/") ? config.getWrapperPidFile() :
Expand All @@ -118,7 +126,7 @@ private String getWrapperPidFile() throws IOException {

private void installInitd() {
String rcDir = getRunCommandDir();
String runFile = INITD_DIR + "/" + config.getName();
String runFile = getInitdRunFile();

try {
FileWriter writer = new FileWriter(runFile);
Expand Down Expand Up @@ -162,24 +170,21 @@ public void uninstall() {

System.out.println("Uninstalling " + config.getName() + " ...");

if(isSystemdRunning()) {
uninstallSystemd();
} else {
uninstallInitd();
}
uninstallSystemd();
uninstallInitd();

System.out.println("Done");
}

private void uninstallSystemd() {
runServiceCommand(getSystemdCommand(SYSTEMD_SCRIPT_DISABLE, config.getName()));
String runFile = SYSTEMD_INSTALL_DIR + "/" + config.getName() + ".service";
String runFile = getSystemdScriptFile();
new File(runFile).delete();
}

private void uninstallInitd() {
String rcDir = getRunCommandDir();
String runFile = INITD_DIR + "/" + config.getName();
String runFile = getInitdRunFile();
for (String runLevel : RUN_LEVELS_START) {
new File(rcDir + "/rc" + runLevel + ".d/S" + RUN_SEQUENCE_START + config.getName()).delete();
}
Expand Down Expand Up @@ -208,11 +213,8 @@ public boolean isPrivileged() {

@Override
public boolean isInstalled() {
if(isSystemdRunning()) {
return new File(SYSTEMD_INSTALL_DIR + "/" + config.getName() + ".service").exists();
} else {
return new File(INITD_DIR + "/" + config.getName()).exists();
}
return (new File(getSystemdScriptFile()).exists() ||
new File(getInitdRunFile()).exists());
}

@Override
Expand Down Expand Up @@ -287,7 +289,7 @@ protected void killProcess(int pid, boolean isTerminate) {

private ArrayList<String> getServiceCommand(String command) {
ArrayList<String> s = new ArrayList<String>();
String runFile = INITD_DIR + "/" + config.getName();
String runFile = getInitdRunFile();
s.add(runFile);
s.add(command);
return s;
Expand All @@ -314,7 +316,7 @@ public void start() {
stopProcesses(true);
System.out.println("Waiting for server to start");

if(isSystemdRunning()) {
if(isSystemdRunning() && new File(getSystemdScriptFile()).exists()) {
boolean success = true;
if(shouldRunService()) {
success = runServiceCommand(getSystemdCommand(SYSTEMD_SCRIPT_START, config.getName()));
Expand Down Expand Up @@ -426,7 +428,7 @@ protected void stopProcesses(boolean isStopAbandoned) {
}
}

if(isSystemdRunning()) {
if(isSystemdRunning() && new File(getSystemdScriptFile()).exists()) {
if(shouldRunService()) {
runServiceCommand(getSystemdCommand(SYSTEMD_SCRIPT_STOP, config.getName()));
} else {
Expand Down

0 comments on commit cf72ebe

Please sign in to comment.