{"id":1268,"date":"2021-02-18T01:26:00","date_gmt":"2021-02-17T17:26:00","guid":{"rendered":"http:\/\/diuut.com\/?p=1268"},"modified":"2021-02-21T04:31:02","modified_gmt":"2021-02-20T20:31:02","slug":"%e5%9f%ba%e4%ba%8ejsch%e7%9a%84%e7%ae%80%e6%98%93%e6%9c%8d%e5%8a%a1%e7%9b%91%e6%8e%a7%e6%9c%8d%e5%8a%a1-watchdog","status":"publish","type":"post","link":"https:\/\/diuut.com\/?p=1268","title":{"rendered":"\u57fa\u4e8eJSCH\u7684\u7b80\u6613\u670d\u52a1\u76d1\u63a7\u670d\u52a1-WatchDog"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\"><p>\u9700\u6c42\uff1a<\/p><cite>\u7a0b\u5e8f\u51fabug\u5728\u6240\u96be\u514d\uff0c\u4e3a\u51cf\u5c11\u51fa\u95ee\u9898\u65f6\u5bfc\u81f4\u7528\u6237\u65e0\u6cd5\u6b63\u5e38\u4f7f\u7528\u7684\u65f6\u957f\u8fc7\u957f\uff0c\u4eba\u5de5\u5904\u7406\u8ddf\u8fdb\u4ee5\u5916\uff0c\u8fd8\u9700\u898124\u5c0f\u65f6\u7684\u76d1\u63a7\u670d\u52a1\uff0c\u6700\u597d\u80fd\u591f\u76f4\u63a5\u5b8c\u6210\u5e94\u6025\u5904\u7406\u3002<\/cite><\/blockquote>\n\n\n\n<p>\u4e3b\u8981\u529f\u80fd\u4e3a\u9879\u76ee\u5931\u6548\u540e\u81ea\u52a8\u91cd\u542f\uff0c\u91cd\u542f\u5931\u8d25\u6216\u8005\u6307\u5b9a\u591a\u5c11\u79d2\u4ee5\u540e\u4f9d\u65e7\u672a\u6062\u590d\u6b63\u5e38\u7684\u8bdd\u5c31\u53d1\u9001\u77ed\u4fe1\u7ed9\u6307\u5b9a\u7ef4\u62a4\u4eba\u5458\u3002<\/p>\n\n\n\n<p>\u6838\u5fc3\u5b9e\u4e60\u4e3aspring\u5b9a\u65f6\u4efb\u52a1Schduled\uff0c\u6307\u5b9a\u56fa\u5b9a\u65f6\u957f\u53bb\u8bf7\u6c42\u9700\u8981\u76d1\u63a7\u7684\u670d\u52a1\u5fc3\u8df3\u63a5\u53e3\uff0c\u5982\u679c\u7d2f\u8ba1\u591a\u5c11\u79d2\u540e\u4f9d\u65e7\u672a\u6b63\u5e38\u54cd\u5e94\uff0c\u57fa\u672c\u6392\u9664\u7f51\u7edc\u5361\u987f\u539f\u56e0\uff0c\u6b64\u65f6\u9996\u5148\u91cd\u542f\u670d\u52a1\uff0c\u6307\u5b9a\u65f6\u95f4\u540e\u518d\u6b21\u68c0\u6d4b\uff0c\u5982\u679c\u672a\u6210\u529f\u6062\u590d\u54cd\u5e94\uff0c\u8bf4\u660e\u91cd\u542f\u5931\u8d25\u6216\u8005\u662f\u670d\u52a1\u5668\u95ee\u9898\uff0c\u9700\u8981\u540e\u7aef\u7ef4\u62a4\u4eba\u5458\u53bb\u5904\u7406\uff0c\u5c31\u53d1\u9001\u77ed\u4fe1\u8fdb\u884c\u901a\u77e5\u3002<\/p>\n\n\n\n<p>\u8981\u5b9e\u73b0\u4ece\u670d\u52a1\u4e2d\u63a7\u5236\u91cd\u542f\u5176\u4ed6\u670d\u52a1\uff0c\u8fd9\u91cc\u5c31\u9700\u8981\u5f15\u5165<em>Jsch<\/em>(Java Secure Channel)\uff0c\u529f\u80fd\u7b80\u800c\u8a00\u4e4b\u5c31\u662f\u4ee5java\u7684\u65b9\u5f0f\u901a\u8fc7<em>jsch<\/em>\u8fde\u63a5,\u6765\u5bf9\u670d\u52a1\u5668\u8fdb\u884c\u64cd\u4f5c\uff0c\u53d1\u9001\u77ed\u4fe1\u5c31\u662f\u963f\u91cc\u4e91sms\u670d\u52a1\uff0c\u5f15\u5165\u8c03\u7528\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u5f15\u5165\u9879\u76ee\u4e2d\u4f7f\u7528\u7684\u4f9d\u8d56<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n &lt;dependency&gt;\n            &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n            &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n        &lt;\/dependency&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;com.alibaba.cloud&lt;\/groupId&gt;\n            &lt;artifactId&gt;spring-cloud-starter-alibaba-nacos-discovery&lt;\/artifactId&gt;\n        &lt;\/dependency&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;com.alibaba.cloud&lt;\/groupId&gt;\n            &lt;artifactId&gt;spring-cloud-starter-alibaba-nacos-config&lt;\/artifactId&gt;\n        &lt;\/dependency&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n            &lt;artifactId&gt;spring-cloud-starter-openfeign&lt;\/artifactId&gt;\n        &lt;\/dependency&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n            &lt;artifactId&gt;spring-boot-starter-data-redis&lt;\/artifactId&gt;\n        &lt;\/dependency&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;com.aliyun&lt;\/groupId&gt;\n            &lt;artifactId&gt;aliyun-java-sdk-core&lt;\/artifactId&gt;\n        &lt;\/dependency&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;org.apache.commons&lt;\/groupId&gt;\n            &lt;artifactId&gt;commons-pool2&lt;\/artifactId&gt;\n        &lt;\/dependency&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;com.aliyun.oss&lt;\/groupId&gt;\n            &lt;artifactId&gt;aliyun-sdk-oss&lt;\/artifactId&gt;\n        &lt;\/dependency&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;com.jcraft&lt;\/groupId&gt;\n            &lt;artifactId&gt;jsch&lt;\/artifactId&gt;\n            &lt;version&gt;0.1.51&lt;\/version&gt;\n        &lt;\/dependency&gt;\n<\/pre><\/div>\n\n\n<p>\u8fdc\u7a0b\u8fde\u63a5\u6240\u9700\u6570\u636e\u5c01\u88c5\u6210\u4e00\u4e2a\u5b9e\u4f53\u7c7bPOJO<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\npublic class SshContextConf {\n\n    private String      remoteHost;  \/\/\u8fdc\u7a0b\u8fde\u63a5\u670d\u52a1\u5668\u5730\u5740\n    private int         remotePort = 22; \/\/\u8fdc\u7a0b\u8fde\u63a5\u670d\u52a1\u5668\u7aef\u53e3\n    private String      userName ; \/\/ \u8fdc\u7a0b\u8fde\u63a5\u7684\u7528\u6237\u540d\n    private String      password; \/\/\u8fdc\u7a0b\u8fde\u63a5\u7528\u6237\u7684\u5bc6\u7801\n    private String identity = &quot;~\/.ssh\/id_rsa&quot;;\n    private String passphrase = &quot;&quot;;\n\n    public SshContextConf(String userName, String remoteHost, String password) {\n        this.userName = userName;\n        this.remoteHost = remoteHost;\n        this.password = password;\n    }\n}\n<\/pre><\/div>\n\n\n<p>JSCH\u8c03\u7528\u5de5\u5177\u7c7b<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\npublic class SshCmdClient {\n\n    private JSch jsch;\n\n    private Session session;\n\n    private SshContextConf conf;\n\n    public SshCmdClient() {\n        SshContextConf conf = new SshContextConf(&quot;\u767b\u5f55\u7528\u6237&quot;,&quot;\u767b\u9646\u5730\u5740&quot;,&quot;\u767b\u9646\u5bc6\u7801&quot;);\n        this.conf=conf;\n        jsch = new JSch();\n        connect();\n    }\n\n\n    \/**\n     * \u5173\u95edssh\u8fde\u63a5\n     *\/\n    public void close() {\n        session.disconnect();\n    }\n\n    \/**\n     * \u672c\u5730\u7aef\u53e3\u8f6c\u53d1\n     *\n     * @param localPort      \u88ab\u8f6c\u53d1\u7684\u672c\u5730\u7aef\u53e3\n     * @param remoteHost     \u8f6c\u53d1\u540e\u7684\u670d\u52a1\u5668\n     * @param remoteHostPost \u8f6c\u53d1\u540e\u7684\u670d\u52a1\u5668\u7684\u7aef\u53e3\n     *\/\n    public void forwardingL(int localPort, String remoteHost, int remoteHostPost) {\n        if (session == null) {\n            throw new RuntimeException(&quot;please establish ssh connection before forwardingL&quot;);\n        }\n        try {\n            int assinged_port = session.setPortForwardingL(localPort, remoteHost, remoteHostPost);\n            System.out.println(&quot;\u672c\u5730\u7aef\u53e3\u8f6c\u53d1\u6210\u529f  from localhost:&quot; + assinged_port + &quot; to &quot; + remoteHost + &quot;:&quot; + remoteHostPost);\n        } catch (JSchException e) {\n            e.printStackTrace();\n        }\n    }\n\n    \/**\n     * \u8fdc\u7a0b\u7aef\u53e3\u8f6c\u53d1\n     *\n     * @param remotePort \u88ab\u8f6c\u53d1\u7684\u8fdc\u7a0b\u7aef\u53e3\n     * @param localHost  \u8f6c\u53d1\u540e\u7684\u670d\u52a1\u5668\u5730\u5740\n     * @param localPort  \u8f6c\u53d1\u540e\u7684\u670d\u52a1\u5668\u7684\u7aef\u53e3\n     *\/\n    public void forwardingR(int remotePort, String localHost, int localPort) {\n        if (session == null) {\n            throw new RuntimeException(&quot;please establish ssh connection before forwardingR&quot;);\n        }\n        try {\n            session.setPortForwardingR(remotePort, localHost, localPort);\n            System.out.println(&quot;\u8fdc\u7a0b\u7aef\u53e3\u8f6c\u53d1\u6210\u529f  from &quot; + conf.getRemoteHost() + &quot;:&quot; + remotePort + &quot; to &quot; + localHost + &quot;:&quot; + localPort);\n        } catch (JSchException e) {\n            e.printStackTrace();\n        }\n    }\n\n\n    \/**\n     * \u53d6\u6d88\u5df2\u5206\u914d\u7684\u672c\u5730\u7aef\u53e3\u8f6c\u53d1\n     *\n     * @param localPort \u88ab\u8f6c\u53d1\u7684\u672c\u5730\u7aef\u53e3\n     *\/\n    public void delForwardingL(int localPort) {\n        try {\n            session.delPortForwardingL(localPort);\n        } catch (JSchException e) {\n            e.printStackTrace();\n        }\n    }\n\n    \/**\n     * \u53d6\u6d88\u5df2\u5206\u914d\u7684\u8fdc\u7a0b\u7aef\u53e3\u8f6c\u53d1\n     *\n     * @param remotePort \u88ab\u8f6c\u53d1\u7684\u8fdc\u7a0b\u7aef\u53e3\n     *\/\n    public void delForwardingR(int remotePort) {\n        try {\n            session.delPortForwardingR(remotePort);\n        } catch (JSchException e) {\n            e.printStackTrace();\n        }\n    }\n\n    \/**\n     * \u6267\u884c\u6307\u4ee4\u6ca1\u6709\u8fd4\u56de\u7ed3\u679c\n     *\/\n    public void executeExecN(String command) {\n        executeExec(command, false);\n    }\n\n    \/**\n     * \u6267\u884c\u6307\u4ee4\u6709\u8fd4\u56de\u7ed3\u679c\n     *\/\n    public List&lt;String&gt; executeExec(String command) {\n        return executeExec(command, true);\n    }\n\n\n    \/**\n     * \u6267\u884c\u6307\u4ee4\n     *\n     * @param command    \u6307\u4ee4\n     * @param needResult \u662f\u5426\u9700\u8981\u8fd4\u56de\u6025\u6307\u4ee4\u6267\u884c\u7ed3\u679c\n     * @return \u6307\u4ee4\u6267\u884c\u7ed3\u679c\n     *\/\n    public List&lt;String&gt; executeExec(String command, boolean needResult) {\n        isDisconnect();\n        List&lt;String&gt; resultLines = null;\n        ChannelExec execChannel = null;\n        try {\n            execChannel = (ChannelExec) session.openChannel(&quot;exec&quot;);\n            execChannel.setCommand(command);\n            execChannel.setErrStream(System.err);\n            execChannel.connect(10000);\n            if (needResult) {\n                resultLines = collectResult(execChannel.getInputStream());\n            }\n        } catch (IOException | JSchException e) {\n            e.printStackTrace();\n        } finally {\n            if (execChannel != null) {\n                try {\n                    execChannel.disconnect();\n                } catch (Exception e) {\n                    System.out.println(&quot;JSch channel disconnect error:&quot; + e);\n                }\n            }\n        }\n        return resultLines;\n    }\n\n\n    \/**\n     * \u6536\u96c6\u811a\u672c\u6267\u884c\u7684\u7ed3\u679c\n     *\n     * @param input ssh\u8fde\u63a5\u901a\u9053\u8f93\u5165\u6d41\n     * @return \u811a\u672c\u6267\u884c\u7684\u7ed3\u679c\n     *\/\n    private List&lt;String&gt; collectResult(InputStream input) {\n        List&lt;String&gt; resultLines = new ArrayList&lt;&gt;();\n        try {\n            BufferedReader inputReader = new BufferedReader(new InputStreamReader(input));\n            String inputLine = null;\n            while ((inputLine = inputReader.readLine()) != null) {\n                resultLines.add(inputLine);\n            }\n        } catch (IOException e) {\n            e.printStackTrace();\n        } finally {\n            if (input != null) {\n                try {\n                    input.close();\n                } catch (Exception e) {\n                    System.err.println(&quot;JSch inputStream close error:&quot; + e);\n                }\n            }\n        }\n        return resultLines;\n    }\n\n    \/**\n     * \u4e0a\u4f20\u6587\u4ef6\n     *\n     * @param lfile \u88ab\u4e0a\u4f20\u7684\u672c\u5730\u6587\u4ef6\n     * @param rfile \u4e0a\u4f20\u540e\u7684\u670d\u52a1\u5668\u4fdd\u5b58\u7684\u4f4d\u7f6e\n     *\/\n    public void upload(String lfile, String rfile) {\n        FileInputStream fis = null;\n        try {\n            boolean ptimestamp = false;\n            \/\/ exec 'scp -t rfile' remotely\n            rfile = rfile.replace(&quot;'&quot;, &quot;'\\\\''&quot;);\n            rfile = &quot;'&quot; + rfile + &quot;'&quot;;\n            String command = &quot;scp &quot; + (ptimestamp ? &quot;-p&quot; : &quot;&quot;) + &quot; -t &quot; + rfile;\n            Channel channel = session.openChannel(&quot;exec&quot;);\n            ((ChannelExec) channel).setCommand(command);\n\n            \/\/ get I\/O streams for remote scp\n            OutputStream out = channel.getOutputStream();\n            InputStream in = channel.getInputStream();\n\n            channel.connect();\n\n            if (checkAck(in) != 0) {\n                return;\n            }\n\n            File _lfile = new File(lfile);\n\n            if (ptimestamp) {\n                command = &quot;T &quot; + (_lfile.lastModified() \/ 1000) + &quot; 0&quot;;\n                \/\/ The access time should be sent here,\n                \/\/ but it is not accessible with JavaAPI ;-&lt;\n                command += (&quot; &quot; + (_lfile.lastModified() \/ 1000) + &quot; 0\\n&quot;);\n                out.write(command.getBytes());\n                out.flush();\n                if (checkAck(in) != 0) {\n                    System.exit(0);\n                }\n            }\n\n            \/\/ send &quot;C0644 filesize filename&quot;, where filename should not include '\/'\n            long filesize = _lfile.length();\n            command = &quot;C0644 &quot; + filesize + &quot; &quot;;\n            if (lfile.lastIndexOf('\/') &gt; 0) {\n                command += lfile.substring(lfile.lastIndexOf('\/') + 1);\n            } else {\n                command += lfile;\n            }\n            command += &quot;\\n&quot;;\n            out.write(command.getBytes());\n            out.flush();\n            if (checkAck(in) != 0) {\n                return;\n            }\n\n            \/\/ send a content of lfile\n            fis = new FileInputStream(lfile);\n            byte&#91;] buf = new byte&#91;1024];\n            while (true) {\n                int len = fis.read(buf, 0, buf.length);\n                if (len &lt;= 0) {\n                    break;\n                }\n                out.write(buf, 0, len); \/\/out.flush();\n            }\n            fis.close();\n            fis = null;\n            \/\/ send '\\0'\n            buf&#91;0] = 0;\n            out.write(buf, 0, 1);\n            out.flush();\n            if (checkAck(in) != 0) {\n                return;\n            }\n            out.close();\n            channel.disconnect();\n        } catch (Exception e) {\n            e.printStackTrace();\n            try {\n                if (fis != null) {\n                    fis.close();\n                }\n            } catch (Exception e1) {\n                e1.printStackTrace();\n            }\n        }\n    }\n\n    \/**\n     * \u4e0b\u8f7d\u6587\u4ef6\n     *\n     * @param source      \u88ab\u4e0b\u8f7d\u7684\u6587\u4ef6\n     * @param destination \u4e0b\u8f7d\u540e\u672c\u5730\u4fdd\u5b58\u7684\u8def\u5f84\n     * @return\n     *\/\n    public long download(String source, String destination) {\n        FileOutputStream fileOutputStream = null;\n        try {\n            ChannelExec channel = (ChannelExec) session.openChannel(&quot;exec&quot;);\n            channel.setCommand(&quot;scp -f &quot; + source);\n            OutputStream out = channel.getOutputStream();\n            InputStream in = channel.getInputStream();\n            channel.connect();\n            byte&#91;] buf = new byte&#91;1024];\n            \/\/send '\\0'\n            buf&#91;0] = 0;\n            out.write(buf, 0, 1);\n            out.flush();\n            while (true) {\n                if (checkAck(in) != 'C') {\n                    break;\n                }\n            }\n            \/\/read '644 '\n            in.read(buf, 0, 4);\n            long fileSize = 0;\n            while (true) {\n                if (in.read(buf, 0, 1) &lt; 0) {\n                    break;\n                }\n                if (buf&#91;0] == ' ') {\n                    break;\n                }\n                fileSize = fileSize * 10L + (long) (buf&#91;0] - '0');\n            }\n            String file = null;\n            for (int i = 0; ; i++) {\n                in.read(buf, i, 1);\n                if (buf&#91;i] == (byte) 0x0a) {\n                    file = new String(buf, 0, i);\n                    break;\n                }\n            }\n            \/\/ send '\\0'\n            buf&#91;0] = 0;\n            out.write(buf, 0, 1);\n            out.flush();\n            \/\/ read a content of lfile\n            if (Files.isDirectory(Paths.get(destination))) {\n                fileOutputStream = new FileOutputStream(destination + File.separator + file);\n            } else {\n                fileOutputStream = new FileOutputStream(destination);\n            }\n            long sum = 0;\n            while (true) {\n                int len = in.read(buf, 0, buf.length);\n                if (len &lt;= 0) {\n                    break;\n                }\n                sum += len;\n                if (len &gt;= fileSize) {\n                    fileOutputStream.write(buf, 0, (int) fileSize);\n                    break;\n                }\n                fileOutputStream.write(buf, 0, len);\n                fileSize -= len;\n            }\n            return sum;\n        } catch (Exception e) {\n            e.printStackTrace();\n        } finally {\n            if (fileOutputStream != null) {\n                try {\n                    fileOutputStream.close();\n                } catch (Exception e) {\n                    e.printStackTrace();\n                }\n            }\n        }\n        return -1;\n    }\n\n    private int checkAck(InputStream in) throws IOException {\n        int b = in.read();\n        \/\/ b may be 0 for success,\n        \/\/          1 for error,\n        \/\/          2 for fatal error,\n        \/\/          -1\n        if (b == 0) {\n            return b;\n        }\n        if (b == -1) {\n            return b;\n        }\n\n        if (b == 1 || b == 2) {\n            StringBuffer sb = new StringBuffer();\n            int c;\n            do {\n                c = in.read();\n                sb.append((char) c);\n            }\n            while (c != '\\n');\n            if (b == 1) { \/\/ error\n                System.out.print(sb.toString());\n            }\n            if (b == 2) { \/\/ fatal error\n                System.out.print(sb.toString());\n            }\n        }\n        return b;\n    }\n\n    \/**\n     * \u5224\u65ad\u662f\u5426\u65ad\u5f00ssh\u8fde\u63a5\u8fdb\u884c\u91cd\u8fde\n     *\/\n    private void isDisconnect() {\n        if (!session.isConnected()) {\n            connect();\n        }\n    }\n\n    \/**\n     * \u5efa\u7acbssh\u8fde\u63a5\n     *\/\n    private void connect() {\n        try {\n            if (Files.exists(Paths.get(conf.getIdentity()))) {\n                jsch.addIdentity(conf.getIdentity(), conf.getPassphrase());\n            }\n            session = jsch.getSession(conf.getUserName(), conf.getRemoteHost(), conf.getRemotePort());\n            session.setPassword(conf.getPassword());\n            session.setConfig(&quot;StrictHostKeyChecking&quot;, &quot;no&quot;); \/\/ \u5173\u95ed\u786e\u8ba4\u63d0\u793a\n            session.connect(30000);\n        } catch (JSchException e) {\n            e.printStackTrace();\n        }\n    }\n}\n<\/pre><\/div>\n\n\n<p>\u76d1\u63a7\u91cd\u542f\u903b\u8f91\u5b9e\u73b0<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\npublic class ServerScheduled {\n    @Autowired\n    RestTemplateClient restTemplateClient;\n    @Autowired\n    RedisTemplate&lt;String, String&gt; redisTemplate;\n    @Autowired\n    SmsUtil smsUtil;\n\n    private SshServiceClient sshServiceClient() {\n        return new SshServiceClient();\n    }\n    private SshCmdClient sshCmdClient(){\n        return new SshCmdClient();\n    }\n\n\n    @Scheduled(fixedDelay = 10000)\n    public void serviceHeart() throws IOException {\n        String heart = null;\n        try {\n            heart = restTemplateClient.serviceHeart();\n        } catch (Exception e) {\n            heart = &quot;GG&quot;;\n        }\n        int newTime = 0;\n        log.info(&quot;heart:{}&quot;, heart);\n        if (!StringUtils.pathEquals(&quot;ok&quot;, heart)) {\n            String time = redisTemplate.opsForValue().get(&quot;qdchess-watchdog:service-time&quot;);\n            if (time == null) {\n                redisTemplate.opsForValue().set(&quot;qdchess-watchdog:service-time&quot;, 1 + &quot;&quot;);\n            } else {\n                newTime = Integer.parseInt(time);\n            }\n            if (newTime &lt; 6) {\n                redisTemplate.opsForValue().set(&quot;qdchess-watchdog:service-time&quot;, (newTime + 1) + &quot;&quot;);\n            } else if (newTime == 6) {\n                redisTemplate.opsForValue().set(&quot;qdchess-watchdog:service-time&quot;, (newTime + 1) + &quot;&quot;);\n                log.info(&quot;\u670d\u52a1\u5df2\u65ad\u5f00:{}\u79d2&quot;, newTime * 10);\n                log.info(&quot;------------\u91cd\u542f\u670d\u52a1------------&quot;);\n                try {\n                    String cmd = &quot;cd \/home\/dragon\/qdchess;  &quot; +\n                            &quot;ps -ef | grep qdchess-service-1.0.0.jar | grep -v grep | awk '{print $2}' | xargs kill -9;&quot; +\n                            &quot; nohup java -jar qdchess-service-1.0.0.jar  &gt; qdchess-service.out 2&gt;&amp;1 &amp;&quot;;\n                    List&lt;String&gt; result = sshServiceClient().executeExec(cmd);\n                    log.info(&quot;result:{}&quot;, result);\n\n                } catch (Exception e) {\n                    e.printStackTrace();\n                    log.info(&quot;----------\u91cd\u542f\u62a5\u9519----------&quot;);\n                }finally {\n                    sshServiceClient().close();\n                }\n            } else if (newTime == 18 || newTime == 30 || newTime == 90 || newTime == 180 || newTime == 360 || newTime == 720) {\n                \/\/3\u5206\u949f||5\u5206\u949f||15\u5206\u949f||30\u5206\u949f||60\u5206\u949f||120\u5206\u949f\n                redisTemplate.opsForValue().set(&quot;qdchess-watchdog:service-time&quot;, (newTime + 1) + &quot;&quot;);\n                log.info(&quot;\u670d\u52a1\u5df2\u65ad\u5f00:{}\u79d2&quot;, newTime * 10);\n                log.info(&quot;------------\u53d1\u9001\u77ed\u4fe1------------&quot;);\n                smsUtil.sendSms(&quot;1*********8&quot;, &quot;qdchess-service&quot;, newTime * 10);\/\/smsUtil\u4e3a\u77ed\u4fe1\u5de5\u5177\u7c7b\uff0c\u4ee5\u524d\u7684\u6587\u7ae0\u4e2d\u6709\u3002\n              \n                log.info(&quot;------------\u518d\u6b21\u91cd\u542f\u670d\u52a1------------&quot;);\n                try {\n                    String cmd = &quot;cd \/home\/dragon\/qdchess;  &quot; +\n                            &quot;ps -ef | grep qdchess-service-1.0.0.jar | grep -v grep | awk '{print $2}' | xargs kill -9;&quot; +\n                            &quot; nohup java -jar qdchess-service-1.0.0.jar  &gt; qdchess-service.out 2&gt;&amp;1 &amp;&quot;;\n                    List&lt;String&gt; result = sshServiceClient().executeExec(cmd);\n                    log.info(&quot;result:{}&quot;, result);\n                } catch (Exception e) {\n                    e.printStackTrace();\n                    log.info(&quot;----------\u91cd\u542f\u62a5\u9519----------&quot;);\n                }finally {\n                    sshServiceClient().close();\n                }\n            } else {\n                redisTemplate.opsForValue().set(&quot;qdchess-watchdog:service-time&quot;, (newTime + 1) + &quot;&quot;);\n                log.info(&quot;\u670d\u52a1\u5df2\u65ad\u5f00:{}\u79d2&quot;, newTime * 10);\n            }\n        } else {\n            redisTemplate.delete(&quot;qdchess-watchdog:service-time&quot;);\n        }\n    }\n}\n<\/pre><\/div>\n\n\n<p>\u6b64\u5904\u9700\u8981\u76d1\u63a7\u7684\u90a3\u8fb9\u7684\u670d\u52a1\u6709\u4e00\u4e2a\u4e3aheart\u7684\u5fc3\u8df3\u63a5\u53e3\u7528\u4e8e\u68c0\u6d4b\u72b6\u6001\uff0c\u5982\u679c\u4e0d\u65b9\u4fbf\u4fee\u6539\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u7684\u63a5\u53e3\uff0c\u4e3b\u8981\u5c31\u662f\u53ef\u4ee5\u786e\u4fdd\u670d\u52a1\u5668\u7684\u8fd0\u884c\u72b6\u6001\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42\uff1a \u7a0b\u5e8f\u51fabug\u5728\u6240\u96be\u514d\uff0c\u4e3a\u51cf\u5c11\u51fa\u95ee\u9898\u65f6\u5bfc\u81f4\u7528\u6237\u65e0\u6cd5\u6b63\u5e38\u4f7f\u7528\u7684\u65f6\u957f\u8fc7\u957f\uff0c\u4eba\u5de5\u5904\u7406\u8ddf\u8fdb\u4ee5\u5916\uff0c\u8fd8\u9700\u898124\u5c0f\u65f6\u7684<span class=\"more-button\"><a href=\"https:\/\/diuut.com\/?p=1268\" class=\"more-link\">view all . . .<span class=\"screen-reader-text\">\u57fa\u4e8eJSCH\u7684\u7b80\u6613\u670d\u52a1\u76d1\u63a7\u670d\u52a1-WatchDog<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":1269,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[12],"_links":{"self":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/1268"}],"collection":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1268"}],"version-history":[{"count":3,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/1268\/revisions"}],"predecessor-version":[{"id":1272,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/1268\/revisions\/1272"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/media\/1269"}],"wp:attachment":[{"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}