Java はシェル スクリプトを呼び出してサービスを再起動します

サービスは mq に接続する必要がありますが、mq の動作が停止または異常であり、サービスの再接続メカニズムが無効です。ここで直接 mq とその独自のサービスを再起動します。

    public void exeShell() {
    
    
        try {
    
    
        // restart.sh脚本里写了stop和start语句,杀死和启动指定服务。
        // 这里是专门用来重启的方法,脚本的路径可以自定义
            String filePath = "/home/catic/restart.sh";
            File file = new File(filePath);
            if (file.exists()) {
    
    
                Runtime.getRuntime().exec(filePath);
                LOGGER.info("系统重启成功!!!");
            } else {
    
    
                LOGGER.info("执行的脚本不存在!");
            }
        } catch (IOException e) {
    
    
            e.printStackTrace();
            LOGGER.info("执行脚本异常!!!");
        }
    }

おすすめ

転載: blog.csdn.net/qq_31424825/article/details/127445900