Skip to content

Commit 380106f

Browse files
committed
Append output of stop command to avoid clearing output file
Request: MO Change-Id: Ifc6e5dc4a3e47510bdc34a78ec9187f179b3fff9
1 parent 2cb7001 commit 380106f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pcu/src/main/java/io/bdeploy/pcu/ProcessController.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.File;
44
import java.io.IOException;
55
import java.io.OutputStream;
6+
import java.lang.ProcessBuilder.Redirect;
67
import java.lang.ProcessHandle.Info;
78
import java.nio.charset.StandardCharsets;
89
import java.nio.file.Files;
@@ -400,7 +401,7 @@ private void doStart(boolean resetRecoverCount) {
400401
}
401402

402403
try {
403-
Process p = launch(processConfig.start);
404+
Process p = launch(processConfig.start, false);
404405
process = p.toHandle();
405406
processStdin = p.getOutputStream();
406407
processExit = process.onExit();
@@ -773,13 +774,17 @@ private void doCheckUptime() {
773774
* @return the process handle
774775
* @throws IOException in case of an error starting the {@link Process}.
775776
*/
776-
private Process launch(List<String> cmd) throws IOException {
777+
private Process launch(List<String> cmd, boolean append) throws IOException {
777778
List<String> command = replaceVariables(cmd);
778779
logger.log(l -> l.debug("Launching new process {}", command));
779780

780781
ProcessBuilder b = new ProcessBuilder(command).directory(processDir.toFile());
781782
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+
}
783788
return b.start();
784789
}
785790

@@ -825,7 +830,7 @@ private void doInvokeStopCommand(List<String> stopCommand) {
825830
}
826831
try {
827832
logger.log(l -> l.info("Invoking configured stop command {}.", stopCommand));
828-
Process p = launch(stopCommand);
833+
Process p = launch(stopCommand, true);
829834
boolean exited = p.waitFor(processConfig.processControl.gracePeriod, TimeUnit.MILLISECONDS);
830835
if (!exited) {
831836
// stop command did not complete within allowed time, kill both

0 commit comments

Comments
 (0)