#!/bin/bash # Install DaemonControl as systemd service set -e echo "========================================" echo " DaemonControl Service Installation" echo "========================================" echo # Check if running with sudo if [ "$EUID" -ne 0 ]; then echo "⚠️ This script needs sudo privileges to install systemd service" echo " Re-running with sudo..." echo exec sudo "$0" "$@" fi # Get the directory where the script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SERVICE_FILE="$SCRIPT_DIR/daemoncontrol.service" SYSTEMD_DIR="/etc/systemd/system" echo "📁 Project directory: $SCRIPT_DIR" echo "📄 Service file: $SERVICE_FILE" echo # Check if service file exists if [ ! -f "$SERVICE_FILE" ]; then echo "❌ Service file not found: $SERVICE_FILE" exit 1 fi # Copy service file to systemd directory echo "📋 Copying service file to $SYSTEMD_DIR..." cp "$SERVICE_FILE" "$SYSTEMD_DIR/daemoncontrol.service" # Reload systemd daemon echo "🔄 Reloading systemd daemon..." systemctl daemon-reload # Enable service to start on boot echo "✅ Enabling service to start on boot..." systemctl enable daemoncontrol.service echo echo "========================================" echo " Installation Complete! ✅" echo "========================================" echo echo "Available commands:" echo " sudo systemctl start daemoncontrol - Start the daemon" echo " sudo systemctl stop daemoncontrol - Stop the daemon" echo " sudo systemctl restart daemoncontrol - Restart the daemon" echo " sudo systemctl status daemoncontrol - Check daemon status" echo " sudo systemctl disable daemoncontrol - Disable auto-start" echo " sudo journalctl -u daemoncontrol -f - View logs (live)" echo echo "To start the daemon now, run:" echo " sudo systemctl start daemoncontrol" echo