vdi-cloud/terminal/kiosk-shell/src/monitor_main.cpp
宋一鸣 162dcc1e02 初始化:导入 VDI 云终端代码与会话基础能力
变更详情:init: VDI 云终端代码(kiosk-shell 登录/桌面列表/Moonlight/RDP/看门狗)
2026-10-28 20:52:20 +08:00

67 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 看门狗 Monitor 入口
//
// 用法:vdi-kiosk-monitor -- <主进程命令行>
// 例: vdi-kiosk-monitor -- /home/armbian/vdi-terminal/bin/kiosk-shell
//
// 对应会议纪要要求:
// "必须部署独立的 Monitor(看门狗)程序监控主进程状态,
// 主进程假死或崩溃时由 Monitor 执行 kill 操作并重启"
#include <cstdio>
#include <string>
#include "monitor.h"
int main(int argc, char** argv) {
if (argc < 2) {
std::fprintf(stderr, "用法: vdi-kiosk-monitor [--verbose] -- <主进程命令行>\n");
return 2;
}
int idx = 1;
vdi::MonitorConfig config;
config.verbose = true;
while (idx < argc && std::string(argv[idx]).rfind("--", 0) == 0) {
const std::string opt = argv[idx];
if (opt == "--") {
++idx;
break;
}
if (opt == "--quiet") {
config.verbose = false;
} else if (opt == "--verbose") {
config.verbose = true;
} else if (opt == "--heartbeat-timeout" && idx + 1 < argc) {
config.heartbeatTimeoutMs = std::atoi(argv[++idx]);
} else if (opt == "--check-interval" && idx + 1 < argc) {
config.checkIntervalMs = std::atoi(argv[++idx]);
} else if (opt == "--max-restart" && idx + 1 < argc) {
config.maxRestartAttempts = std::atoi(argv[++idx]);
} else if (opt == "--heartbeat-file" && idx + 1 < argc) {
config.heartbeatFile = argv[++idx];
} else {
// 未知选项视为主进程命令行的起点
break;
}
++idx;
}
if (idx >= argc) {
std::fprintf(stderr, "缺少主进程命令行\n");
return 2;
}
// 拼出主进程命令行
std::string command;
for (int i = idx; i < argc; ++i) {
if (i > idx) {
command += " ";
}
command += argv[i];
}
vdi::Monitor monitor(config);
return monitor.run(command);
}