@ -27,43 +27,50 @@ _install_caddy_service() {
# setcap CAP_NET_BIND_SERVICE=+eip /usr/local/bin/caddy
# setcap CAP_NET_BIND_SERVICE=+eip /usr/local/bin/caddy
if [ [ $systemd ] ] ; then
if [ [ $systemd ] ] ; then
cp -f ${ caddy_tmp } init/linux-systemd/caddy.service /lib/systemd/system/
# cp -f ${caddy_tmp} init/linux-systemd/caddy.service /lib/systemd/system/
# if ! wget https://raw.githubusercontent.com/caddyserver/caddy/master/dist/init/linux-systemd/caddy.service -O /lib/systemd/system/caddy.service; then
# if ! wget https://raw.githubusercontent.com/caddyserver/caddy/master/dist/init/linux-systemd/caddy.service -O /lib/systemd/system/caddy.service; then
# echo -e "$red 下载 caddy.service 失败!$none" && exit 1
# echo -e "$red 下载 caddy.service 失败!$none" && exit 1
# fi
# fi
# sed -i "s/-log-timestamps=false//g" /lib/systemd/system/caddy.service
# sed -i "s/-log-timestamps=false//g" /lib/systemd/system/caddy.service
if [ [ ! $( grep "ReadWriteDirectories" /lib/systemd/system/caddy.service) ] ] ; then
# if [[ ! $(grep "ReadWriteDirectories" /lib/systemd/system/caddy.service) ]]; then
sed -i "/ReadWritePaths/a ReadWriteDirectories=/etc/ssl/caddy" /lib/systemd/system/caddy.service
# sed -i "/ReadWritePaths/a ReadWriteDirectories=/etc/ssl/caddy" /lib/systemd/system/caddy.service
fi
# fi
sed -i "s/www-data/root/g" /lib/systemd/system/caddy.service
# sed -i "s/www-data/root/g" /lib/systemd/system/caddy.service
# sed -i "/on-abnormal/a RestartSec=3" /lib/systemd/system/caddy.service
# sed -i "/on-abnormal/a RestartSec=3" /lib/systemd/system/caddy.service
# sed -i "s/on-abnormal/always/" /lib/systemd/system/caddy.service
# sed -i "s/on-abnormal/always/" /lib/systemd/system/caddy.service
#### 。。。。。 Warning.....Warning.......Warning........Warning......
#### 。。。。。 Warning.....Warning.......Warning........Warning......
#### 。。。。。 use root user run caddy...
#### 。。。。。 use root user run caddy...
# cat >/lib/systemd/system/caddy.service <<-EOF
cat >/lib/systemd/system/caddy.service <<-EOF
# [Unit ]
[ Unit]
# Description=Caddy HTTP/2 web server
Description = Caddy HTTP/2 web server
# Documentation=https://caddyserver.com/docs
Documentation = https://caddyserver.com/docs
# After=network.target
After = network.target
# Wants=network.target
Wants = network.target
# [Service]
[ Service]
# Restart=always
Restart = on-abnormal
# RestartSec=3
User = root
# Environment=CADDYPATH=/root/.caddy
Group = root
# ExecStart=/usr/local/bin/caddy -log stdout -agree=true -conf=/etc/caddy/Caddyfile -root=/var/tmp
Environment = CADDYPATH = /etc/ssl/caddy
# ExecReload=/bin/kill -USR1 $MAINPID
ExecStart = /usr/local/bin/caddy -log stdout -log-timestamps= false -agree= true -conf= /etc/caddy/Caddyfile -root= /var/tmp
# KillMode=mixed
ExecReload = /bin/kill -USR1 \$ MAINPID
# KillSignal=SIGQUIT
KillMode = mixed
# TimeoutStopSec=5s
KillSignal = SIGQUIT
# LimitNOFILE=1048576
TimeoutStopSec = 5s
# LimitNPROC=512
LimitNOFILE = 1048576
LimitNPROC = 512
PrivateTmp = true
PrivateDevices = false
ProtectHome = true
ProtectSystem = full
ReadWritePaths = /etc/ssl/caddy
ReadWriteDirectories = /etc/ssl/caddy
# [Install]
[ Install]
# WantedBy=multi-user.target
WantedBy = multi-user.target
# EOF
EOF
systemctl enable caddy
systemctl enable caddy
else
else
cp -f ${ caddy_tmp } init/linux-sysvinit/caddy /etc/init.d/caddy
cp -f ${ caddy_tmp } init/linux-sysvinit/caddy /etc/init.d/caddy