Преглед на файлове

新增用腳本判斷服務是否重啟

chenweida преди 9 години
родител
ревизия
d9b15b7661

+ 1 - 1
Hos-Resource-Mini-Update/src/main/java/com/yihu/ehr/config/ThreadConfig.java

@ -32,7 +32,7 @@ public class ThreadConfig {
    public static String TOKEN_INFO = "{\"fingerprint\": \"abc\"}";
    public static String TOKEN_METHOD = "authorizations/clients/";
    public static String TOMCAT_SERVICENAME = "tomcat8-esb-service";
    public static String TOMCAT_SERVICENAME = "tomcat8-esb-ds";
    public static String SOFT_VERSIONCODE = "1";
    public static String SYSTEM_CODE = "";

+ 24 - 4
Hos-Resource-Mini-Update/src/main/java/com/yihu/ehr/thread/UpdateThread.java

@ -48,8 +48,7 @@ public class UpdateThread implements Runnable {
                        if (!StringUtils.isEmpty(filePath)) {
                            //关闭服務
                            closeService();
                            //睡眠五秒
                            Thread.sleep(1000 * 60);
                            //睡眠8秒
                            //解压
                            if (zipFile(filePath)) {
                                //启动服务
@ -166,10 +165,30 @@ public class UpdateThread implements Runnable {
                }
                fis.close();
                br.close();
                //判断是否服务是否关闭
                while (true) {
                    String batPath = UpdateThread.class.getResource("/").getPath() + "config/serviceAlive.bat";
                    Process ps = Runtime.getRuntime().exec(batPath);
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    InputStream os = ps.getInputStream();
                    byte b[] = new byte[256];
                    while (os.read(b) > 0)
                        baos.write(b);
                    String s = baos.toString();
                    System.out.println(s);
                    os.close();
                    baos.close();
                    if (Boolean.valueOf(s.trim())) {
                        break;
                    }
                    Thread.sleep(800L);
                }
            } else {
                LogUtil.info("重启linux服务");
                Runtime.getRuntime().exec("service " + ThreadConfig.TOMCAT_SERVICENAME + " stop");
                Thread.sleep(6000L);
            }
            LogUtil.info("关闭成功");
        } catch (Exception e) {
            LogUtil.error("关闭失败:" + e.getMessage());
@ -323,10 +342,11 @@ public class UpdateThread implements Runnable {
        return folderPath + fileName + ".war";
    }
    public static void main(String[] args) {
        getProcess();
    public static void main(String[] args) throws Exception {
    }
    public static boolean getProcess() {
        boolean flag = false;
        try {

+ 9 - 0
Hos-Resource-Mini-Update/src/main/resources/config/serviceAlive.bat

@ -0,0 +1,9 @@
@echo off
for /f "skip=3 tokens=4" %%i in ('sc query tomcat8-esb-service') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
    echo true
) else (
    echo false
)
exit