Skip to content

Instantly share code, notes, and snippets.

@trojblue
Last active March 4, 2023 00:44
Show Gist options
  • Save trojblue/aad0e71c0732a89e4f412402945add38 to your computer and use it in GitHub Desktop.
Save trojblue/aad0e71c0732a89e4f412402945add38 to your computer and use it in GitHub Desktop.
Checks if stable diffusion webui is not running every 5 seconds, and restarts if it is killed
#!/bin/bash
# Start the program
cd /root/webui
source /root/miniconda3/bin/activate /root/miniconda3/envs/py310
python ~/webui/launch.py --lowram --no-half-vae --port 6006 --disable-console-progressbars --disable-safe-unpickle --api & pid=$!
# Wait for the program to start
while ! netstat -an | grep "LISTEN" | grep ":6006" > /dev/null; do
sleep 1
done
echo "Program is running with PID $pid"
# Check if the program is still running
while kill -0 $pid > /dev/null 2>&1; do
# Check if port 6006 is in use
netstat -an | grep "LISTEN" | grep ":6006" > /dev/null
result=$?
# If port 6006 is not in use, restart the program
if [ $result -ne 0 ]; then
echo "Port 6006 is not in use. Running command..."
cd /root/webui
source /root/miniconda3/bin/activate /root/miniconda3/envs/py310
python ~/webui/launch.py --lowram --no-half-vae --port 6006 --disable-console-progressbars --disable-safe-unpickle --api & pid=$!
echo "Program is running with PID $pid"
fi
# Sleep for 5 seconds before checking again
sleep 5
done
echo "Program has stopped"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment