|
|
@@ -19,6 +19,7 @@ import cn.reghao.autodop.dagent.mqttsub.impl.AppRpcClazzImpl;
|
|
|
import cn.reghao.jutil.jdk.http.WebClient;
|
|
|
import cn.reghao.jutil.jdk.serializer.JsonConverter;
|
|
|
import cn.reghao.jutil.jdk.text.TextFile;
|
|
|
+import cn.reghao.jutil.jdk.util.SingleInstance;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import oshi.SystemInfo;
|
|
|
|
|
|
@@ -29,7 +30,6 @@ import java.util.List;
|
|
|
|
|
|
@Slf4j
|
|
|
public class DagentApp {
|
|
|
- static ServerSocket serverSocket;
|
|
|
static AsyncMqttClient mqttClient;
|
|
|
static DagentTopicListener dagentTopicListener;
|
|
|
static NodeEventClazzPubImpl nodeEventClazzPub;
|
|
|
@@ -52,43 +52,18 @@ public class DagentApp {
|
|
|
}
|
|
|
|
|
|
static void stop() {
|
|
|
- try {
|
|
|
- serverSocket.close();
|
|
|
- } catch (IOException e) {
|
|
|
- String errmsg = ExceptionUtil.errorMsg(e);
|
|
|
- log.error("关闭 54321 端口出错 {}", errmsg);
|
|
|
- }
|
|
|
-
|
|
|
pubDagentShutdown();
|
|
|
log.info("资源清理完成,结束 autodop-dagent...");
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 通过监听一个端口来保证一台机器上只运行一个 autodop-dagent 实例
|
|
|
- *
|
|
|
- * @param
|
|
|
- * @return
|
|
|
- * @date 2021-11-02 下午3:01
|
|
|
- */
|
|
|
- static void singleInstance() throws Exception {
|
|
|
- try {
|
|
|
- serverSocket = new ServerSocket();
|
|
|
- serverSocket.bind(new InetSocketAddress("127.0.0.1", 54321));
|
|
|
- } catch (IOException e) {
|
|
|
- throw new Exception("已有一个 autodop-dagent 实例在运行, 一台机器上只能运行一个 autodop-dagent 实例.");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
- singleInstance();
|
|
|
- Appender<ILoggingEvent> appender = Appenders.fileAppender();
|
|
|
- LoggerConfig.initLogger(List.of(appender));
|
|
|
-
|
|
|
-
|
|
|
if (args.length != 1) {
|
|
|
log.error("必须指定配置文件...");
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ //Thread t = new Thread(new SingleInstance(65432));
|
|
|
+
|
|
|
String configFilePath = ConfigFile.configFilePath(args[0], DagentApp.class);
|
|
|
String json = new TextFile().readFile(configFilePath);
|
|
|
MqttProperties mqttProperties = JsonConverter.jsonToObject(json, MqttProperties.class);
|
|
|
@@ -106,5 +81,8 @@ public class DagentApp {
|
|
|
|
|
|
mqttClient.connect(connActionListener);
|
|
|
shutdownGracefully();
|
|
|
+
|
|
|
+ Appender<ILoggingEvent> appender = Appenders.fileAppender();
|
|
|
+ LoggerConfig.initLogger(List.of(appender));
|
|
|
}
|
|
|
}
|