fix: agent config search order — 1st arg > /etc/ > ~/.config/
The systemd service runs as root so /root is /root, but config is written to /etc/servermanager/agent.conf. The agent now tries: 1. Path from command-line argument 2. /etc/servermanager/agent.conf (system mode) 3. $HOME/.config/servermanager/agent.conf (user mode) Service ExecStart and cron job both pass the config path explicitly.
This commit is contained in:
@@ -53,7 +53,14 @@ cat > "$AGENT_BIN" << 'AGENTSCRIPT'
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
CONFIG_FILE="${1:-$HOME/.config/servermanager/agent.conf}"
|
# Config search order: 1st arg > /etc/servermanager/agent.conf > $HOME/.config/servermanager/agent.conf
|
||||||
|
if [ -n "$1" ] && [ -f "$1" ]; then
|
||||||
|
CONFIG_FILE="$1"
|
||||||
|
elif [ -f "/etc/servermanager/agent.conf" ]; then
|
||||||
|
CONFIG_FILE="/etc/servermanager/agent.conf"
|
||||||
|
else
|
||||||
|
CONFIG_FILE="$HOME/.config/servermanager/agent.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
load_config() {
|
load_config() {
|
||||||
if [ -f "$CONFIG_FILE" ]; then
|
if [ -f "$CONFIG_FILE" ]; then
|
||||||
@@ -141,7 +148,7 @@ After=network-online.target
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=/usr/local/bin/servermanager-agent
|
ExecStart=/usr/local/bin/servermanager-agent /etc/servermanager/agent.conf
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
[Install]
|
[Install]
|
||||||
@@ -152,7 +159,7 @@ UNIT
|
|||||||
systemctl restart servermanager-agent 2>/dev/null || true
|
systemctl restart servermanager-agent 2>/dev/null || true
|
||||||
else
|
else
|
||||||
echo " Using crontab (@reboot)..."
|
echo " Using crontab (@reboot)..."
|
||||||
CRON_JOB="@reboot $AGENT_BIN > $CONFIG_DIR/agent.log 2>&1"
|
CRON_JOB="@reboot $AGENT_BIN $CONFIG_FILE > $CONFIG_DIR/agent.log 2>&1"
|
||||||
(crontab -l 2>/dev/null | grep -v '_sm_agent\|servermanager-agent'; echo "$CRON_JOB") | crontab - 2>/dev/null || {
|
(crontab -l 2>/dev/null | grep -v '_sm_agent\|servermanager-agent'; echo "$CRON_JOB") | crontab - 2>/dev/null || {
|
||||||
echo "WARNING: Could not install crontab. Agent must be started manually."
|
echo "WARNING: Could not install crontab. Agent must be started manually."
|
||||||
echo " Run: $AGENT_BIN &"
|
echo " Run: $AGENT_BIN &"
|
||||||
|
|||||||
Reference in New Issue
Block a user