Skip to content

Instantly share code, notes, and snippets.

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 brianjking/667139946f3177111098 to your computer and use it in GitHub Desktop.
Save brianjking/667139946f3177111098 to your computer and use it in GitHub Desktop.
letsencrypt_cert_autoupdate
#!/bin/bash
#
# Copyright (c) 2016 Katsuya SAITO
# This software is released under the MIT License.
# http://opensource.org/licenses/mit-license.php
#
# @(#) letsencrypt_cert_autoupdate_webroot.sh ver.0.1.0 2016.01.31
#
# Usage:
#
#
#
# Description:
#
#
#
#
###############################################################################
# CONFIGER SECTION #----------------------------------------------------------#
readonly CMD_PATH=/usr/local/letsencrypt
readonly LOG_FILE=/var/log/letsencrypt/renew.log
readonly SERVER_RESTART_CMD='/etc/init.d/nginx restart' # After update CA, How to restart WEB Server?
# Default set is for NGINX
readonly CN="exsample.com" # Your Common Name for CA
readonly WEB_ROOT_PATH=/var/www/html # WEB ROOT Path
readonly MAIL_TO="root" # Mail to update result.
# Default set is Local USER ROOT!
#-----------------------------------------------------------------------------#
# SCRIPT SECTION #------------------------------------------------------------#
today=`date +%F-%a-%T`
echo "# Let's Encrypt Cert autopudate Start: ${today}" >${LOG_FILE}
echo "# Update Log START --------------------------------------------------------------#" >>${LOG_FILE}
${CMD_PATH}/letsencrypt-auto certonly --renew-by-default --webroot -w ${WEB_ROOT_PATH} -d ${CN} >>${LOG_FILE} 2>&1
echo >>${LOG_FILE}
echo "# WEB SERVER RESTART LOG START ------------------------------#" >>${LOG_FILE}
${SERVER_RESTART_CMD} >> ${LOG_FILE}
echo "#---------------------------- WEB SERVER RESTART LOG END ---#" >>${LOG_FILE}
echo "#------------------------------------------------------------- Update Log END ---#" >>${LOG_FILE}
today=`date +%F-%a-%T`
echo "# Let's Encrypt Cert autopudate End: ${today}" >>${LOG_FILE}
cat ${LOG_FILE} | mail -s "[Let's Encrypt Auto Update] Update Report for ${CN}" ${MAIL_TO}
exit 0
#-----------------------------------------------------------------------------#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment