Last active
February 28, 2024 10:49
-
-
Save Denperidge/cacb08725d8ca3942a207fc7bfdc6bd3 to your computer and use it in GitHub Desktop.
A simple bash script that installs caddy as a service on your Linux system, merely automating the official steps described here https://caddyserver.com/docs/install#linux-service
This file contains 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/bash | |
echo "Enter your download url that you made from here: https://caddyserver.com/download" | |
read downloadurl | |
curl --output caddy $downloadurl | |
chmod +x caddy | |
sudo mv caddy /usr/bin | |
# Confirmation dialogue taken from https://stackoverflow.com/a/1885534/5522348 | |
read -p "Do you want to allow caddy to use low-level ports? (E.g. 80 and 443) [y/N]" | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
sudo setcap 'cap_net_bind_service=+ep' /usr/bin/caddy | |
fi | |
sudo groupadd --system caddy | |
sudo useradd --system \ | |
--gid caddy \ | |
--create-home \ | |
--home-dir /var/lib/caddy \ | |
--shell /usr/sbin/nologin \ | |
--comment "Caddy web server" \ | |
caddy | |
curl --output caddy.service https://raw.githubusercontent.com/caddyserver/dist/master/init/caddy.service | |
sudo mv caddy.service /etc/systemd/system/caddy.service | |
sudo systemctl daemon-reload | |
sudo systemctl enable caddy | |
sudo mkdir /etc/caddy/ | |
echo "Done! Now just create a Caddyfile and put it in /etc/caddy/Caddyfile" | |
echo "Then, simple run the following command to start the caddy service:" | |
echo "sudo systemctl start caddy" | |
echo "Logs are available through the following command:" | |
echo "journalctl -u caddy --no-pager | less" | |
echo "Reload (to apply configuration changes if need be) and stop caddy with the following commands respectively" | |
echo "sudo systemctl reload caddy" | |
echo "sudo systemctl stop caddy" | |
echo "Have a nice day!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment