From 2090da57f5d2219dae5c584fce479b73cf5a5ea9 Mon Sep 17 00:00:00 2001 From: Ben Reed Date: Tue, 19 Aug 2025 10:56:32 -0300 Subject: [PATCH] Add systemd deployment configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Create systemd service and timer files for 8am and 12pm runs - Add automated installation script - Include deployment documentation with troubleshooting - Configure for production with proper paths and environment Ready for production deployment with: sudo ./deploy/install.sh 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- DEPLOY.md | 124 +++++++++++++++++++++++++++++++ deploy/hvac-content-12pm.service | 18 +++++ deploy/hvac-content-12pm.timer | 10 +++ deploy/hvac-content-8am.service | 18 +++++ deploy/hvac-content-8am.timer | 10 +++ deploy/install.sh | 36 +++++++++ 6 files changed, 216 insertions(+) create mode 100644 DEPLOY.md create mode 100644 deploy/hvac-content-12pm.service create mode 100644 deploy/hvac-content-12pm.timer create mode 100644 deploy/hvac-content-8am.service create mode 100644 deploy/hvac-content-8am.timer create mode 100755 deploy/install.sh diff --git a/DEPLOY.md b/DEPLOY.md new file mode 100644 index 0000000..c0b4029 --- /dev/null +++ b/DEPLOY.md @@ -0,0 +1,124 @@ +# Deployment Instructions + +## Prerequisites + +Ensure the following are completed: +1. Python environment is set up with `uv` +2. All dependencies installed: `uv pip install -r requirements.txt` +3. `.env` file configured with API credentials +4. Test run successful: `uv run python run_api_production_v2.py` + +## Deploy to Production + +### Option 1: Automated Installation (Recommended) + +```bash +cd /home/ben/dev/hvac-kia-content/deploy +sudo ./install.sh +``` + +This will: +- Copy systemd service files to `/etc/systemd/system/` +- Enable and start the timers +- Show service status + +### Option 2: Manual Installation + +```bash +# Copy service files +sudo cp deploy/*.service /etc/systemd/system/ +sudo cp deploy/*.timer /etc/systemd/system/ + +# Reload systemd +sudo systemctl daemon-reload + +# Enable timers (start on boot) +sudo systemctl enable hvac-content-8am.timer +sudo systemctl enable hvac-content-12pm.timer + +# Start timers immediately +sudo systemctl start hvac-content-8am.timer +sudo systemctl start hvac-content-12pm.timer +``` + +## Verify Deployment + +Check timer status: +```bash +systemctl list-timers | grep hvac +``` + +Expected output: +``` +NEXT LEFT LAST PASSED UNIT ACTIVATES +Mon 2025-08-20 08:00:00 ADT 21h left n/a n/a hvac-content-8am.timer hvac-content-8am.service +Mon 2025-08-19 12:00:00 ADT 1h 9min left n/a n/a hvac-content-12pm.timer hvac-content-12pm.service +``` + +## Monitor Services + +View logs in real-time: +```bash +# Morning run logs +journalctl -u hvac-content-8am -f + +# Noon run logs +journalctl -u hvac-content-12pm -f + +# All logs +journalctl -u hvac-content-* -f +``` + +## Manual Testing + +Run the service manually: +```bash +# Test morning run +sudo systemctl start hvac-content-8am.service + +# Check status +sudo systemctl status hvac-content-8am.service +``` + +## Stop/Disable Services + +If needed: +```bash +# Stop timers +sudo systemctl stop hvac-content-8am.timer +sudo systemctl stop hvac-content-12pm.timer + +# Disable from starting on boot +sudo systemctl disable hvac-content-8am.timer +sudo systemctl disable hvac-content-12pm.timer +``` + +## Troubleshooting + +### Service Fails to Start +1. Check logs: `journalctl -u hvac-content-8am -n 50` +2. Verify paths in service files +3. Check Python environment: `source .venv/bin/activate && python --version` +4. Test manual run: `cd /home/ben/dev/hvac-kia-content && uv run python run_api_production_v2.py` + +### Permission Issues +- Ensure user `ben` has read/write access to data directories +- Check NAS mount permissions: `ls -la /mnt/nas/hvacknowitall/` + +### Timer Not Triggering +- Check timer status: `systemctl status hvac-content-8am.timer` +- Verify system time: `timedatectl` +- Check timer schedule: `systemctl cat hvac-content-8am.timer` + +## Schedule + +The system runs automatically at: +- **8:00 AM ADT** - Morning content aggregation +- **12:00 PM ADT** - Noon content aggregation + +Both runs will: +1. Fetch new content from all sources +2. Merge with existing cumulative files +3. Update metrics and add captions where available +4. Archive previous versions +5. Sync to NAS at `/mnt/nas/hvacknowitall/` \ No newline at end of file diff --git a/deploy/hvac-content-12pm.service b/deploy/hvac-content-12pm.service new file mode 100644 index 0000000..80260a3 --- /dev/null +++ b/deploy/hvac-content-12pm.service @@ -0,0 +1,18 @@ +[Unit] +Description=HVAC Content Aggregation - 12 PM Run +After=network.target + +[Service] +Type=oneshot +User=ben +Group=ben +WorkingDirectory=/home/ben/dev/hvac-kia-content +Environment="PATH=/home/ben/.local/bin:/usr/local/bin:/usr/bin:/bin" +Environment="DISPLAY=:0" +Environment="XAUTHORITY=/run/user/1000/.mutter-Xwaylandauth.90WDB3" +ExecStart=/usr/bin/bash -c 'source /home/ben/dev/hvac-kia-content/.venv/bin/activate && python run_api_production_v2.py' +StandardOutput=journal +StandardError=journal + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/deploy/hvac-content-12pm.timer b/deploy/hvac-content-12pm.timer new file mode 100644 index 0000000..d0cf9ed --- /dev/null +++ b/deploy/hvac-content-12pm.timer @@ -0,0 +1,10 @@ +[Unit] +Description=HVAC Content Aggregation - 12 PM Timer +Requires=hvac-content-12pm.service + +[Timer] +OnCalendar=*-*-* 12:00:00 +Persistent=true + +[Install] +WantedBy=timers.target \ No newline at end of file diff --git a/deploy/hvac-content-8am.service b/deploy/hvac-content-8am.service new file mode 100644 index 0000000..4efd0aa --- /dev/null +++ b/deploy/hvac-content-8am.service @@ -0,0 +1,18 @@ +[Unit] +Description=HVAC Content Aggregation - 8 AM Run +After=network.target + +[Service] +Type=oneshot +User=ben +Group=ben +WorkingDirectory=/home/ben/dev/hvac-kia-content +Environment="PATH=/home/ben/.local/bin:/usr/local/bin:/usr/bin:/bin" +Environment="DISPLAY=:0" +Environment="XAUTHORITY=/run/user/1000/.mutter-Xwaylandauth.90WDB3" +ExecStart=/usr/bin/bash -c 'source /home/ben/dev/hvac-kia-content/.venv/bin/activate && python run_api_production_v2.py' +StandardOutput=journal +StandardError=journal + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/deploy/hvac-content-8am.timer b/deploy/hvac-content-8am.timer new file mode 100644 index 0000000..0f6c2b2 --- /dev/null +++ b/deploy/hvac-content-8am.timer @@ -0,0 +1,10 @@ +[Unit] +Description=HVAC Content Aggregation - 8 AM Timer +Requires=hvac-content-8am.service + +[Timer] +OnCalendar=*-*-* 08:00:00 +Persistent=true + +[Install] +WantedBy=timers.target \ No newline at end of file diff --git a/deploy/install.sh b/deploy/install.sh new file mode 100755 index 0000000..6f1fbd6 --- /dev/null +++ b/deploy/install.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Installation script for HVAC Content Aggregation systemd services + +echo "Installing HVAC Content Aggregation systemd services..." + +# Copy service files +sudo cp hvac-content-8am.service /etc/systemd/system/ +sudo cp hvac-content-8am.timer /etc/systemd/system/ +sudo cp hvac-content-12pm.service /etc/systemd/system/ +sudo cp hvac-content-12pm.timer /etc/systemd/system/ + +# Reload systemd +sudo systemctl daemon-reload + +# Enable timers +sudo systemctl enable hvac-content-8am.timer +sudo systemctl enable hvac-content-12pm.timer + +# Start timers +sudo systemctl start hvac-content-8am.timer +sudo systemctl start hvac-content-12pm.timer + +# Show status +echo "" +echo "Service status:" +sudo systemctl status hvac-content-8am.timer --no-pager +echo "" +sudo systemctl status hvac-content-12pm.timer --no-pager + +echo "" +echo "Installation complete!" +echo "" +echo "Useful commands:" +echo " View logs: journalctl -u hvac-content-8am -f" +echo " Check timer: systemctl list-timers | grep hvac" +echo " Manual run: sudo systemctl start hvac-content-8am.service" \ No newline at end of file