Created
January 19, 2017 01:46
-
-
Save monobilisim/071a3a9bdc0455902a5966a07a33987c to your computer and use it in GitHub Desktop.
Caddy init.d file for CentOS 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
DESC="the caddy web server" | |
NAME=caddy | |
DAEMON=$(which caddy) | |
DAEMONUSER=webapps | |
EMAIL=root@localhost | |
PIDFILE=/var/run/$NAME.pid | |
LOCKFILE=/var/lock/subsys/$NAME | |
LOGFILE=/var/log/caddy/$NAME.log | |
CONFIGFILE=/etc/caddy/Caddyfile | |
DAEMONOPTS="-agree=true -email=$EMAIL -pidfile=$PIDFILE -log=$LOGFILE -conf=$CONFIGFILE" | |
USERBIND="setcap cap_net_bind_service=+ep" | |
STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/5/KILL/5}" | |
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 -p $PIDFILE -l $LOCKFILE $DAEMON $DAEMONOPTS | |
} | |
stop() { | |
kill -9 $(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 | |
;; | |
restart) | |
echo "Restarting $NAME" | |
stop | |
start | |
;; | |
status) | |
status | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart|status}" | |
exit 2 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, Thanks for sharing. Well done!
I've forked and modified to run caddy from unprivileged (regular) user.
Maybe it helps somebody.