0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00
caddy/dist/init/mac-launchd
AJ ONeal aa7ecb02af update macOS launchd example (#1600)
* update to match same paths as systemd

* update to match new launchd plist

* generated from scratch with LaunchControl, flawless

Had some issues with the previous go and found LaunchControl which made it easy to generate a perfectly correct launchd conf

* Update README.md
2017-04-26 13:44:32 -06:00
..
com.caddyserver.web.plist update macOS launchd example (#1600) 2017-04-26 13:44:32 -06:00
README.md update macOS launchd example (#1600) 2017-04-26 13:44:32 -06:00

launchd service for macOS

This is a working sample file for a launchd service on Mac, which should be placed here:

/Library/LaunchDaemons/com.caddyserver.web.plist

To create the proper directories as used in the example file:

sudo mkdir -p /etc/caddy /etc/ssl/caddy /var/log/caddy /usr/local/bin /var/tmp /srv/www/localhost
sudo touch /etc/caddy/Caddyfile
sudo chown root:wheel -R /usr/local/bin/caddy /Library/LaunchDaemons/
sudo chown _www:_www -R /etc/caddy /etc/ssl/caddy /var/log/caddy
sudo chmod 0750 /etc/ssl/caddy

Create a simple web page and Caddyfile

sudo bash -c 'echo "Hello, World!" > /srv/www/localhost/index.html'
sudo bash -c 'echo "http://localhost {
    root /srv/www/localhost
}" >> /etc/caddy/Caddyfile'

Start and Stop the Caddy launchd service using the following commands:

launchctl load /Library/LaunchDaemons/com.caddyserver.web.plist
launchctl unload /Library/LaunchDaemons/com.caddyserver.web.plist

To start on every boot use the -w flag (to write):

launchctl load -w /Library/LaunchAgents/com.caddyserver.web.plist

More information can be found in this blogpost: Running Caddy as a service on macOS X server