Run Stable Diffusion WebUI AUTOMATIC111 As Background Service
Stable Diffusion, the revolutionary AI image generation model, has taken the world by storm. Its ease of use through the AUTOMATIC1111 WebUI has opened doors for artists, creators, and even curious tech enthusiasts. But what if you want to access its magic anytime, without manually launching the interface? That’s where running AUTOMATIC1111 as a system service comes in.
This guide delves into the process of transforming your AUTOMATIC1111 instance into a self-starting, always-on guardian of image creation. By the end, you’ll be generating fantastical landscapes, breathtaking portraits, and everything in between, with just a quick line of code.
Before you begin:
- Ensure you have a working AUTOMATIC1111 installation with a functioning model.
- Familiarity with the command line and basic Linux administration is recommended.
- Choose your platform: the guide focuses on Linux (specifically Ubuntu), but adaptations for Windows are available online.
- Setting Up Environment and Dependencies:
Follow this guide on how to install python environment. Let’s call sdwebui.
2. Create a shell script to activate the virtual environment:
First, create a shell script that activates the Pyenv virtual environment and then starts Stable Diffusion WebUI. For example, create a file named start-sdwedui.sh:
#!/bin/bash
cd
echo $USER
pwd
source .bashrc
source .bash_profile
# Activate the virtual environment
pyenv activate sdwebui
# Start Stable Diffusion WebUI
# Listen on 0.0.0.0 instead default as 127.0.0.1
./webui.sh --listen3. Create a systemd service unit file:
Create a systemd unit file to manage the Stable Diffusion WebUI service. Open a text editor and create a file, e.g., /etc/systemd/system/sdwebui.service:
sudo nano /etc/systemd/system/sdwebui.service
Add the following content to the file, adjusting the paths and options as needed:
[Unit]
Description=Stable Diffusion WebUI
[Service]
User=ec2-user
Group=ec2-user
Type=simple
ExecStart=/home/ec2-user/start-sdwebui.sh
[Install]
WantedBy=multi-user.target4. Enable and start the service:
sudo systemctl enable sdwebui
sudo systemctl start sdwebuiThe service will now start automatically on boot and can be managed using systemctl.
5. Check status and Verify
sudo systemctl status sdwebui -l
Restart if needed via:
sudo systemctl daemon-reload sudo systemctl restart sdwebui
6. View full logs
Just use the journalctl command, as in:
journalctl -u service-name.service
Or, to see only log messages for the current boot:
journalctl -u service-name.service -b
For things named .service, you can actually just use , as in:
journalctl -u service-name
Conclusion:
Running AUTOMATIC1111 as a system service makes Stable Diffusion an ever-present tool in your creative arsenal. Now, inspiration can strike anytime, and generating magnificent visuals is just a browser window away. Remember, be responsible with your newfound AI powers, unleash your imagination, and keep learning — the possibilities are endless!





