29 lines
1009 B
Plaintext
29 lines
1009 B
Plaintext
|
#!/bin/bash
|
||
|
SDIR=$(dirname "$(readlink -f "$0")") || exit
|
||
|
DIR=$(dirname "$SDIR") || exit
|
||
|
source $SDIR/library
|
||
|
CONF=$DIR/conf/${1:-caddy}.conf
|
||
|
get-caddy-name # this sets $CADDY_BIN
|
||
|
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 [ $INVOCATION_ID ]; then
|
||
|
echo running under systemd service
|
||
|
else
|
||
|
CAP="cap_net_bind_service+eip"
|
||
|
ISSET=$(getcap $BIN | grep $CAP )
|
||
|
echo before $ISSET
|
||
|
if [ ! "$ISSET" ]; then
|
||
|
echo binary 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
|
||
|
fi
|
||
|
echo $BIN run --config $CONF --adapter caddyfile
|
||
|
set-env $DIR/env
|
||
|
su -c "for f in $DIR/env/*.env; do source $f; done && $BIN run --config $CONF --adapter caddyfile" - caddy
|