Files
LLM-Router-Stack/setup-sd-service.sh
T
2026-04-05 07:17:02 +00:00

59 lines
1.5 KiB
Bash

#!/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 <<EOF
[Unit]
Description=Stable Diffusion WebUI Forge
After=network.target
[Service]
Type=simple
User=$ACTUAL_USER
WorkingDirectory=$SD_DIR
ExecStart=$SD_DIR/webui.sh --api --listen --xformers --no-half-vae --medvram-sdxl
Restart=on-failure
RestartSec=10
Environment=HOME=$ACTUAL_HOME
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable stable-diffusion
systemctl start stable-diffusion
echo ""
echo "Service created and started!"
echo " Status: sudo systemctl status stable-diffusion"
echo " Logs: journalctl -u stable-diffusion -f"
echo " Stop: sudo systemctl stop stable-diffusion"
echo " Restart: sudo systemctl restart stable-diffusion"