0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Let’Encrypt の自動更新の設定

Last updated at Posted at 2021-03-31

★この記事は古いので、自動更新はcertbot が勝手にやってくれるよ。

経緯

https の自動更新設定が失敗し、エラーが発生していた。
手動でrenew コマンドを実行したところ更新できず、エラー!!
エラーの結論としては、Apache の再起動が出来なかった。
理由: nginx を使っていたため。

こちらで解決: https://jijigrammer.info/programming/1115

https も期限切れを起こしていた・・・けど、renew で解決出来ましたー!!

やること

やりたいこと -> コマンド実行と合わせて、実行したことをslack へ投げたい!!

  1. shell を作る
  2. cron に設定

slack へ投げる準備

slack へ投げるshell を作成。
バッククオートで囲ったsudo [ファイルパス]/certbot-auto renew が、このslack へ投げるのと同時に実行され、変数 wに 結果が入る。

つまり!! slack 側で、実行結果を見る事が出来る(≧∇≦)b

slack.sh

# !/bin/bash

set -eu

msg="From $(hostname) server \n"
w="[https renew]\n"
w+=`sudo [ファイルパス]/certbot-auto renew`
msg+="\n$w"

SLACK_WEBHOOK_URL="https://hooks.slack.com/services/************"


post_slack() {
  # ex: "#times_hoge"
  channel="#チャンネル名"
  # ex: "hoge"
  user="設定しているユーザー名"
  # ex: "smile"
  emoji="絵文字の名前"
  message=${msg}
  # list: good / danger
  color=""

  file=$(mktemp)
  trap "rm ${file}" EXIT

  cat << EOJ > $file
    {
      "link_names": 1,
      "channel": "${channel}",
      "username": "${user}",
      "icon_emoji": ":${emoji}:",
      "attachments": [
        {
          "color": "${color}",
          "text": "${message}"
        }
      ]
    }
EOJ

  curl -s -S -X POST -d @$file ${SLACK_WEBHOOK_URL}
}

post_slack

cron に設定

#crontab -u ユーザー名 -e コマンドを実行
★ちな、rootに設定しております。

0 4 1 * * [任意のパス]/slack.sh

任意のパスは、slack.sh を置いた場所を指定。

このcron は、毎月1日 4:00 AM に実行されます。

まとめ

久々にサーバ入ったけど、どこに置いたか全然覚えてなくて><
メモしててよかった・・・!! と思ったよw知識がないから、どこに置くかしらずに置いてるからね。(調べて入るけど、都度だよね。)
メモだけは、きちんととってあったので、良かったー!!

みんなメモは、重要だから絶対とっておいた方がいいよー!!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?