fix:升级脚本

This commit is contained in:
waner
2026-05-13 16:15:48 +08:00
parent c3465dbb2a
commit c55ae9a35e
2 changed files with 40 additions and 3 deletions
@@ -228,9 +228,7 @@ public class UpgradeTaskRunner {
*/
protected void triggerDetachedTmsRestart(Path logPath, boolean rollback) throws IOException {
String phase = rollback ? "rollback" : "upgrade";
String command = "nohup /home/tms/scripts/tms.sh restart >> "
+ shellQuote(logPath.toString())
+ " 2>&1 < /dev/null &";
String command = buildDetachedTmsRestartCommand(logPath);
Process shell = new ProcessBuilder("bash", "-lc", command)
.redirectErrorStream(true)
.redirectOutput(Redirect.appendTo(logPath.toFile()))
@@ -246,6 +244,25 @@ public class UpgradeTaskRunner {
}
}
String buildDetachedTmsRestartCommand(Path logPath) {
return "nohup bash -lc "
+ shellQuote("set -e; "
+ "APP_HOME=\"${APP_HOME:-/home/tms}\"; "
+ "RUN_DIR=\"${RUN_DIR:-${APP_HOME}/run}\"; "
+ "PENDING_META=\"${RUN_DIR}/tms-upgrade.pending-jar\"; "
+ "\"${APP_HOME}/scripts/tms.sh\" stop; "
+ "if [ -s \"${PENDING_META}\" ]; then "
+ "PENDING_JAR=\"$(cat \"${PENDING_META}\")\"; "
+ "test -s \"${PENDING_JAR}\"; "
+ "cp \"${PENDING_JAR}\" \"${APP_HOME}/tms-framework.jar\"; "
+ "rm -f \"${PENDING_META}\" \"${RUN_DIR}/tms-framework.jar.pending\"; "
+ "fi; "
+ "\"${APP_HOME}/scripts/tms.sh\" start")
+ " >> "
+ shellQuote(logPath.toString())
+ " 2>&1 < /dev/null &";
}
private void writeLogLine(Path logPath, String message) throws IOException {
Files.writeString(
logPath,