Bläddra i källkod

1.使用 bash 的绝对路径
2.调整 log 的输出格式

reghao 1 år sedan
förälder
incheckning
3f7a5a7fca
1 ändrade filer med 7 tillägg och 4 borttagningar
  1. 7 4
      deployer/src/main/java/cn/reghao/devops/deployer/util/Sftp.java

+ 7 - 4
deployer/src/main/java/cn/reghao/devops/deployer/util/Sftp.java

@@ -19,6 +19,7 @@ import java.util.Objects;
 @Slf4j
 public class Sftp {
     private final TextFile textFile = new TextFile();
+    private final String bash = "/usr/bin/bash";
 
     public Session getSession(RemoteHost remoteHost) throws Exception {
         String host = remoteHost.getHost();
@@ -207,10 +208,11 @@ public class Sftp {
         Session session = getSession(remoteHost);
         boolean exist = mkdir(session, remoteDir);
         if (exist) {
-            String command = String.format("cd %s && sh shutdown.sh", remoteDir);
+            String command = String.format("cd %s && %s shutdown.sh", remoteDir, bash);
             ShellResult shellResult = exec(session, command);
             if (!shellResult.isSuccess()) {
-                log.info("shutdown application failed: {} - {}", shellResult.getExitCode(), shellResult.getResult());
+                log.info("shutdown application failed\nexitCode {}\nmsg:{}", shellResult.getExitCode(), shellResult.getResult());
+                System.exit(-1);
             } else {
                 log.info("shutdown application successfully");
             }
@@ -221,10 +223,11 @@ public class Sftp {
         upload(session, localDir, remoteDir);
         log.info("files uploaded");
 
-        String command = String.format("cd %s && sh start.sh", remoteDir);
+        String command = String.format("cd %s && %s start.sh", remoteDir, bash);
         ShellResult shellResult = exec(session, command);
         if (!shellResult.isSuccess()) {
-            log.info("start application failed: {} - {}", shellResult.getExitCode(), shellResult.getResult());
+            log.info("start application failed\nexitCode {}\nmsg:{}", shellResult.getExitCode(), shellResult.getResult());
+            System.exit(-1);
         } else {
             log.info("start application successfully");
         }