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?

Self Host GitLabを unattended-upgrades で自動更新する

0
Posted at

はじめに

GitLabは毎月のマイナーリリースや必要に応じたパッチリリースが行われるため、継続的なバージョンアップが必要になります。

以前、GitLabのアップグレード手順について記事を書きましたが、毎回手動でアップグレードするのは運用負荷が高くなりがちです。

本記事では、この運用負荷を解消するため、Debian系ディストリビューションで利用可能なunattended-upgradesを利用して、Self Host GitLabのアップグレードを自動化してみました。

補足

RHEL系ディストリビューションでは、類似パッケージとしてdnf-automaticがあります。
(この記事では扱いません)

想定環境は次の通りです。

  • 想定環境
    • Self Host GitLab
      • GitLab Community EditionのLinux Package(Omnibus)

設定手順

GitLabリポジトリを自動更新対象に追加する

Ubuntu標準では、Ubuntu公式リポジトリのみが自動更新対象となっています。

GitLabのパッケージも自動更新対象にするため、設定ファイルを追加します。

設定ファイルを作成

vim /etc/apt/apt.conf.d/51unattended-upgrades

以下の内容を追記します。

Unattended-Upgrade::Allowed-Origins {
        "packages.gitlab.com/gitlab/gitlab-ce:${distro_codename}";
        "packages.gitlab.com/runner/gitlab-runner:${distro_codename}";
};

必要に応じてその他のリポジトリも追加

Dockerなど、GitLab以外のリポジトリも自動更新対象にしたい場合は、さらに内容を追記します。
以下は、Docker Engineを追記した例です。

Unattended-Upgrade::Allowed-Origins {
        "packages.gitlab.com/gitlab/gitlab-ce:${distro_codename}";
        "packages.gitlab.com/runner/gitlab-runner:${distro_codename}";
        "Docker:${distro_codename}";
};

環境に合わせて必要なリポジトリのみ指定してください。

実行時刻を変更する

unattended-upgradesはsystemd Timerによって定期実行されています。

デフォルトではランダムな時間帯に実行されるため、メンテナンス時間帯に合わせて変更しておくと管理しやすくなります。
以下の例では、次のように動作します。

  • 08:10 に apt update 実行
  • 08:30 に apt upgrade 実行

注意

ここでの時間指定はシステムのローカルタイムゾーンに依存します。

apt-daily.timer

systemctl edit apt-daily.timer
[Timer]
OnCalendar=*-*-* 8:10

apt-daily-upgrade.timer

systemctl edit apt-daily-upgrade.timer
[Timer]
OnCalendar=*-*-* 8:30

補足:オプション設定

[Timer]の項目にはいくつかオプション設定があります。
一部を紹介しますので、実環境に合わせて設定してください。

  • RandomizedDelaySec
    • 実行時刻をランダムに遅延させる
      • 複数サーバ同時実行によるスパイクを回避したい場合に使用します
    • 例) 8:10~8:15の間で実行する場合
      • [Timer]
        OnCalendar=*-*-* 8:10
        RandomizedDelaySec=5m
        
  • Persistent
    • 遅れていた実行を、起動後できるだけ早く1回実行する
      • 指定した時刻に実行できなかった場合、実行可能になったタイミングで補完実行します
      • default = false
    • 例)
      • [Timer]
        OnCalendar=*-*-* 8:10
        Persistent=true
        

設定確認

設定内容は次のコマンドで確認できます。

systemctl cat apt-daily.timer
systemctl cat apt-daily-upgrade.timer

タイマーの実行予定は以下で確認できます。

systemctl list-timers apt-daily*

動作確認

実際に自動更新が実行される前に、Dry Runで確認しておくことをおすすめします。

unattended-upgrade --dry-run

出力例

/usr/bin/dpkg --status-fd 10 --no-triggers --unpack --auto-deconfigure /var/cache/apt/archives/gitlab-ce_19.1.1-ce.0_amd64.deb
/usr/bin/dpkg --status-fd 10 --configure --pending

GitLabパッケージが更新対象として認識されていれば設定は完了です。

まとめ

以上、Ubuntuのunattended-upgradesを利用してSelf Host GitLabのアップグレードを自動化する方法を紹介しました。

一度設定してしまえば、日常的なパッチリリースやマイナーアップデートへの追従負荷を大きく減らせるため、運用の省力化に役立ちます。

参考情報

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?