Skip to content

Instantly share code, notes, and snippets.

@kacchan822
Last active February 19, 2016 00:17
Show Gist options
  • Save kacchan822/b03a0b7770eda085524e to your computer and use it in GitHub Desktop.
Save kacchan822/b03a0b7770eda085524e 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
#-----------------------------------------------------------------------------#
@kacchan822
Copy link
Author

-------- Report Message Sample --------

    Subject: [Let's Encrypt Auto Update] Update Report for exsample.com
    Date: Sun, 31 Jan 2016 12:54:22 +0900 (JST)
    From: root <[email protected]>
    To: [email protected]

    # Let's Encrypt Cert autopudate Start: 2016-01-31-Sun-12:54:02
    # Update Log START --------------------------------------------------------------#
    Updating letsencrypt and virtual environment dependencies......
    Requesting root privileges to run with virtualenv: /root/.local/share/letsencrypt/bin/letsencrypt certonly --renew-by-default --webroot -w /var/www/html -d exsample.com
    IMPORTANT NOTES:
    - Congratulations! Your certificate and chain have been saved at
    /etc/letsencrypt/live/exsample.com/fullchain.pem. Your cert will
    expire on 2016-04-30. To obtain a new version of the certificate in
    the future, simply run Let's Encrypt again.
    - If you like Let's Encrypt, please consider supporting our work by:

    Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
    Donating to EFF: https://eff.org/donate-le


    # WEB SERVER RESTART LOG START ------------------------------#
    * Restarting nginx nginx
    ...done.
    #---------------------------- WEB SERVER RESTART LOG END ---#
    #------------------------------------------------------------- Update Log END ---#
    # Let's Encrypt Cert autopudate End: 2016-01-31-Sun-12:54:22

-------- Report Message Sample --------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment