docs(infra): add PostgreSQL tuning and systemd service documentation

- POSTGRESQL_TUNING.md: documents applied config (8GB shared_buffers,
  64MB work_mem, 8GB max_wal_size, SSD params)
- SYSTEMD_SERVICES.md: lists all production systemd services
- systemd/: versioned copies of all .service and .timer files
- .gitignore: ignore package-lock.json and backups/
This commit is contained in:
2026-04-29 06:30:22 +00:00
parent 44c3a6c910
commit c766571b7d
11 changed files with 196 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
[Unit]
Description=Warm Redis cache for Nexus vehicle info
After=postgresql.service redis-server.service
[Service]
Type=oneshot
User=postgres
WorkingDirectory=/home/Autopartes
ExecStart=/usr/bin/python3 /home/Autopartes/scripts/warm_vehicle_cache.py --batch-size 10000 --ttl 7200
StandardOutput=append:/var/log/nexus-pos/cache_warm.log
StandardError=append:/var/log/nexus-pos/cache_warm.log

View File

@@ -0,0 +1,9 @@
[Unit]
Description=Daily Redis cache warming at 04:00 UTC (1h after MV refresh)
[Timer]
OnCalendar=*-*-* 04:00:00
Persistent=true
[Install]
WantedBy=timers.target

View File

@@ -0,0 +1,19 @@
[Unit]
Description=Nexus POS Celery Worker
After=network.target postgresql.service redis.service
[Service]
Type=simple
User=postgres
WorkingDirectory=/home/Autopartes/pos
Environment=MASTER_DB_URL=postgresql://postgres@/nexus_autoparts
Environment=REDIS_URL=redis://localhost:6379/0
Environment=PYTHONPATH=/home/Autopartes/pos
ExecStart=/usr/bin/python3 -m celery -A celery_app worker --loglevel=info --concurrency=4 -n nexus-worker@%h
Restart=on-failure
RestartSec=10
StandardOutput=append:/var/log/nexus-pos/celery.log
StandardError=append:/var/log/nexus-pos/celery.log
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,10 @@
[Unit]
Description=Refresh Nexus part_vehicle_preview materialized view
After=postgresql.service
[Service]
Type=oneshot
User=postgres
ExecStart=/usr/bin/python3 /home/Autopartes/scripts/refresh_part_vehicle_preview.py
StandardOutput=append:/var/log/nexus-pos/mv_refresh.log
StandardError=append:/var/log/nexus-pos/mv_refresh.log

View File

@@ -0,0 +1,9 @@
[Unit]
Description=Daily refresh of part_vehicle_preview materialized view at 03:00
[Timer]
OnCalendar=*-*-* 03:00:00
Persistent=true
[Install]
WantedBy=timers.target

23
systemd/nexus-pos.service Normal file
View File

@@ -0,0 +1,23 @@
[Unit]
Description=Nexus POS (Gunicorn)
After=network.target postgresql.service redis-server.service
[Service]
Type=simple
User=root
WorkingDirectory=/home/Autopartes/pos
ExecStart=/usr/local/bin/gunicorn -c gunicorn.conf.py "app:create_app()"
Restart=always
RestartSec=5
Environment=PYTHONUNBUFFERED=1
Environment=PYTHONPATH=/home/Autopartes/pos
Environment=MASTER_DB_URL=postgresql://postgres@/nexus_autoparts
Environment=TENANT_DB_URL_TEMPLATE=postgresql://postgres@/nexus_autoparts
Environment=POS_JWT_SECRET=nexus-pos-jwt-secret-12345678901234567890123456789012
Environment=REDIS_URL=redis://localhost:6379/0
Environment=REDIS_ENABLED=true
Environment=MEILI_URL=http://localhost:7700
Environment=MEILI_ENABLED=true
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,16 @@
[Unit]
Description=Nexus Quart Async Catalog (hypercorn)
After=network.target postgresql.service
[Service]
Type=simple
User=root
WorkingDirectory=/home/Autopartes/pos
ExecStart=/usr/local/bin/hypercorn async_catalog:app --bind 0.0.0.0:5002
Restart=always
RestartSec=5
Environment=PYTHONUNBUFFERED=1
Environment=MASTER_DB_URL=postgresql://postgres@localhost/nexus_autoparts
[Install]
WantedBy=multi-user.target

17
systemd/nexus.service Normal file
View File

@@ -0,0 +1,17 @@
[Unit]
Description=Nexus Autoparts Dashboard
After=network.target postgresql.service
[Service]
Type=simple
User=root
WorkingDirectory=/home/Autopartes/dashboard
ExecStart=/usr/bin/python3 server.py
Restart=always
RestartSec=5
Environment=PYTHONUNBUFFERED=1
Environment=DATABASE_URL=postgresql://postgres@localhost/nexus_autoparts
Environment=JWT_SECRET=nexus-dashboard-jwt-secret-12345678901234567890123456789012
[Install]
WantedBy=multi-user.target