dev_1.0.0_yuyr_2:重新提交 PR,增加 master/agent 以及系统集成测试 (#17)
Reviewed-on: #17 Reviewed-by: sundapeng <sundp@mail.zgclab.edu.cn> Reviewed-by: xuxt <xuxt@zgclab.edu.cn>
This commit was merged in pull request #17.
This commit is contained in:
1
src/master/build/dns-monitor.sh
Symbolic link
1
src/master/build/dns-monitor.sh
Symbolic link
@@ -0,0 +1 @@
|
||||
../../bind/build/dns-monitor.sh
|
||||
59
src/master/build/start-master.sh
Executable file
59
src/master/build/start-master.sh
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# 中文提示:确保共享目录与 DNS 相关脚本存在
|
||||
DNS_DIR="/private/argus/etc"
|
||||
DNS_SCRIPT="${DNS_DIR}/update-dns.sh"
|
||||
MASTER_DOMAIN_FILE="${DNS_DIR}/master.argus.com"
|
||||
RUNTIME_USER="${ARGUS_RUNTIME_USER:-argus}"
|
||||
RUNTIME_UID="${ARGUS_BUILD_UID:-2133}"
|
||||
RUNTIME_GID="${ARGUS_BUILD_GID:-2015}"
|
||||
MASTER_DATA_DIR="/private/argus/master"
|
||||
METRIC_DIR="/private/argus/metric/prometheus"
|
||||
|
||||
mkdir -p "$DNS_DIR"
|
||||
chown -R "$RUNTIME_UID:$RUNTIME_GID" "$DNS_DIR" 2>/dev/null || true
|
||||
mkdir -p "$MASTER_DATA_DIR"
|
||||
mkdir -p "$METRIC_DIR"
|
||||
chown -R "$RUNTIME_UID:$RUNTIME_GID" "$MASTER_DATA_DIR" "$METRIC_DIR" 2>/dev/null || true
|
||||
|
||||
if [[ -x "$DNS_SCRIPT" ]]; then
|
||||
echo "[INFO] Running update-dns.sh before master starts"
|
||||
# 中文提示:若脚本存在则执行,保证容器使用 bind 作为 DNS
|
||||
"$DNS_SCRIPT" || echo "[WARN] update-dns.sh execution failed"
|
||||
else
|
||||
echo "[WARN] DNS update script not found or not executable: $DNS_SCRIPT"
|
||||
fi
|
||||
|
||||
# 中文提示:记录 master 当前 IP,供 bind 服务同步
|
||||
MASTER_IP=$(ifconfig | grep -A 1 eth0 | grep inet | awk '{print $2}' || true)
|
||||
if [[ -n "${MASTER_IP}" ]]; then
|
||||
echo "current IP: ${MASTER_IP}"
|
||||
echo "${MASTER_IP}" > "$MASTER_DOMAIN_FILE"
|
||||
chown "$RUNTIME_UID:$RUNTIME_GID" "$MASTER_DOMAIN_FILE" 2>/dev/null || true
|
||||
else
|
||||
echo "[WARN] Failed to detect master IP via ifconfig"
|
||||
fi
|
||||
|
||||
WORKERS=${GUNICORN_WORKERS:-4}
|
||||
BIND_ADDR=${GUNICORN_BIND:-0.0.0.0:3000}
|
||||
EXTRA_OPTS=${GUNICORN_EXTRA_ARGS:-}
|
||||
|
||||
if [[ -n "$EXTRA_OPTS" ]]; then
|
||||
read -r -a EXTRA_ARRAY <<< "$EXTRA_OPTS"
|
||||
else
|
||||
EXTRA_ARRAY=()
|
||||
fi
|
||||
|
||||
command=(gunicorn --bind "$BIND_ADDR" --workers "$WORKERS")
|
||||
if [[ ${#EXTRA_ARRAY[@]} -gt 0 ]]; then
|
||||
command+=("${EXTRA_ARRAY[@]}")
|
||||
fi
|
||||
command+=("app:create_app()")
|
||||
|
||||
if command -v runuser >/dev/null 2>&1; then
|
||||
exec runuser -u "$RUNTIME_USER" -- "${command[@]}"
|
||||
else
|
||||
printf -v _cmd_str '%q ' "${command[@]}"
|
||||
exec su -s /bin/bash -m "$RUNTIME_USER" -c "exec ${_cmd_str}"
|
||||
fi
|
||||
39
src/master/build/supervisord.conf
Normal file
39
src/master/build/supervisord.conf
Normal file
@@ -0,0 +1,39 @@
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
logfile=/var/log/supervisor/supervisord.log
|
||||
pidfile=/var/run/supervisord.pid
|
||||
user=root
|
||||
|
||||
[program:master]
|
||||
command=/usr/local/bin/start-master.sh
|
||||
user=root
|
||||
stdout_logfile=/var/log/supervisor/master.log
|
||||
stderr_logfile=/var/log/supervisor/master_error.log
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startsecs=5
|
||||
stopwaitsecs=30
|
||||
killasgroup=true
|
||||
stopasgroup=true
|
||||
|
||||
[program:dns-monitor]
|
||||
command=/usr/local/bin/dns-monitor.sh
|
||||
user=root
|
||||
stdout_logfile=/var/log/supervisor/dns-monitor.log
|
||||
stderr_logfile=/var/log/supervisor/dns-monitor_error.log
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startsecs=5
|
||||
stopwaitsecs=10
|
||||
killasgroup=true
|
||||
stopasgroup=true
|
||||
|
||||
[unix_http_server]
|
||||
file=/var/run/supervisor.sock
|
||||
chmod=0700
|
||||
|
||||
[supervisorctl]
|
||||
serverurl=unix:///var/run/supervisor.sock
|
||||
|
||||
[rpcinterface:supervisor]
|
||||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
||||
Reference in New Issue
Block a user