From aa7ecb02afb34eb30eec7bfcf166159af7c03107 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 26 Apr 2017 13:44:32 -0600 Subject: [PATCH] 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 --- dist/init/mac-launchd/README.md | 40 ++++++++-- .../mac-launchd/com.caddyserver.web.plist | 80 ++++++++++++------- 2 files changed, 86 insertions(+), 34 deletions(-) diff --git a/dist/init/mac-launchd/README.md b/dist/init/mac-launchd/README.md index 168356775..8fbd0d9c5 100644 --- a/dist/init/mac-launchd/README.md +++ b/dist/init/mac-launchd/README.md @@ -1,12 +1,42 @@ launchd service for macOS ========================= -This is a sample file for a *launchd* service on Mac. -Edit the paths and email in the plist file to match your info. +This is a working sample file for a *launchd* service on Mac, which should be placed here: + +```bash +/Library/LaunchDaemons/com.caddyserver.web.plist +``` + +To create the proper directories as used in the example file: + +```bash +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 + +```bash +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/LaunchAgents/com.caddyserver.web.plist - $ launchctl unload ~/Library/LaunchAgents/com.caddyserver.web.plist +```bash +launchctl load /Library/LaunchDaemons/com.caddyserver.web.plist +launchctl unload /Library/LaunchDaemons/com.caddyserver.web.plist +``` -More information can be found in this blogpost: [Running Caddy as a service on macOS X server](https://denbeke.be/blog/software/running-caddy-as-a-service-on-macos-os-x-server/) \ No newline at end of file +To start on every boot use the `-w` flag (to write): + +```bash +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](https://denbeke.be/blog/software/running-caddy-as-a-service-on-macos-os-x-server/) diff --git a/dist/init/mac-launchd/com.caddyserver.web.plist b/dist/init/mac-launchd/com.caddyserver.web.plist index 517c3702e..980bfb2a1 100644 --- a/dist/init/mac-launchd/com.caddyserver.web.plist +++ b/dist/init/mac-launchd/com.caddyserver.web.plist @@ -1,31 +1,53 @@ - + - - Label - com.caddyserver.web - EnvironmentVariables - - HOME - /Users/mathias - - ProgramArguments - - sh - -c - ulimit -n 8192; cd /Users/mathias/Sites; ./caddy -agree -email my_email@domain.com -conf=/Users/mathias/Sites/Caddyfile - - UserName - www - RunAtLoad - - KeepAlive - - WorkingDirectory - /Users/mathias/Sites - StandardOutPath - /Users/mathias/Sites/caddy.log - StandardErrorPath - /Users/mathias/Sites/caddy_error.log - - \ No newline at end of file + + Label + Caddy + ProgramArguments + + /usr/local/bin/caddy + -agree + -conf + /etc/caddy/Caddyfile + -root + /var/tmp + + EnvironmentVariables + + CADDYPATH + /etc/ssl/caddy + + + UserName + root + GroupName + wheel + InitGroups + + + RunAtLoad + + KeepAlive + + Crashed + + + + SoftResourceLimits + + NumberOfFiles + 8192 + + HardResourceLimits + + + WorkingDirectory + /etc/ssl/caddy + + StandardErrorPath + /var/log/caddy/error.log + StandardOutPath + /var/log/caddy/info.log + +