|
3 | 3 | import java.io.File;
|
4 | 4 | import java.io.IOException;
|
5 | 5 | import java.io.OutputStream;
|
| 6 | +import java.lang.ProcessBuilder.Redirect; |
6 | 7 | import java.lang.ProcessHandle.Info;
|
7 | 8 | import java.nio.charset.StandardCharsets;
|
8 | 9 | import java.nio.file.Files;
|
@@ -400,7 +401,7 @@ private void doStart(boolean resetRecoverCount) {
|
400 | 401 | }
|
401 | 402 |
|
402 | 403 | try {
|
403 |
| - Process p = launch(processConfig.start); |
| 404 | + Process p = launch(processConfig.start, false); |
404 | 405 | process = p.toHandle();
|
405 | 406 | processStdin = p.getOutputStream();
|
406 | 407 | processExit = process.onExit();
|
@@ -773,13 +774,17 @@ private void doCheckUptime() {
|
773 | 774 | * @return the process handle
|
774 | 775 | * @throws IOException in case of an error starting the {@link Process}.
|
775 | 776 | */
|
776 |
| - private Process launch(List<String> cmd) throws IOException { |
| 777 | + private Process launch(List<String> cmd, boolean append) throws IOException { |
777 | 778 | List<String> command = replaceVariables(cmd);
|
778 | 779 | logger.log(l -> l.debug("Launching new process {}", command));
|
779 | 780 |
|
780 | 781 | ProcessBuilder b = new ProcessBuilder(command).directory(processDir.toFile());
|
781 | 782 | b.redirectErrorStream(true);
|
782 |
| - b.redirectOutput(processDir.resolve(OUT_TXT).toFile()); |
| 783 | + if (append) { |
| 784 | + b.redirectOutput(Redirect.appendTo(processDir.resolve(OUT_TXT).toFile())); |
| 785 | + } else { |
| 786 | + b.redirectOutput(Redirect.to(processDir.resolve(OUT_TXT).toFile())); |
| 787 | + } |
783 | 788 | return b.start();
|
784 | 789 | }
|
785 | 790 |
|
@@ -825,7 +830,7 @@ private void doInvokeStopCommand(List<String> stopCommand) {
|
825 | 830 | }
|
826 | 831 | try {
|
827 | 832 | logger.log(l -> l.info("Invoking configured stop command {}.", stopCommand));
|
828 |
| - Process p = launch(stopCommand); |
| 833 | + Process p = launch(stopCommand, true); |
829 | 834 | boolean exited = p.waitFor(processConfig.processControl.gracePeriod, TimeUnit.MILLISECONDS);
|
830 | 835 | if (!exited) {
|
831 | 836 | // stop command did not complete within allowed time, kill both
|
|
0 commit comments