#!/bin/bash # Create a systemd service for Stable Diffusion WebUI Forge # Run this AFTER setup-sd.sh has completed and you've verified the WebUI starts correctly # # IMPORTANT: Run this script with sudo, but from your regular user account: # sudo ./setup-sd-service.sh set -e # Detect the actual user (not root) when run with sudo if [ -n "$SUDO_USER" ]; then ACTUAL_USER="$SUDO_USER" ACTUAL_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6) else ACTUAL_USER=$(whoami) ACTUAL_HOME="$HOME" fi SD_DIR="$ACTUAL_HOME/stable-diffusion-webui" SERVICE_FILE="/etc/systemd/system/stable-diffusion.service" if [ ! -d "$SD_DIR" ]; then echo "ERROR: $SD_DIR not found. Run setup-sd.sh first." exit 1 fi echo "Creating systemd service for Stable Diffusion WebUI Forge..." echo " User: $ACTUAL_USER" echo " Directory: $SD_DIR" tee "$SERVICE_FILE" > /dev/null <