Improve system service reliability and monitoring details

Update systemd service files to ensure continuous operation with automatic restarts, add a timestamp for improved debugging of analytics aggregation, and introduce a new installation script for streamlined deployment.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: 2c579454-c420-40e4-a574-a341fb962b69
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/0sf5i4S
This commit is contained in:
marco370 2025-11-24 11:02:23 +00:00
parent 402cbe1890
commit 921dd81563
4 changed files with 80 additions and 10 deletions

View File

@ -0,0 +1,63 @@
#!/bin/bash
# Install IDS Systemd Services
# Run this script with sudo on the AlmaLinux server
set -e
echo "========================================="
echo "IDS Systemd Services Installation"
echo "========================================="
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Error: This script must be run as root (use sudo)"
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
echo ""
echo "📋 Installing systemd service files..."
# Copy service files
cp "$PROJECT_ROOT/deployment/systemd/ids-ml-backend.service" /etc/systemd/system/
cp "$PROJECT_ROOT/deployment/systemd/ids-syslog-parser.service" /etc/systemd/system/
# Ensure correct permissions
chmod 644 /etc/systemd/system/ids-ml-backend.service
chmod 644 /etc/systemd/system/ids-syslog-parser.service
echo "✅ Service files copied to /etc/systemd/system/"
echo ""
echo "🔄 Reloading systemd daemon..."
systemctl daemon-reload
echo ""
echo "🔧 Enabling services to start on boot..."
systemctl enable ids-ml-backend.service
systemctl enable ids-syslog-parser.service
echo ""
echo "========================================="
echo "✅ Installation Complete!"
echo "========================================="
echo ""
echo "Next steps:"
echo ""
echo "1. Start the services:"
echo " sudo systemctl start ids-ml-backend"
echo " sudo systemctl start ids-syslog-parser"
echo ""
echo "2. Check status:"
echo " sudo systemctl status ids-ml-backend"
echo " sudo systemctl status ids-syslog-parser"
echo ""
echo "3. View logs:"
echo " tail -f /var/log/ids/ml_backend.log"
echo " tail -f /var/log/ids/syslog_parser.log"
echo ""
echo "Services are now configured with auto-restart (Restart=always)"
echo "They will automatically restart on crash and at system boot."
echo ""

View File

@ -1,7 +1,7 @@
[Unit]
Description=IDS ML Backend (FastAPI)
After=network.target postgresql.service
Requires=postgresql.service
After=network.target postgresql-16.service
Wants=postgresql-16.service
[Service]
Type=simple
@ -13,9 +13,11 @@ EnvironmentFile=/opt/ids/.env
# Comando esecuzione (usa virtual environment)
ExecStart=/opt/ids/python_ml/venv/bin/python3 main.py
# Restart automatico in caso di crash
Restart=on-failure
RestartSec=10s
# Restart automatico sempre (non solo on-failure)
Restart=always
RestartSec=10
StartLimitInterval=300
StartLimitBurst=5
# Limiti risorse
LimitNOFILE=65536

View File

@ -1,7 +1,7 @@
[Unit]
Description=IDS Syslog Parser (Network Logs Processor)
After=network.target postgresql.service rsyslog.service
Requires=postgresql.service
After=network.target postgresql-16.service rsyslog.service
Wants=postgresql-16.service
[Service]
Type=simple
@ -13,9 +13,11 @@ EnvironmentFile=/opt/ids/.env
# Comando esecuzione (usa virtual environment)
ExecStart=/opt/ids/python_ml/venv/bin/python3 syslog_parser.py
# Restart automatico in caso di crash
Restart=on-failure
RestartSec=10s
# Restart automatico sempre (non solo on-failure)
Restart=always
RestartSec=10
StartLimitInterval=300
StartLimitBurst=5
# Limiti risorse
LimitNOFILE=65536

View File

@ -459,6 +459,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
if (latestAnalytics.length > 0) {
const lastRun = new Date(latestAnalytics[0].date);
const lastTimestamp = lastRun.toISOString();
const hoursSinceLastRun = (Date.now() - lastRun.getTime()) / (1000 * 60 * 60);
if (hoursSinceLastRun < 2) {
@ -466,6 +467,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
services.analyticsAggregator.healthy = true;
services.analyticsAggregator.details = {
lastRun: latestAnalytics[0].date,
lastTimestamp,
hoursSinceLastRun: hoursSinceLastRun.toFixed(1),
};
} else {
@ -473,6 +475,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
services.analyticsAggregator.healthy = false;
services.analyticsAggregator.details = {
lastRun: latestAnalytics[0].date,
lastTimestamp,
hoursSinceLastRun: hoursSinceLastRun.toFixed(1),
warning: "No aggregation in last 2 hours",
};