|
|
@ -16,25 +16,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.launchscript;
|
|
|
|
package org.springframework.boot.launchscript;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
import org.assertj.core.api.Condition;
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Assumptions;
|
|
|
|
import org.junit.jupiter.api.Assumptions;
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
import org.junit.jupiter.params.provider.MethodSource;
|
|
|
|
import org.junit.jupiter.params.provider.MethodSource;
|
|
|
|
import org.testcontainers.containers.GenericContainer;
|
|
|
|
|
|
|
|
import org.testcontainers.containers.output.ToStringConsumer;
|
|
|
|
|
|
|
|
import org.testcontainers.images.builder.ImageFromDockerfile;
|
|
|
|
|
|
|
|
import org.testcontainers.utility.MountableFile;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.ansi.AnsiColor;
|
|
|
|
import org.springframework.boot.ansi.AnsiColor;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Integration tests for Spring Boot's launch script on OSs that use SysVinit.
|
|
|
|
* Integration tests for Spring Boot's launch script on OSs that use SysVinit.
|
|
|
@ -42,14 +32,12 @@ import static org.hamcrest.Matchers.containsString;
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
* @author Ali Shahbour
|
|
|
|
* @author Ali Shahbour
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class SysVinitLaunchScriptIT {
|
|
|
|
class SysVinitLaunchScriptIT extends AbstractLaunchScriptIT {
|
|
|
|
|
|
|
|
|
|
|
|
private static final char ESC = 27;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void statusWhenStopped(String os, String version) throws Exception {
|
|
|
|
void statusWhenStopped(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "status-when-stopped.sh");
|
|
|
|
String output = doTest(os, version, "init.d/status-when-stopped.sh");
|
|
|
|
assertThat(output).contains("Status: 3");
|
|
|
|
assertThat(output).contains("Status: 3");
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.RED, "Not running"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.RED, "Not running"));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -57,7 +45,7 @@ class SysVinitLaunchScriptIT {
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void statusWhenStarted(String os, String version) throws Exception {
|
|
|
|
void statusWhenStarted(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "status-when-started.sh");
|
|
|
|
String output = doTest(os, version, "init.d/status-when-started.sh");
|
|
|
|
assertThat(output).contains("Status: 0");
|
|
|
|
assertThat(output).contains("Status: 0");
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -65,7 +53,7 @@ class SysVinitLaunchScriptIT {
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void statusWhenKilled(String os, String version) throws Exception {
|
|
|
|
void statusWhenKilled(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "status-when-killed.sh");
|
|
|
|
String output = doTest(os, version, "init.d/status-when-killed.sh");
|
|
|
|
assertThat(output).contains("Status: 1");
|
|
|
|
assertThat(output).contains("Status: 1");
|
|
|
|
assertThat(output)
|
|
|
|
assertThat(output)
|
|
|
|
.has(coloredString(AnsiColor.RED, "Not running (process " + extractPid(output) + " not found)"));
|
|
|
|
.has(coloredString(AnsiColor.RED, "Not running (process " + extractPid(output) + " not found)"));
|
|
|
@ -74,7 +62,7 @@ class SysVinitLaunchScriptIT {
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void stopWhenStopped(String os, String version) throws Exception {
|
|
|
|
void stopWhenStopped(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "stop-when-stopped.sh");
|
|
|
|
String output = doTest(os, version, "init.d/stop-when-stopped.sh");
|
|
|
|
assertThat(output).contains("Status: 0");
|
|
|
|
assertThat(output).contains("Status: 0");
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -82,7 +70,7 @@ class SysVinitLaunchScriptIT {
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void forceStopWhenStopped(String os, String version) throws Exception {
|
|
|
|
void forceStopWhenStopped(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "force-stop-when-stopped.sh");
|
|
|
|
String output = doTest(os, version, "init.d/force-stop-when-stopped.sh");
|
|
|
|
assertThat(output).contains("Status: 0");
|
|
|
|
assertThat(output).contains("Status: 0");
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -90,7 +78,7 @@ class SysVinitLaunchScriptIT {
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void startWhenStarted(String os, String version) throws Exception {
|
|
|
|
void startWhenStarted(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "start-when-started.sh");
|
|
|
|
String output = doTest(os, version, "init.d/start-when-started.sh");
|
|
|
|
assertThat(output).contains("Status: 0");
|
|
|
|
assertThat(output).contains("Status: 0");
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Already running [" + extractPid(output) + "]"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Already running [" + extractPid(output) + "]"));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -98,7 +86,7 @@ class SysVinitLaunchScriptIT {
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void restartWhenStopped(String os, String version) throws Exception {
|
|
|
|
void restartWhenStopped(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "restart-when-stopped.sh");
|
|
|
|
String output = doTest(os, version, "init.d/restart-when-stopped.sh");
|
|
|
|
assertThat(output).contains("Status: 0");
|
|
|
|
assertThat(output).contains("Status: 0");
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.YELLOW, "Not running (pidfile not found)"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
|
|
@ -107,7 +95,7 @@ class SysVinitLaunchScriptIT {
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void restartWhenStarted(String os, String version) throws Exception {
|
|
|
|
void restartWhenStarted(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "restart-when-started.sh");
|
|
|
|
String output = doTest(os, version, "init.d/restart-when-started.sh");
|
|
|
|
assertThat(output).contains("Status: 0");
|
|
|
|
assertThat(output).contains("Status: 0");
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extract("PID1", output) + "]"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extract("PID1", output) + "]"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Stopped [" + extract("PID1", output) + "]"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Stopped [" + extract("PID1", output) + "]"));
|
|
|
@ -117,7 +105,7 @@ class SysVinitLaunchScriptIT {
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void startWhenStopped(String os, String version) throws Exception {
|
|
|
|
void startWhenStopped(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "start-when-stopped.sh");
|
|
|
|
String output = doTest(os, version, "init.d/start-when-stopped.sh");
|
|
|
|
assertThat(output).contains("Status: 0");
|
|
|
|
assertThat(output).contains("Status: 0");
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -125,14 +113,14 @@ class SysVinitLaunchScriptIT {
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void basicLaunch(String os, String version) throws Exception {
|
|
|
|
void basicLaunch(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "basic-launch.sh");
|
|
|
|
String output = doTest(os, version, "init.d/basic-launch.sh");
|
|
|
|
assertThat(output).doesNotContain("PID_FOLDER");
|
|
|
|
assertThat(output).doesNotContain("PID_FOLDER");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void launchWithMissingLogFolderGeneratesAWarning(String os, String version) throws Exception {
|
|
|
|
void launchWithMissingLogFolderGeneratesAWarning(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "launch-with-missing-log-folder.sh");
|
|
|
|
String output = doTest(os, version, "init.d/launch-with-missing-log-folder.sh");
|
|
|
|
assertThat(output).has(
|
|
|
|
assertThat(output).has(
|
|
|
|
coloredString(AnsiColor.YELLOW, "LOG_FOLDER /does/not/exist does not exist. Falling back to /tmp"));
|
|
|
|
coloredString(AnsiColor.YELLOW, "LOG_FOLDER /does/not/exist does not exist. Falling back to /tmp"));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -140,7 +128,7 @@ class SysVinitLaunchScriptIT {
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void launchWithMissingPidFolderGeneratesAWarning(String os, String version) throws Exception {
|
|
|
|
void launchWithMissingPidFolderGeneratesAWarning(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "launch-with-missing-pid-folder.sh");
|
|
|
|
String output = doTest(os, version, "init.d/launch-with-missing-pid-folder.sh");
|
|
|
|
assertThat(output).has(
|
|
|
|
assertThat(output).has(
|
|
|
|
coloredString(AnsiColor.YELLOW, "PID_FOLDER /does/not/exist does not exist. Falling back to /tmp"));
|
|
|
|
coloredString(AnsiColor.YELLOW, "PID_FOLDER /does/not/exist does not exist. Falling back to /tmp"));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -148,43 +136,43 @@ class SysVinitLaunchScriptIT {
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void launchWithSingleCommandLineArgument(String os, String version) throws Exception {
|
|
|
|
void launchWithSingleCommandLineArgument(String os, String version) throws Exception {
|
|
|
|
doLaunch(os, version, "launch-with-single-command-line-argument.sh");
|
|
|
|
doLaunch(os, version, "init.d/launch-with-single-command-line-argument.sh");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void launchWithMultipleCommandLineArguments(String os, String version) throws Exception {
|
|
|
|
void launchWithMultipleCommandLineArguments(String os, String version) throws Exception {
|
|
|
|
doLaunch(os, version, "launch-with-multiple-command-line-arguments.sh");
|
|
|
|
doLaunch(os, version, "init.d/launch-with-multiple-command-line-arguments.sh");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void launchWithSingleRunArg(String os, String version) throws Exception {
|
|
|
|
void launchWithSingleRunArg(String os, String version) throws Exception {
|
|
|
|
doLaunch(os, version, "launch-with-single-run-arg.sh");
|
|
|
|
doLaunch(os, version, "init.d/launch-with-single-run-arg.sh");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void launchWithMultipleRunArgs(String os, String version) throws Exception {
|
|
|
|
void launchWithMultipleRunArgs(String os, String version) throws Exception {
|
|
|
|
doLaunch(os, version, "launch-with-multiple-run-args.sh");
|
|
|
|
doLaunch(os, version, "init.d/launch-with-multiple-run-args.sh");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void launchWithSingleJavaOpt(String os, String version) throws Exception {
|
|
|
|
void launchWithSingleJavaOpt(String os, String version) throws Exception {
|
|
|
|
doLaunch(os, version, "launch-with-single-java-opt.sh");
|
|
|
|
doLaunch(os, version, "init.d/launch-with-single-java-opt.sh");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void launchWithDoubleLinkSingleJavaOpt(String os, String version) throws Exception {
|
|
|
|
void launchWithDoubleLinkSingleJavaOpt(String os, String version) throws Exception {
|
|
|
|
doLaunch(os, version, "launch-with-double-link-single-java-opt.sh");
|
|
|
|
doLaunch(os, version, "init.d/launch-with-double-link-single-java-opt.sh");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void launchWithMultipleJavaOpts(String os, String version) throws Exception {
|
|
|
|
void launchWithMultipleJavaOpts(String os, String version) throws Exception {
|
|
|
|
doLaunch(os, version, "launch-with-multiple-java-opts.sh");
|
|
|
|
doLaunch(os, version, "init.d/launch-with-multiple-java-opts.sh");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
@ -192,13 +180,13 @@ class SysVinitLaunchScriptIT {
|
|
|
|
void launchWithUseOfStartStopDaemonDisabled(String os, String version) throws Exception {
|
|
|
|
void launchWithUseOfStartStopDaemonDisabled(String os, String version) throws Exception {
|
|
|
|
// CentOS doesn't have start-stop-daemon
|
|
|
|
// CentOS doesn't have start-stop-daemon
|
|
|
|
Assumptions.assumeFalse(os.equals("CentOS"));
|
|
|
|
Assumptions.assumeFalse(os.equals("CentOS"));
|
|
|
|
doLaunch(os, version, "launch-with-use-of-start-stop-daemon-disabled.sh");
|
|
|
|
doLaunch(os, version, "init.d/launch-with-use-of-start-stop-daemon-disabled.sh");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void launchWithRelativePidFolder(String os, String version) throws Exception {
|
|
|
|
void launchWithRelativePidFolder(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "launch-with-relative-pid-folder.sh");
|
|
|
|
String output = doTest(os, version, "init.d/launch-with-relative-pid-folder.sh");
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Started [" + extractPid(output) + "]"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Running [" + extractPid(output) + "]"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Running [" + extractPid(output) + "]"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Stopped [" + extractPid(output) + "]"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.GREEN, "Stopped [" + extractPid(output) + "]"));
|
|
|
@ -207,56 +195,56 @@ class SysVinitLaunchScriptIT {
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void pidFolderOwnership(String os, String version) throws Exception {
|
|
|
|
void pidFolderOwnership(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "pid-folder-ownership.sh");
|
|
|
|
String output = doTest(os, version, "init.d/pid-folder-ownership.sh");
|
|
|
|
assertThat(output).contains("phil root");
|
|
|
|
assertThat(output).contains("phil root");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void pidFileOwnership(String os, String version) throws Exception {
|
|
|
|
void pidFileOwnership(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "pid-file-ownership.sh");
|
|
|
|
String output = doTest(os, version, "init.d/pid-file-ownership.sh");
|
|
|
|
assertThat(output).contains("phil root");
|
|
|
|
assertThat(output).contains("phil root");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void logFileOwnership(String os, String version) throws Exception {
|
|
|
|
void logFileOwnership(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "log-file-ownership.sh");
|
|
|
|
String output = doTest(os, version, "init.d/log-file-ownership.sh");
|
|
|
|
assertThat(output).contains("phil root");
|
|
|
|
assertThat(output).contains("phil root");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void logFileOwnershipIsChangedWhenCreated(String os, String version) throws Exception {
|
|
|
|
void logFileOwnershipIsChangedWhenCreated(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "log-file-ownership-is-changed-when-created.sh");
|
|
|
|
String output = doTest(os, version, "init.d/log-file-ownership-is-changed-when-created.sh");
|
|
|
|
assertThat(output).contains("andy root");
|
|
|
|
assertThat(output).contains("andy root");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void logFileOwnershipIsUnchangedWhenExists(String os, String version) throws Exception {
|
|
|
|
void logFileOwnershipIsUnchangedWhenExists(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "log-file-ownership-is-unchanged-when-exists.sh");
|
|
|
|
String output = doTest(os, version, "init.d/log-file-ownership-is-unchanged-when-exists.sh");
|
|
|
|
assertThat(output).contains("root root");
|
|
|
|
assertThat(output).contains("root root");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void launchWithRelativeLogFolder(String os, String version) throws Exception {
|
|
|
|
void launchWithRelativeLogFolder(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "launch-with-relative-log-folder.sh");
|
|
|
|
String output = doTest(os, version, "init.d/launch-with-relative-log-folder.sh");
|
|
|
|
assertThat(output).contains("Log written");
|
|
|
|
assertThat(output).contains("Log written");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void launchWithRunAsUser(String os, String version) throws Exception {
|
|
|
|
void launchWithRunAsUser(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "launch-with-run-as-user.sh");
|
|
|
|
String output = doTest(os, version, "init.d/launch-with-run-as-user.sh");
|
|
|
|
assertThat(output).contains("wagner root");
|
|
|
|
assertThat(output).contains("wagner root");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void whenRunAsUserDoesNotExistLaunchFailsWithInvalidArgument(String os, String version) throws Exception {
|
|
|
|
void whenRunAsUserDoesNotExistLaunchFailsWithInvalidArgument(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "launch-with-run-as-invalid-user.sh");
|
|
|
|
String output = doTest(os, version, "init.d/launch-with-run-as-invalid-user.sh");
|
|
|
|
assertThat(output).contains("Status: 2");
|
|
|
|
assertThat(output).contains("Status: 2");
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.RED, "Cannot run as 'johndoe': no such user"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.RED, "Cannot run as 'johndoe': no such user"));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -264,7 +252,7 @@ class SysVinitLaunchScriptIT {
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@ParameterizedTest(name = "{0} {1}")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void whenJarOwnerAndRunAsUserAreBothSpecifiedRunAsUserTakesPrecedence(String os, String version) throws Exception {
|
|
|
|
void whenJarOwnerAndRunAsUserAreBothSpecifiedRunAsUserTakesPrecedence(String os, String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "launch-with-run-as-user-preferred-to-jar-owner.sh");
|
|
|
|
String output = doTest(os, version, "init.d/launch-with-run-as-user-preferred-to-jar-owner.sh");
|
|
|
|
assertThat(output).contains("wagner root");
|
|
|
|
assertThat(output).contains("wagner root");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -272,49 +260,11 @@ class SysVinitLaunchScriptIT {
|
|
|
|
@MethodSource("parameters")
|
|
|
|
@MethodSource("parameters")
|
|
|
|
void whenLaunchedUsingNonRootUserWithRunAsUserSpecifiedLaunchFailsWithInsufficientPrivilege(String os,
|
|
|
|
void whenLaunchedUsingNonRootUserWithRunAsUserSpecifiedLaunchFailsWithInsufficientPrivilege(String os,
|
|
|
|
String version) throws Exception {
|
|
|
|
String version) throws Exception {
|
|
|
|
String output = doTest(os, version, "launch-with-run-as-user-root-required.sh");
|
|
|
|
String output = doTest(os, version, "init.d/launch-with-run-as-user-root-required.sh");
|
|
|
|
assertThat(output).contains("Status: 4");
|
|
|
|
assertThat(output).contains("Status: 4");
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.RED, "Cannot run as 'wagner': current user is not root"));
|
|
|
|
assertThat(output).has(coloredString(AnsiColor.RED, "Cannot run as 'wagner': current user is not root"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static List<Object[]> parameters() {
|
|
|
|
|
|
|
|
List<Object[]> parameters = new ArrayList<>();
|
|
|
|
|
|
|
|
for (File os : new File("src/test/resources/conf").listFiles()) {
|
|
|
|
|
|
|
|
for (File version : os.listFiles()) {
|
|
|
|
|
|
|
|
parameters.add(new Object[] { os.getName(), version.getName() });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return parameters;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void doLaunch(String os, String version, String script) throws Exception {
|
|
|
|
|
|
|
|
assertThat(doTest(os, version, script)).contains("Launched");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String doTest(String os, String version, String script) throws Exception {
|
|
|
|
|
|
|
|
ToStringConsumer consumer = new ToStringConsumer().withRemoveAnsiCodes(false);
|
|
|
|
|
|
|
|
try (LaunchScriptTestContainer container = new LaunchScriptTestContainer(os, version, script)) {
|
|
|
|
|
|
|
|
container.withLogConsumer(consumer);
|
|
|
|
|
|
|
|
container.start();
|
|
|
|
|
|
|
|
while (container.isRunning()) {
|
|
|
|
|
|
|
|
Thread.sleep(100);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumer.toUtf8String();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Condition<String> coloredString(AnsiColor color, String string) {
|
|
|
|
|
|
|
|
String colorString = ESC + "[0;" + color + "m" + string + ESC + "[0m";
|
|
|
|
|
|
|
|
return new Condition<String>() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean matches(String value) {
|
|
|
|
|
|
|
|
return containsString(colorString).matches(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String extractPid(String output) {
|
|
|
|
private String extractPid(String output) {
|
|
|
|
return extract("PID", output);
|
|
|
|
return extract("PID", output);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -328,32 +278,4 @@ class SysVinitLaunchScriptIT {
|
|
|
|
throw new IllegalArgumentException("Failed to extract " + label + " from output: " + output);
|
|
|
|
throw new IllegalArgumentException("Failed to extract " + label + " from output: " + output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final class LaunchScriptTestContainer extends GenericContainer<LaunchScriptTestContainer> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private LaunchScriptTestContainer(String os, String version, String testScript) {
|
|
|
|
|
|
|
|
super(new ImageFromDockerfile("spring-boot-launch-script/" + os.toLowerCase() + "-" + version)
|
|
|
|
|
|
|
|
.withFileFromFile("Dockerfile",
|
|
|
|
|
|
|
|
new File("src/test/resources/conf/" + os + "/" + version + "/Dockerfile"))
|
|
|
|
|
|
|
|
.withFileFromFile("spring-boot-launch-script-tests.jar", findApplication())
|
|
|
|
|
|
|
|
.withFileFromFile("test-functions.sh", new File("src/test/resources/scripts/test-functions.sh")));
|
|
|
|
|
|
|
|
withCopyFileToContainer(MountableFile.forHostPath("src/test/resources/scripts/" + testScript),
|
|
|
|
|
|
|
|
"/" + testScript);
|
|
|
|
|
|
|
|
withCommand("/bin/bash", "-c", "chmod +x " + testScript + " && ./" + testScript);
|
|
|
|
|
|
|
|
withStartupTimeout(Duration.ofMinutes(10));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static File findApplication() {
|
|
|
|
|
|
|
|
File targetDir = new File("target");
|
|
|
|
|
|
|
|
for (File file : targetDir.listFiles()) {
|
|
|
|
|
|
|
|
if (file.getName().startsWith("spring-boot-launch-script-tests") && file.getName().endsWith(".jar")
|
|
|
|
|
|
|
|
&& !file.getName().endsWith("-sources.jar")) {
|
|
|
|
|
|
|
|
return file;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new IllegalStateException(
|
|
|
|
|
|
|
|
"Could not find test application in target directory. Have you built it (mvn package)?");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|