[Linux] Stop systemd services before installation
parent
9a0e00f474
commit
0c65ad04c7
|
@ -214,11 +214,11 @@ public class Installer {
|
|||
}
|
||||
|
||||
this.installFonts();
|
||||
this.finishInstallation();
|
||||
|
||||
if (error < 0) return;
|
||||
|
||||
System.out.println("\n" + Tr.get("installation_executionSuccessful") + "\n");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,7 +233,11 @@ public class Installer {
|
|||
p.waitFor(5, TimeUnit.SECONDS);
|
||||
|
||||
} else if (InstallConfig.getOsType() == OSType.LINUX) {
|
||||
Process p = new ProcessBuilder("bash", "-c", "pkill -9 -f '" + conf.getApplicationNameShort() + ".jar'").start();
|
||||
// If a service was installed previously try to stop it first. This will fail internal when no service was created
|
||||
Process p = new ProcessBuilder("bash", "-c", "systemctl stop \"" + conf.getApplicationNameShort() + ".service" + "\"").start();
|
||||
p.waitFor(5, TimeUnit.SECONDS);
|
||||
|
||||
p = new ProcessBuilder("bash", "-c", "pkill -9 -f '" + conf.getApplicationNameShort() + ".jar'").start();
|
||||
p.waitFor(5, TimeUnit.SECONDS);
|
||||
}
|
||||
} catch (Exception ex) { /* not required */ }
|
||||
|
@ -824,12 +828,12 @@ public class Installer {
|
|||
*/
|
||||
public void createUnitFile() {
|
||||
|
||||
// nothing to do (maybe create a windows service file when needed)
|
||||
// Nothing to do (maybe create a windows service file when needed)
|
||||
if (InstallConfig.getOsType() != OSType.LINUX) return;
|
||||
|
||||
try {
|
||||
|
||||
// check if systemd is present on the machine
|
||||
// Check if systemd is present on the machine
|
||||
String testCommand = "if [ -d /run/systemd/system/ ]; then echo yes; else echo no; fi";
|
||||
Process p = new ProcessBuilder("bash", "-c", testCommand).start();
|
||||
p.waitFor();
|
||||
|
@ -837,6 +841,10 @@ public class Installer {
|
|||
String output = buf.readLine();
|
||||
if (!output.equals("yes")) { logger.log("d", "systemd was nout found on the machine -> don't create a service unit", "registerApplication (create Unit File)"); return; }
|
||||
|
||||
// Try to stop an unit that is already running (it will be updated with the newest version of the unit file -> don't leave)
|
||||
p = new ProcessBuilder("bash", "-c", "systemctl stop \"" + conf.getApplicationNameShort() + ".service" + "\"").start();
|
||||
p.waitFor(5000, TimeUnit.SECONDS);
|
||||
|
||||
// create the unit file
|
||||
String s = "[Unit]\n";
|
||||
s += "Description=" + (conf.unitDescription == null ? conf.getApplicationNameShort() : conf.unitDescription) + "\n";
|
||||
|
@ -862,8 +870,8 @@ public class Installer {
|
|||
if (conf.serviceRestart != null) s += "Restart=" + conf.serviceRestart + "\n";
|
||||
if (conf.serviceRestartSec != null) s += "RestartSec=" + conf.serviceRestartSec + "\n";
|
||||
|
||||
// get all users for systemd configs: getent passwd | grep -v '/usr/sbin/nologin' | grep -v '/bin/false' | awk -F: '($6 != "" && ($3 > 10 || $3 == 0)) {print $6}'
|
||||
// for Linux only a installation as root is supported -> no user systemd entry
|
||||
// Get all users for systemd configs: getent passwd | grep -v '/usr/sbin/nologin' | grep -v '/bin/false' | awk -F: '($6 != "" && ($3 > 10 || $3 == 0)) {print $6}'.
|
||||
// For Linux only a installation as root is supported -> no user systemd entry
|
||||
String destination = "/etc/systemd/system/" + conf.getApplicationNameShort() + ".service";
|
||||
File createLink = new File(destination);
|
||||
|
||||
|
@ -1166,6 +1174,20 @@ public class Installer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will finish the installation by executing commands
|
||||
* that are only needed in edge cases.
|
||||
*/
|
||||
private void finishInstallation() {
|
||||
if (InstallConfig.getOsType() == OSType.LINUX) {
|
||||
try {
|
||||
// Try to start a previously installed service again that was stopped during installation
|
||||
Process p = new ProcessBuilder("bash", "-c", "systemctl start \"" + conf.getApplicationNameShort() + ".service" + "\"").start();
|
||||
p.waitFor(5, TimeUnit.SECONDS);
|
||||
} catch (Exception ex) { /* Not required */ }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the installation was successful (0 = successful, {@literal <}0 = error)
|
||||
*
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
root_rights_required=\
|
||||
For the installation of the program administrator / root privileges are required.\n\n\
|
||||
If you don't have these you can try to install the program portable or only for the currently logged in user [Windows].\n\
|
||||
For further help execute the program over the command line with the parameter "--help".
|
||||
If you don't have these you can try to install the program portable or only for the currently logged-in user [Windows].\n\
|
||||
For further help execute the program via the command line with the parameter "--help".
|
||||
root_askForRestart=\
|
||||
If you do have such rights the installation can be restarted automatically with root privileges.\n\
|
||||
Do you want to try to restart the program with root privileges (Y/N)?
|
||||
Would you like to try a restart of the program with root privileges (Y/N)?
|
||||
|
||||
userInstallation_notAvailable=A user installation is only available under windows
|
||||
userInstallation_notAvailable=A user installation is only available for windows
|
||||
|
||||
installation_start=Starting the installation of {0} (version {1})
|
||||
installation_architekture=Determine architecture and operating system
|
||||
|
@ -14,7 +14,7 @@ installation_architekture=Determine architecture and operating system
|
|||
installation_download=Downloading file
|
||||
installation_download_success=Downloading file: successful downloaded
|
||||
installation_download_invalid=The given file is invalid!
|
||||
installation_download_failed=An error occured while downloading the file.\nPlease check your Internet connection and try again later (URL: {0})
|
||||
installation_download_failed=An error occurred while downloading the file.\nPlease check your Internet connection and try again later (URL: {0})
|
||||
installation_download_urlNotFound=The determined URL was not found (URL: {0});
|
||||
|
||||
installation_portable_start=Program will be installed in the directory: "{0}"
|
||||
|
|
Loading…
Reference in New Issue