feat: systemd service for agent daemon + one-click deploy script
This commit is contained in:
parent
4b7343c87e
commit
bdd2ce49ff
47
scripts/deploy-agent.sh
Executable file
47
scripts/deploy-agent.sh
Executable file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
# FOMS Agent 一键部署 — 在 A/B 机器上执行
|
||||
set -e
|
||||
|
||||
INSTALL_DIR=${1:-/opt/foms-agent}
|
||||
MANAGEMENT_URL=${2:-http://192.168.1.100:9080}
|
||||
NODE_ID=${3:-}
|
||||
AGENT_TOKEN=${4:-}
|
||||
|
||||
if [ -z "$NODE_ID" ]; then
|
||||
echo "用法: $0 <安装目录> <管理端URL> <节点ID> <Agent令牌>"
|
||||
echo "示例: $0 /opt/foms-agent http://192.168.1.100:9080 node_a_001 mytoken123"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "=== FOMS Agent 部署 ==="
|
||||
echo " 安装目录: $INSTALL_DIR"
|
||||
echo " 管理端: $MANAGEMENT_URL"
|
||||
echo " 节点ID: $NODE_ID"
|
||||
|
||||
# 1. 创建目录
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
|
||||
# 2. 复制 agent 脚本
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
cp "$SCRIPT_DIR/foms-agent.py" "$INSTALL_DIR/"
|
||||
|
||||
# 3. 创建 .env
|
||||
cat > "$INSTALL_DIR/.env" << EOF
|
||||
FOMS_MANAGEMENT_URL=$MANAGEMENT_URL
|
||||
FOMS_NODE_ID=$NODE_ID
|
||||
FOMS_AGENT_TOKEN=$AGENT_TOKEN
|
||||
FOMS_HEARTBEAT_INTERVAL=10
|
||||
EOF
|
||||
|
||||
# 4. 安装 systemd 服务
|
||||
cp "$SCRIPT_DIR/foms-agent.service" /etc/systemd/system/foms-agent.service
|
||||
sed -i "s|/opt/foms-agent|$INSTALL_DIR|g" /etc/systemd/system/foms-agent.service
|
||||
|
||||
# 5. 启用并启动
|
||||
systemctl daemon-reload
|
||||
systemctl enable foms-agent
|
||||
systemctl restart foms-agent
|
||||
|
||||
echo "=== 部署完成 ==="
|
||||
echo " systemctl status foms-agent # 查看状态"
|
||||
echo " journalctl -u foms-agent -f # 查看日志"
|
||||
21
scripts/foms-agent.service
Normal file
21
scripts/foms-agent.service
Normal file
@ -0,0 +1,21 @@
|
||||
[Unit]
|
||||
Description=FOMS Agent - Failover Management System Agent
|
||||
Documentation=https://git.opencomputing.cn/yumoqing/foms
|
||||
After=network.target mysqld.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
EnvironmentFile=/opt/foms-agent/.env
|
||||
WorkingDirectory=/opt/foms-agent
|
||||
ExecStart=/usr/bin/python3 /opt/foms-agent/foms-agent.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=append:/var/log/foms-agent.log
|
||||
StandardError=append:/var/log/foms-agent.log
|
||||
# 防止无限重启耗尽资源
|
||||
StartLimitInterval=300
|
||||
StartLimitBurst=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Loading…
x
Reference in New Issue
Block a user