Files
syscall_monitor/main.py
MarceloZoeng 26a5f99587
All checks were successful
CI / lint-and-build (push) Successful in 8s
中文+README
2026-06-14 12:08:27 +08:00

32 lines
1.3 KiB
Python
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.

"""程序入口:系统调用监控器主启动脚本。
由于 eBPF 需要内核能力CAP_BPF/root本脚本必须以 root 权限运行。
"""
import os
import sys
# 引入 Flask 应用,用于创建 Web 服务实例
from web.app import create_app
def main():
# 校验运行权限eBPF 需要 root 或 CAP_BPF 能力,否则无法挂载内核探针
if os.geteuid() != 0:
print("错误:必须以 root 权限运行eBPF 需要 CAP_BPF/root 权限)", file=sys.stderr)
sys.exit(1)
# 创建 Flask 应用并从环境变量读取监听地址与端口(默认 0.0.0.0:5000
app = create_app()
host = os.environ.get("HOST", "0.0.0.0")
port = int(os.environ.get("PORT", "5000"))
# 启动 Web 服务:关闭 debug 与 reloader避免 eBPF 探针被重复加载;开启多线程以并发处理请求
# use_reloader=False 是关键Flask 的自动重载机制会导致主进程被 fork 两次,从而导致 eBPF 探针被加载两次,产生冲突和错误
# thearded=True 是可选的默认情况下Flask 会在多线程中运行,但 eBPF 探针不能在多线程中运行
app.run(host=host, port=port, debug=False, use_reloader=False, threaded=True)
if __name__ == "__main__":
main()