From b5578bde1c05f534a1aa193be9ce3d16f370b26b Mon Sep 17 00:00:00 2001 From: Philip Marzullo Date: Tue, 16 Jun 2020 12:43:59 -0400 Subject: [PATCH] 0004171: Upgrade from 3.9.18 to 3.11.0 -> Symmetric Services shows not installed even though it is --- .../symmetric/wrapper/UnixService.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/symmetric-wrapper/src/main/java/org/jumpmind/symmetric/wrapper/UnixService.java b/symmetric-wrapper/src/main/java/org/jumpmind/symmetric/wrapper/UnixService.java index 34a8138570..77c3e12b2b 100644 --- a/symmetric-wrapper/src/main/java/org/jumpmind/symmetric/wrapper/UnixService.java +++ b/symmetric-wrapper/src/main/java/org/jumpmind/symmetric/wrapper/UnixService.java @@ -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")))) @@ -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() : @@ -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); @@ -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(); } @@ -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 @@ -287,7 +289,7 @@ protected void killProcess(int pid, boolean isTerminate) { private ArrayList getServiceCommand(String command) { ArrayList s = new ArrayList(); - String runFile = INITD_DIR + "/" + config.getName(); + String runFile = getInitdRunFile(); s.add(runFile); s.add(command); return s; @@ -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())); @@ -424,7 +426,7 @@ protected void stopProcesses(boolean isStopAbandoned) { } } - if(isSystemdRunning()) { + if(isSystemdRunning() && new File(getSystemdScriptFile()).exists()) { if(shouldRunService()) { runServiceCommand(getSystemdCommand(SYSTEMD_SCRIPT_STOP, config.getName())); } else {