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:
parent
402cbe1890
commit
921dd81563
63
deployment/install_systemd_services.sh
Normal file
63
deployment/install_systemd_services.sh
Normal 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 ""
|
||||||
@ -1,7 +1,7 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=IDS ML Backend (FastAPI)
|
Description=IDS ML Backend (FastAPI)
|
||||||
After=network.target postgresql.service
|
After=network.target postgresql-16.service
|
||||||
Requires=postgresql.service
|
Wants=postgresql-16.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
@ -13,9 +13,11 @@ EnvironmentFile=/opt/ids/.env
|
|||||||
# Comando esecuzione (usa virtual environment)
|
# Comando esecuzione (usa virtual environment)
|
||||||
ExecStart=/opt/ids/python_ml/venv/bin/python3 main.py
|
ExecStart=/opt/ids/python_ml/venv/bin/python3 main.py
|
||||||
|
|
||||||
# Restart automatico in caso di crash
|
# Restart automatico sempre (non solo on-failure)
|
||||||
Restart=on-failure
|
Restart=always
|
||||||
RestartSec=10s
|
RestartSec=10
|
||||||
|
StartLimitInterval=300
|
||||||
|
StartLimitBurst=5
|
||||||
|
|
||||||
# Limiti risorse
|
# Limiti risorse
|
||||||
LimitNOFILE=65536
|
LimitNOFILE=65536
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=IDS Syslog Parser (Network Logs Processor)
|
Description=IDS Syslog Parser (Network Logs Processor)
|
||||||
After=network.target postgresql.service rsyslog.service
|
After=network.target postgresql-16.service rsyslog.service
|
||||||
Requires=postgresql.service
|
Wants=postgresql-16.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
@ -13,9 +13,11 @@ EnvironmentFile=/opt/ids/.env
|
|||||||
# Comando esecuzione (usa virtual environment)
|
# Comando esecuzione (usa virtual environment)
|
||||||
ExecStart=/opt/ids/python_ml/venv/bin/python3 syslog_parser.py
|
ExecStart=/opt/ids/python_ml/venv/bin/python3 syslog_parser.py
|
||||||
|
|
||||||
# Restart automatico in caso di crash
|
# Restart automatico sempre (non solo on-failure)
|
||||||
Restart=on-failure
|
Restart=always
|
||||||
RestartSec=10s
|
RestartSec=10
|
||||||
|
StartLimitInterval=300
|
||||||
|
StartLimitBurst=5
|
||||||
|
|
||||||
# Limiti risorse
|
# Limiti risorse
|
||||||
LimitNOFILE=65536
|
LimitNOFILE=65536
|
||||||
|
|||||||
@ -459,6 +459,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
|
|
||||||
if (latestAnalytics.length > 0) {
|
if (latestAnalytics.length > 0) {
|
||||||
const lastRun = new Date(latestAnalytics[0].date);
|
const lastRun = new Date(latestAnalytics[0].date);
|
||||||
|
const lastTimestamp = lastRun.toISOString();
|
||||||
const hoursSinceLastRun = (Date.now() - lastRun.getTime()) / (1000 * 60 * 60);
|
const hoursSinceLastRun = (Date.now() - lastRun.getTime()) / (1000 * 60 * 60);
|
||||||
|
|
||||||
if (hoursSinceLastRun < 2) {
|
if (hoursSinceLastRun < 2) {
|
||||||
@ -466,6 +467,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
services.analyticsAggregator.healthy = true;
|
services.analyticsAggregator.healthy = true;
|
||||||
services.analyticsAggregator.details = {
|
services.analyticsAggregator.details = {
|
||||||
lastRun: latestAnalytics[0].date,
|
lastRun: latestAnalytics[0].date,
|
||||||
|
lastTimestamp,
|
||||||
hoursSinceLastRun: hoursSinceLastRun.toFixed(1),
|
hoursSinceLastRun: hoursSinceLastRun.toFixed(1),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@ -473,6 +475,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
services.analyticsAggregator.healthy = false;
|
services.analyticsAggregator.healthy = false;
|
||||||
services.analyticsAggregator.details = {
|
services.analyticsAggregator.details = {
|
||||||
lastRun: latestAnalytics[0].date,
|
lastRun: latestAnalytics[0].date,
|
||||||
|
lastTimestamp,
|
||||||
hoursSinceLastRun: hoursSinceLastRun.toFixed(1),
|
hoursSinceLastRun: hoursSinceLastRun.toFixed(1),
|
||||||
warning: "No aggregation in last 2 hours",
|
warning: "No aggregation in last 2 hours",
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user