Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/sh
# Slack Channel & Webhook URL
CHANNEL="#xxxxx"
WEBHOOKURL="https://hooks.slack.com/services/XXXXXX/XXXXXXXX/XXXXXXXXXXXXXXXXXX"
#Slackに通知
function slack () {
MESSAGE="$1"
BOTNAME="KS STG Server"
curl -s -S -X POST -d "payload={\"channel\": \"${CHANNEL}\", \"username\": \"${BOTNAME}\", \"text\": \"${MESSAGE}\" }" ${WEBHOOKURL} >/dev/null
}
# letsencrypt ssl authentication renewal log
LOG=/var/log/letsencrypt/renew.log
TMP=tmp.log
echo "[START] $(date '+%Y/%m/%d %H:%M:%S')" >> $LOG 2>&1
message="Lets Encrypt SSL証明書更新"
touch $TMP
sh /root/letsencrypt.sh/letsencrypt.sh --config /root/letsencrypt.sh/config.sh --cron > $TMP 2>&1
# renewal skipping flag.
is_renew=$(grep 'Skipping renew' $TMP | wc -l)
if [ $is_renew -ne 0 ]; then
echo 'NO required to Update SSL' >> $LOG 2>&1
message="$message
有効期限が 30日以上ある為、更新する必要がありませんでした。"
else
echo 'Success Update SSL. and execute httpd graceful !' >> $LOG 2>&1
service httpd graceful
message="$message
有効期限が 30日を切った為、SSL証明書を更新し、 httpd サーバを再起動しました。"
fi
slack "$message"
cat $TMP >> $LOG
rm $TMP
echo "[FINISH] $(date '+%Y/%m/%d %H:%M:%S')" >> $LOG 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.