feat(install): add Linux client systemd installation script
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
HUB_URL="${1:-http://hub.example.com:8443}"
|
||||
ENROLL_SECRET="${2:-}"
|
||||
|
||||
INSTALL_DIR="/opt/logar-client"
|
||||
CONFIG_DIR="/etc/logar"
|
||||
|
||||
echo "[+] Installing LOGAR Client..."
|
||||
mkdir -p "${INSTALL_DIR}" "${CONFIG_DIR}/certs"
|
||||
|
||||
if [ -f "dist/Linux_Client.bin" ]; then
|
||||
cp dist/Linux_Client.bin "${INSTALL_DIR}/Linux_Client"
|
||||
elif [ -f "dist/Linux_Client" ]; then
|
||||
cp dist/Linux_Client "${INSTALL_DIR}/Linux_Client"
|
||||
else
|
||||
echo "[!] Warning: dist/Linux_Client binary not found in current directory. Continuing with existing binary if present."
|
||||
fi
|
||||
|
||||
if [ -f "${INSTALL_DIR}/Linux_Client" ]; then
|
||||
chmod +x "${INSTALL_DIR}/Linux_Client"
|
||||
fi
|
||||
|
||||
# Bootstrap certificate if missing and enrollment secret is provided
|
||||
if [ ! -f "${CONFIG_DIR}/certs/client.crt" ] && [ -n "${ENROLL_SECRET}" ]; then
|
||||
echo "[+] Enrolling client with LOGAR Hub..."
|
||||
MACHINE_ID=$(cat /etc/machine-id 2>/dev/null || hostname)
|
||||
RESPONSE=$(curl -s -X POST "${HUB_URL}/api/client/enroll" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"client_id\": \"${MACHINE_ID}\", \"hostname\": \"$(hostname)\", \"os\": \"linux\", \"enrollment_secret\": \"${ENROLL_SECRET}\"}")
|
||||
|
||||
echo "${RESPONSE}" | grep -q "client_cert" || {
|
||||
echo "[!] Enrollment failed: ${RESPONSE}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if command -v jq >/dev/null 2>&1; then
|
||||
echo "${RESPONSE}" | jq -r .ca_cert > "${CONFIG_DIR}/certs/ca.crt"
|
||||
echo "${RESPONSE}" | jq -r .client_cert > "${CONFIG_DIR}/certs/client.crt"
|
||||
echo "${RESPONSE}" | jq -r .client_key > "${CONFIG_DIR}/certs/client.key"
|
||||
else
|
||||
python3 -c "import sys, json; data=json.loads(sys.stdin.read()); open('${CONFIG_DIR}/certs/ca.crt','w').write(data['ca_cert']); open('${CONFIG_DIR}/certs/client.crt','w').write(data['client_cert']); open('${CONFIG_DIR}/certs/client.key','w').write(data['client_key'])" <<< "${RESPONSE}"
|
||||
fi
|
||||
chmod 600 "${CONFIG_DIR}/certs/client.key"
|
||||
echo "[+] Certificates written to ${CONFIG_DIR}/certs"
|
||||
fi
|
||||
|
||||
cat <<EOF > /etc/systemd/system/logar-client.service
|
||||
[Unit]
|
||||
Description=LOGAR Edge Log Aggregator Client
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=${INSTALL_DIR}/Linux_Client --config ${CONFIG_DIR}/config.json
|
||||
Restart=always
|
||||
RestartSec=5s
|
||||
User=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
if command -v systemctl >/dev/null 2>&1; then
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now logar-client.service || true
|
||||
echo "[+] LOGAR Client service configured and activated."
|
||||
else
|
||||
echo "[+] Systemd service installed at /etc/systemd/system/logar-client.service"
|
||||
fi
|
||||
Reference in New Issue
Block a user