fix:升级脚本
This commit is contained in:
parent
c3465dbb2a
commit
c55ae9a35e
@ -228,9 +228,7 @@ public class UpgradeTaskRunner {
|
|||||||
*/
|
*/
|
||||||
protected void triggerDetachedTmsRestart(Path logPath, boolean rollback) throws IOException {
|
protected void triggerDetachedTmsRestart(Path logPath, boolean rollback) throws IOException {
|
||||||
String phase = rollback ? "rollback" : "upgrade";
|
String phase = rollback ? "rollback" : "upgrade";
|
||||||
String command = "nohup /home/tms/scripts/tms.sh restart >> "
|
String command = buildDetachedTmsRestartCommand(logPath);
|
||||||
+ shellQuote(logPath.toString())
|
|
||||||
+ " 2>&1 < /dev/null &";
|
|
||||||
Process shell = new ProcessBuilder("bash", "-lc", command)
|
Process shell = new ProcessBuilder("bash", "-lc", command)
|
||||||
.redirectErrorStream(true)
|
.redirectErrorStream(true)
|
||||||
.redirectOutput(Redirect.appendTo(logPath.toFile()))
|
.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 {
|
private void writeLogLine(Path logPath, String message) throws IOException {
|
||||||
Files.writeString(
|
Files.writeString(
|
||||||
logPath,
|
logPath,
|
||||||
|
|||||||
@ -173,6 +173,26 @@ class UpgradeTaskRunnerTest {
|
|||||||
Assertions.assertTrue(log.contains("scheduling detached TMS restart"));
|
Assertions.assertTrue(log.contains("scheduling detached TMS restart"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void detachedTmsRestartCommandAppliesPendingJarAfterStopAndBeforeStart() throws Exception {
|
||||||
|
UpgradeTaskRunner runner = new UpgradeTaskRunner(
|
||||||
|
new InMemoryUpgradeTaskRepository(),
|
||||||
|
new InMemoryFileRecordRepository(),
|
||||||
|
new InMemoryDeviceSoftwareVersionRepository(),
|
||||||
|
stagingService(Files.createTempDirectory("upgrade-staging"), Files.createTempDirectory("upgrade-logs")),
|
||||||
|
properties(Files.createTempDirectory("upgrade-staging-props"), Files.createTempDirectory("upgrade-logs-props")),
|
||||||
|
objectMapper
|
||||||
|
);
|
||||||
|
|
||||||
|
String command = runner.buildDetachedTmsRestartCommand(Path.of("/home/tms/tmp/tms-upgrade-logs/UPG-001.log"));
|
||||||
|
|
||||||
|
Assertions.assertTrue(command.contains("PENDING_META"));
|
||||||
|
Assertions.assertTrue(command.contains("tms-upgrade.pending-jar"));
|
||||||
|
Assertions.assertTrue(command.contains("cp \"${PENDING_JAR}\" \"${APP_HOME}/tms-framework.jar\""));
|
||||||
|
Assertions.assertTrue(command.indexOf("\"${APP_HOME}/scripts/tms.sh\" stop") < command.indexOf("cp \"${PENDING_JAR}\""));
|
||||||
|
Assertions.assertTrue(command.indexOf("cp \"${PENDING_JAR}\"") < command.indexOf("\"${APP_HOME}/scripts/tms.sh\" start"));
|
||||||
|
}
|
||||||
|
|
||||||
private UpgradeProperties properties(Path stagingRoot, Path logDir) {
|
private UpgradeProperties properties(Path stagingRoot, Path logDir) {
|
||||||
UpgradeProperties properties = new UpgradeProperties();
|
UpgradeProperties properties = new UpgradeProperties();
|
||||||
properties.setStagingRootDir(stagingRoot.toString());
|
properties.setStagingRootDir(stagingRoot.toString());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user