Add systemd service and installation guide for LGL Team

- Add wrike-monitor-lgl.service for systemd deployment
- Add INSTALLATION_LGL.md with complete setup instructions
- Include service management commands
- Document troubleshooting steps
- Add duplicate detection monitoring guide
This commit is contained in:
Dave Porter 2025-12-17 16:22:00 -05:00
parent 026d97d491
commit 4fd9bbb1fc
2 changed files with 361 additions and 0 deletions

338
INSTALLATION_LGL.md Normal file
View file

@ -0,0 +1,338 @@
# Installation Guide - LGL Team Monitor Service
This guide covers installing the **wrike_monitor_lgl.py** service for the LGL Team (Production) board.
## Prerequisites
- Linux server with systemd
- Python 3.6 or higher
- Root or sudo access
- Active Wrike API token with access to LGL Team space
## Installation Steps
### 1. Prepare the Installation Directory
```bash
# Create installation directory
sudo mkdir -p /root/wrike-import
# Copy files to server
sudo cp wrike_monitor_lgl.py /root/wrike-import/
sudo cp requirements.txt /root/wrike-import/
sudo cp wrike-monitor-lgl.service /etc/systemd/system/
```
### 2. Install Python Dependencies
```bash
cd /root/wrike-import
# Install dependencies
pip3 install -r requirements.txt
```
### 3. Configure the Script
Edit `/root/wrike-import/wrike_monitor_lgl.py` and update paths (lines 41-44):
```python
# === PATHS (EDIT FOR SERVER) ===
HOT_FOLDER = Path("/path/to/json_files")
PROCESSED_FOLDER = Path("/path/to/processed")
FAILED_FOLDER = Path("/path/to/processed/Failed")
REPORTS_DIR = Path("/path/to/processed/reports")
```
**Note:** API token and LGL Team configuration are already set in the script.
### 4. Create Required Directories
```bash
# Create directories (adjust paths to match your configuration)
sudo mkdir -p /path/to/json_files
sudo mkdir -p /path/to/processed
sudo mkdir -p /path/to/processed/Failed
sudo mkdir -p /path/to/processed/reports
# Set permissions
sudo chmod 755 /path/to/json_files
sudo chmod 755 /path/to/processed
```
### 5. Test the Script
Before enabling the service, test the script manually:
```bash
cd /root/wrike-import
python3 wrike_monitor_lgl.py
```
**Expected output:**
```
2025-12-17 15:00:00 - INFO - Wrike Monitor initialized - Target: LGL Team
2025-12-17 15:00:00 - INFO - 🔍 Scanning for existing JSON files...
2025-12-17 15:00:00 - INFO - Found 0 existing files
2025-12-17 15:00:00 - INFO - ✅ No existing files to process
2025-12-17 15:00:00 - INFO - 🎯 Startup complete - switching to real-time monitoring
2025-12-17 15:00:00 - INFO - 🛡️ Real-time monitoring active on: /path/to/json_files
2025-12-17 15:00:00 - INFO - 📧 Daily reports at 19:00 to daveporter@oliver.agency
```
Press `Ctrl+C` to stop the test.
### 6. Install and Enable the Service
```bash
# Reload systemd to recognize the new service
sudo systemctl daemon-reload
# Enable the service to start on boot
sudo systemctl enable wrike-monitor-lgl.service
# Start the service
sudo systemctl start wrike-monitor-lgl.service
```
### 7. Verify Service Status
```bash
# Check service status
sudo systemctl status wrike-monitor-lgl.service
# View real-time logs
sudo journalctl -u wrike-monitor-lgl.service -f
# View recent logs
sudo journalctl -u wrike-monitor-lgl.service -n 100
```
## Service Management Commands
```bash
# Start the service
sudo systemctl start wrike-monitor-lgl.service
# Stop the service
sudo systemctl stop wrike-monitor-lgl.service
# Restart the service
sudo systemctl restart wrike-monitor-lgl.service
# Check status
sudo systemctl status wrike-monitor-lgl.service
# View logs
sudo journalctl -u wrike-monitor-lgl.service -f
# Disable service (won't start on boot)
sudo systemctl disable wrike-monitor-lgl.service
# Enable service (will start on boot)
sudo systemctl enable wrike-monitor-lgl.service
```
## Monitoring and Logs
### View Service Logs
```bash
# Real-time logs
sudo journalctl -u wrike-monitor-lgl.service -f
# Last 100 lines
sudo journalctl -u wrike-monitor-lgl.service -n 100
# Logs since today
sudo journalctl -u wrike-monitor-lgl.service --since today
# Logs from specific date
sudo journalctl -u wrike-monitor-lgl.service --since "2025-12-17"
```
### Check Application Logs
Application logs are stored in the configured `REPORTS_DIR`:
```bash
# View monitor log
tail -f /path/to/processed/reports/wrike_monitor.log
# View daily reports
ls -lt /path/to/processed/reports/daily_report_*.txt
```
## Daily Reports
The service sends daily email reports at **7:00 PM** to the configured email addresses.
**Email settings** are configured in the script (lines 71-82):
- SMTP Server: smtp.mailgun.org
- Recipients: daveporter@oliver.agency
Reports include:
- Total files processed
- Tasks created vs skipped (duplicates)
- Folder breakdown
- Hourly breakdown
- Error details (if any)
## Duplicate Detection
The LGL Team version includes **recursive duplicate detection**:
- ✅ Searches entire "Business Areas" folder
- ✅ Checks all subfolders at any depth
- ✅ Extracts OMG# from HTML links
- ✅ Skips if OMG# exists anywhere in Business Areas
- ✅ No duplicates will be created
**Example log output:**
```
2025-12-17 15:30:45 - INFO - ✓ Found existing deliverable with OMG# 1988861 in Business Areas: Bissell Pet Products (MQAAAABpUdQ9)
2025-12-17 15:30:45 - INFO - ⊙ Deliverable already exists: PowerClean Corded Mass User Guide (#5791330) - skipping
```
## Troubleshooting
### Service Won't Start
```bash
# Check service status and errors
sudo systemctl status wrike-monitor-lgl.service
# View detailed error logs
sudo journalctl -u wrike-monitor-lgl.service -n 50
```
**Common issues:**
- Python dependencies not installed → Run `pip3 install -r requirements.txt`
- Incorrect paths in script → Edit paths in wrike_monitor_lgl.py
- Permissions issues → Check folder permissions and ownership
- API token invalid → Verify token in script configuration
### Service Crashes/Restarts
The service is configured to automatically restart (`Restart=always`) with a 10-second delay.
To investigate crashes:
```bash
# View crash logs
sudo journalctl -u wrike-monitor-lgl.service | grep -i "error\|exception\|failed"
```
### Files Not Being Processed
1. **Check service is running:**
```bash
sudo systemctl status wrike-monitor-lgl.service
```
2. **Verify folder monitoring:**
```bash
# Should show monitoring message in logs
sudo journalctl -u wrike-monitor-lgl.service | grep "monitoring active"
```
3. **Check file permissions:**
```bash
ls -la /path/to/json_files/
```
4. **Test manually:**
```bash
# Stop service
sudo systemctl stop wrike-monitor-lgl.service
# Run manually to see errors
cd /root/wrike-import
python3 wrike_monitor_lgl.py
```
### Duplicate Files Still Being Created
If duplicates are being created despite the detection logic:
1. **Check logs for duplicate detection:**
```bash
sudo journalctl -u wrike-monitor-lgl.service | grep "Found existing deliverable"
```
2. **Verify Business Areas folder exists** in Wrike LGL Team space
3. **Check OMG# format** - should be HTML links, not plain text
4. **Test duplicate detection manually:**
```bash
cd /root/wrike-import
python3 test_duplicate_detection.py
```
## Running Staging and LGL Team Together
You can run both services simultaneously:
```bash
# Staging version
sudo systemctl start wrike-monitor.service
# LGL Team version
sudo systemctl start wrike-monitor-lgl.service
# Check both are running
sudo systemctl status wrike-monitor.service
sudo systemctl status wrike-monitor-lgl.service
```
Each service monitors its own hot folder and targets its own Wrike space.
## Updating the Service
To update the script:
```bash
# Stop the service
sudo systemctl stop wrike-monitor-lgl.service
# Update the script
sudo cp new_wrike_monitor_lgl.py /root/wrike-import/wrike_monitor_lgl.py
# Start the service
sudo systemctl start wrike-monitor-lgl.service
# Verify it's running
sudo systemctl status wrike-monitor-lgl.service
```
## Uninstalling
To remove the service:
```bash
# Stop and disable the service
sudo systemctl stop wrike-monitor-lgl.service
sudo systemctl disable wrike-monitor-lgl.service
# Remove service file
sudo rm /etc/systemd/system/wrike-monitor-lgl.service
# Reload systemd
sudo systemctl daemon-reload
# Optionally remove installation directory
sudo rm -rf /root/wrike-import
```
## Support
For issues or questions:
1. Check logs: `sudo journalctl -u wrike-monitor-lgl.service -f`
2. Review the main [README.md](README.md)
3. Check Wrike API status: https://status.wrike.com
---
**Last Updated**: December 2025
**Service Name**: wrike-monitor-lgl.service
**Target Board**: LGL Team (Production)

23
wrike-monitor-lgl.service Normal file
View file

@ -0,0 +1,23 @@
[Unit]
Description=Wrike Import Monitor Service - LGL Team (Production)
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/root/wrike-import
ExecStart=/usr/bin/python3 /root/wrike-import/wrike_monitor_lgl.py
Restart=always
RestartSec=10
# Logging
StandardOutput=journal
StandardError=journal
SyslogIdentifier=wrike-monitor-lgl
# Resource limits
MemoryLimit=1G
CPUQuota=50%
[Install]
WantedBy=multi-user.target