Skip to content

Instantly share code, notes, and snippets.

@coocheenin
Forked from monobilisim/caddy
Last active June 13, 2017 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coocheenin/9d6cd2a0f3a148c24c9f2c6649c63643 to your computer and use it in GitHub Desktop.
Save coocheenin/9d6cd2a0f3a148c24c9f2c6649c63643 to your computer and use it in GitHub Desktop.
Caddy init.d script for CentOS 6 (Unprivileged User Edition)
#!/bin/sh
### BEGIN INIT INFO
# Provides: caddy
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the caddy web server
# Description: starts caddy using start-stop-daemon
### END INIT INFO
# Original Author: Frédéric Galusik (fredg)
# Maintainer: Daniel van Dorp (djvdorp)
# Modified by: Mono Bilişim (monobilisim)
## yum install -y daemonize
# Modified To Run From Unprivileged User: by @coocheenin
DESC="the caddy web server"
NAME=caddy
DAEMON=/usr/local/bin/caddy
DAEMONUSER=www-data
PIDFILE=/var/run/$NAME.pid
LOCKFILE=/var/lock/subsys/$NAME
LOGDIR=/var/log/caddy
LOGFILE=$LOGDIR/$NAME.log
CONFIGFILE=/etc/caddy/Caddyfile
DAEMONOPTS="-agree=true -conf=$CONFIGFILE -log=$LOGFILE"
CMD="${DAEMON} ${DAEMONOPTS}"
USERBIND="setcap cap_net_bind_service=+ep"
test -x $DAEMON || exit 0
# Set the CADDYPATH; Let's Encrypt certificates will be written to this directory.
export CADDYPATH=/etc/caddy/ssl
# Set the ulimits
ulimit -n 8192
start() {
$USERBIND $DAEMON
daemonize -u $DAEMONUSER -p $PIDFILE -l $LOCKFILE -o $LOGDIR/stdout -e $LOGDIR/stderr $CMD
}
stop() {
kill -15 $(cat "$PIDFILE")
rm -f $PIDFILE $LOCKFILE
}
status() {
if [ -f $PIDFILE ]; then
if kill -0 $(cat "$PIDFILE"); then
echo "$NAME is running"
else
echo "$NAME process is dead, but pidfile exists"
fi
else
echo "$NAME is not running"
fi
}
case "$1" in
start)
echo "Starting $NAME"
start
;;
stop)
echo "Stopping $NAME"
stop
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 2
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment