Skip to content

Instantly share code, notes, and snippets.

@bviktor
Last active January 25, 2016 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bviktor/a39d3d025d6334d4a713 to your computer and use it in GitHub Desktop.
Save bviktor/a39d3d025d6334d4a713 to your computer and use it in GitHub Desktop.
Let's Encrypt renew script
#!/bin/sh
# make sure the script can find the domain list even when invoked from a different dir
DIR=$(dirname $0)
# store your domain renewal commands here, one line per certificate, e.g.:
# -d foo.bar -d www.foo.bar
# -d foo2.foo.bar
DOMLIST="${DIR}/le-domains.txt"
# don't break at spaces
IFS=$'\n'
# make sure it works even in cron with different $PATH
LECMD='/bin/letsencrypt certonly'
# make sure port 80 is available
eval "/bin/systemctl stop nginx.service"
# don't parse lines starting with #
for DOM in $(grep -v ^# ${DOMLIST})
do
eval "${LECMD} ${DOM}"
# if failed, try until succeeds
while [ $? -ne 0 ]
do
# don't spam too much
sleep 10
eval "${LECMD} ${DOM}"
done
done
eval "/bin/systemctl start nginx.service"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment