Skip to content

Instantly share code, notes, and snippets.

@stpettersens
Last active November 20, 2015 14:33
Show Gist options
  • Save stpettersens/1320e6c410a64c9f446b to your computer and use it in GitHub Desktop.
Save stpettersens/1320e6c410a64c9f446b to your computer and use it in GitHub Desktop.
Wrapper script for Caddy server (shell script and Caddyfile to use with it).
#!/bin/sh
############################################################################
# Run Caddy for the current working directory as a daemon using daemonize.
# Place in serving root.
#
# Prerequisites:
# * caddy installed to /opt/caddy/caddy (http://caddyserver.com)
# * daemonize (http://software.clapper.org/daemonize)
#
# Just run: ./caddy.sh (chmod +x caddy.sh before first run).
# Check server is running with: ps -e | grep caddy
############################################################################
daemonize -c $(pwd) /opt/caddy/caddy
echo "Started Caddy server for" $(pwd)
# Serve to outside world on port 2015.
0.0.0.0:2015
# This rewrite stops caddy.sh being served.
rewrite {
regexp caddy\.sh
to /
}
@mholt
Copy link

mholt commented Nov 19, 2015

Probably best to just not put caddy.sh in your site 😉

@mholt
Copy link

mholt commented Nov 19, 2015

Also, Caddy may restart which changes its process id. Does that affect daemonize?

@stpettersens
Copy link
Author

  1. Yes, alternatively you can see put it above and set the root in the Caddyfile, right? (would then need to tweak the $(pwd) part, but no problem).
  2. If the process ID changes that doesn't affect demonize, because its not quite the same as running a service from what I understand. Just now I just kill Caddy with its PID which might change admittedly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment