钉钉内网穿透经常会失效,如果失效返回的是
Tunnel xxx.vaiwan.com not found
所以可以利用这点,在java定时任务中写个心跳机制,如果调外网接口失败,则重新调用Linux的shell命令,启动内网穿透。
package com.windlight.utils;
import cn.hutool.core.util.RuntimeUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class PiercedUtil {
public static void CMD() {
Thread thread = new Thread(new CMD());
thread.start();
}
@Data
private static class CMD implements Runnable {
@Override
public void run() {
RuntimeUtil.execForStr("/data/aiit_informatization/databoard/Intranet_through/ding -config=/data/aiit_informatization/databoard/Intranet_through/ding.cfg -subdomain=自己随便起一个英文名 5005");
}
}
}
package com.windlight.config;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.windlight.service.TableFieldService;
import com.windlight.utils.PiercedUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
@Configuration
@EnableScheduling
public class SchedulingConfig {
@Scheduled(cron = "0 */1 * * * ?")
public void fenzhong() {
String s = HttpUtil.get("http://刚才起的英文名.vaiwan.com/universal/api/throughTheState");
if (JSONUtil.isJson(s)) {
} else {
PiercedUtil.CMD();
}
}
}
钉钉内网穿透项目地址:https://github.com/open-dingtalk/pierced
也可以自己编写Linux脚本 新建start.sh 文件
vim start.sh
nohup ./ding -config=ding.cfg -subdomain=xxxx 8081 &
:wq
给我们的脚本文件start.sh进行授权
chmod +x start.sh
#启动
./start.sh
#关闭服务
ps -ef|grep ding
kill -9 pid
|