caddy-retired/scripts/caddy

35 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

#!/bin/bash
SDIR=$(dirname "$(readlink -f "$0")") || exit
DIR=$(dirname "$SDIR") || exit
INSTANCE=${1:-default}
source $SDIR/library
echo $SDIR
get-caddy-bin # this sets $CADDY_BIN
CONF_DIR=$DIR/conf/$INSTANCE
CONF_SHARED_DIR=$DIR/conf/_shared
CONF=$CONF_DIR/caddy.conf
SCRIPT=$CONF_DIR/script
BIN=$DIR/bin/$CADDY_BIN
echo running caddy $BIN
[ ! -f "$BIN" ] && echo binary file $BIN does not exist && exit 1
[ ! -x "$BIN" ] && echo binary file $BIN is not executable && exit 1
[ ! -f "$CONF" ] && echo no configuration file $CONF && exit 1
if [ -f "$SCRIPT" ]; then
source $SCRIPT
fi
if [ ! $INVOCATION_ID ]; then
CAP="cap_net_bind_service+eip"
ISSET=$(getcap $BIN | grep $CAP )
if [ ! "$ISSET" ]; then
echo binary $BIN not set for binding port 80 by non-root users, attempting to set
sudo setcap $CAP $BIN
ISSET=$(getcap $BIN | grep $CAP)
echo after $ISSET
[ ! "$ISSET" ] && echo unable to set port binding && exit 1
fi
echo running caddy from commandline, enter caddy user password
su -c "$BIN run --config $CONF --adapter caddyfile" caddy
else
echo running caddy via systemd service
$BIN run --config $CONF --adapter caddyfile
fi