Skip to content

Instantly share code, notes, and snippets.

@rsik
Last active June 1, 2024 04:46
Show Gist options
  • Save rsik/149852d7ec857ec046b710910a05128d to your computer and use it in GitHub Desktop.
Save rsik/149852d7ec857ec046b710910a05128d to your computer and use it in GitHub Desktop.
AUTOMATIC1111 Ollama + Stable Diffusion + Caddy on MacOS service plist

😄 USE AT YOUR OWN RISK - THIS IS PROVIDED AS IS AND YOU ARE IN CHARGE OF YOUR OWN SECURITY 😄

Location + command for plist

sudo launchctl bootstrap system /Library/LaunchDaemons/com.service.sd.plist # loads+starts service

sudo launchctl bootout system /Library/LaunchDaemons/com.service.sd.plist # unloads+stops service

Replace com.service.sd.plist with other plist files for other services. Perfect for local or remote box like a Mac Studio. These services will start on boot and require no login! 🙏

SD defaults to port 7860. Ollama defaults to port 11434. I use caddy to add SSL. Then you may use tools like open-webui and mods that can point to this ollama + SD, api keys, openai compatible api and more!

Why not User / Group in plist?

🤷 not sure but the below does not work for me, so I used sudo -u

<key>UserName</key>
<string>user</string>
<key>Group</key>
<string>staff</string>

Other important command(s) / notes

brew install caddy ollama # I used these binaries for the services

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=name" # for caddy

Make sure to allow through firewall if it's on!

:443 {
tls /path/to/caddy/cert.pem /path/to/caddyfiles/key.pem
reverse_proxy 127.0.0.1:11434 {
header_up Host {host}
header_up Origin ""
header_up Referer ""
}
} # for ollama
:8443 {
tls /path/to/caddy/cert.pem /path/to/caddyfiles/key.pem
reverse_proxy 127.0.0.1:7860
} # for stable diffusion
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.service.caddy</string>
<key>ProgramArguments</key>
<array>
<string>/opt/homebrew/bin/caddy</string>
<string>run</string>
<string>--config</string>
<string>/path/to/caddy/Caddyfile</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<dict>
<key>NetworkState</key>
<true/>
</dict>
<key>StandardOutPath</key>
<string>/path/to/caddy/log/caddy.log</string>
<key>StandardErrorPath</key>
<string>/path/to/caddy/log/caddy-error.log</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin</string>
<key>HOME</key>
<string>/path/to/caddy/</string>
</dict>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- Labels are used to uniquely identify jobs when talking to launchd -->
<key>Label</key>
<string>com.service.ollama</string>
<!-- This array of strings maps one-to-one with your main()'s argv -->
<key>ProgramArguments</key>
<array>
<!-- Specify the full path to the executable if it's not in launchd's PATH -->
<string>/opt/homebrew/bin/ollama</string>
<string>serve</string>
</array>
<!-- Set Environment Variables -->
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin</string>
<key>OLLAMA_ORIGINS</key>
<string>*</string>
<key>OLLAMA_HOST</key>
<string>0.0.0.0:11434</string>
<key>OLLAMA_MODELS</key>
<string>/path/to/ollama/model</string>
<key>OLLAMA_KEEP_ALIVE</key>
<string>5m</string>
<key>HOME</key>
<string>/path/to/ollama</string>
<!-- Add more environment variables as needed -->
</dict>
<!-- Logging -->
<key>StandardOutPath</key>
<string>/path/to/ollama/log/com.service.ollama.out.log</string>
<key>StandardErrorPath</key>
<string>/path/to/ollama/log/com.service.ollama.err.log</string>
<!-- Additions for better service management -->
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.service.sd</string>
<key>ProgramArguments</key>
<array>
<string>sudo</string>
<string>-u</string>
<string>[user]</string>
<string>/path/to/stable-diffusion-webui/webui.sh</string>
<string>--api</string>
</array>
<key>WorkingDirectory</key>
<string>/path/to/stable-diffusion-webui</string>
<key>StandardOutPath</key>
<string>/path/to/log/com.service.sd.out.log</string>
<key>StandardErrorPath</key>
<string>/path/to/com.service.sd.err.log</string>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment