# DaemonControl - Installation Guide ## Quick Start (Milestone 2) ### 1. Prerequisites - Python 3.8 or higher - Linux operating system - pip (Python package manager) ### 2. Install Dependencies ```bash # Option 1: Using pip (recommended) pip install apscheduler # Option 2: Install all dependencies from requirements.txt # (if pip is available) pip install -r requirements.txt ``` **Required for Milestone 2:** - `apscheduler==3.10.4` - Job scheduling with cron support **Optional (for future milestones):** - `PyQt6==6.7.0` - System tray and GUI (Milestone 3+) - `python-dateutil==2.9.0` - Date/time utilities ### 3. Verify Installation ```bash # Test core modules python3 -c "from core import DatabaseManager; print('✓ Core OK')" # Test daemon modules (requires apscheduler) python3 -c "from daemon import SchedulerDaemon; print('✓ Daemon OK')" ``` ### 4. Create Test Jobs ```bash # Create sample jobs with schedules python3 create_test_jobs.py ``` This creates: - `echo_test` - Runs every minute - `date_display` - Runs every 5 minutes - `system_info` - Runs hourly ### 5. Start the Daemon ```bash # Start in foreground (use Ctrl+C to stop) python3 start_daemon.py ``` You should see: ``` ====================================================================== DaemonControl - Job Scheduling Daemon ====================================================================== Starting daemon in foreground mode... Press Ctrl+C to stop ``` ### 6. Monitor Execution In another terminal: ```bash # Watch daemon log tail -f ~/.config/daemon-control/logs/daemon.log # Watch job execution logs tail -f ~/.config/daemon-control/logs/executions/*.log ``` ### 7. Query Execution History ```bash python3 -c " from core import DatabaseManager db = DatabaseManager() with db.get_connection() as conn: cursor = conn.execute(''' SELECT j.name, e.status, e.start_time, e.exit_code FROM executions e JOIN jobs j ON e.job_id = j.id ORDER BY e.start_time DESC LIMIT 10 ''') print('Recent Executions:') print('-' * 60) for row in cursor: print(f'{row[0]:20} {row[1]:10} {row[2]:20} exit={row[3]}') " ``` ## Installation Without pip If `pip` is not available, you can try: ### Option 1: Install via apt (Ubuntu/Debian) ```bash sudo apt update sudo apt install python3-apscheduler ``` ### Option 2: Manual Installation Download and install APScheduler manually: ```bash # Download APScheduler wget https://files.pythonhosted.org/packages/.../APScheduler-3.10.4.tar.gz tar -xzf APScheduler-3.10.4.tar.gz cd APScheduler-3.10.4 # Install (without pip) python3 setup.py install --user ``` ## Troubleshooting ### "ModuleNotFoundError: No module named 'apscheduler'" **Solution:** Install APScheduler: ```bash pip install apscheduler # or sudo apt install python3-apscheduler ``` ### "No module named pip" **Solution:** Install pip: ```bash sudo apt update sudo apt install python3-pip ``` ### "Database is locked" **Solution:** - Ensure only one daemon instance is running - Check file permissions on `~/.config/daemon-control/` - Kill any stale processes: `pkill -f start_daemon.py` ### Daemon doesn't start **Check:** 1. Python version: `python3 --version` (needs 3.8+) 2. Dependencies installed: `python3 -c "import apscheduler"` 3. Database accessible: `ls -la ~/.config/daemon-control/daemon.db` 4. Log file for errors: `cat ~/.config/daemon-control/logs/daemon.log` ### Jobs don't execute **Verify:** 1. Jobs are enabled: `python3 -c "from core import DatabaseManager; db = DatabaseManager(); print(db.get_enabled_jobs())"` 2. Schedules exist: Check database schedules table 3. Cron expression is valid 4. Daemon is running: `ps aux | grep start_daemon` ## Directory Structure After installation, these directories will be created: ``` ~/.config/daemon-control/ ├── config.json # Configuration ├── daemon.db # SQLite database └── logs/ ├── daemon.log # Daemon log └── executions/ # Job execution logs ├── echo_test_20231206_101500.log ├── date_display_20231206_102000.log └── ... ``` ## Configuration Edit configuration file: ```bash nano ~/.config/daemon-control/config.json ``` Key settings: ```json { "daemon": { "max_concurrent_jobs": 3, # Max jobs running at once "default_timeout": 3600, # Default job timeout (seconds) "check_interval": 60 # Scheduler check interval }, "logging": { "level": "INFO", # DEBUG, INFO, WARNING, ERROR "retention_days": 30 # Log retention period } } ``` ## Next Steps Once the daemon is working: 1. **Create your own jobs:** ```python from core import DatabaseManager from datetime import datetime db = DatabaseManager() job_id = db.create_job( name="my_job", job_type="script", executable_path="/path/to/script.py", timeout=600 ) # Add schedule now = datetime.now().isoformat() with db.get_connection() as conn: conn.execute( "INSERT INTO schedules (job_id, cron_expression, enabled, created_at, updated_at) " "VALUES (?, ?, 1, ?, ?)", (job_id, "0 2 * * *", now, now) # Daily at 2 AM ) ``` 2. **Monitor and manage:** - View logs in `~/.config/daemon-control/logs/` - Query database for execution history - Adjust schedules as needed 3. **Advanced usage:** - Setup systemd service for auto-start - Configure log rotation - Implement job chaining (future milestone) ## Support For issues or questions: - Check README.md for detailed documentation - Review logs in ~/.config/daemon-control/logs/ - Open an issue on GitHub --- **Current Version:** Milestone 2 - Daemon Base **Status:** ✅ Complete and functional (requires apscheduler)