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?

【2025年01月版】Ubuntu24.04 で構築した開発環境に自動アップデートを入れてみる【unattended-upgrades】

Last updated at Posted at 2025-01-11

はじめに

開発環境が多くて、定期的に apt update && apt upgrade -y と再起動やるのめんどくさいなぁ

セキュリティアップデートと再起動とか自動でやってくれたらいいのに

そうだ、unattended-upgrades でやろ、のメモ

設定

セキュリティアップデートして必要であれば再起動してくれる設定
セキュリティアップデートはデフォルトでしてくれるようになっているはず

※ コピーして差分をみてるけど、そのまま /etc/apt/apt.conf.d/50unattended-upgrades を修正してもいい

$ sudo apt install unattended-upgrades  # デフォルトで入っているから必要ないはず
$
$ mkdir -p work/"$(date +%Y%m%d)"
$ cd $_
$ cp /etc/apt/apt.conf.d/50unattended-upgrades ./
$ sudo vim /etc/apt/apt.conf.d/50unattended-upgrades
$ diff /etc/apt/apt.conf.d/50unattended-upgrades ./50unattended-upgrades
95d94
< Unattended-Upgrade::Automatic-Reboot "true";
105d103
< Unattended-Upgrade::Automatic-Reboot-Time "04:00";
$ sudo dpkg-reconfigure unattended-upgrades

修正箇所

/etc/apt/apt.conf.d/50unattended-upgrades
Unattended-Upgrade::Automatic-Reboot "true";        # 自動再起動を有効化
Unattended-Upgrade::Automatic-Reboot-Time "04:00";  # 再起動時間指定

自動アップデートがおこなわれいないようなら、以下の設定になっているか確認する

/etc/apt/apt.conf.d/20auto-upgrades
APT::Periodic::Update-Package-Lists "1";         # パッケージリストの自動更新
APT::Periodic::Unattended-Upgrade "1";           # 自動アップデートの有効化

デフォルトはセキュリティアップデートのみになっている

/etc/apt/apt.conf.d/50unattended-upgrades
// Automatically upgrade packages from these (origin:archive) pairs
//
// Note that in Ubuntu security updates may pull in new dependencies
// from non-security sources (e.g. chromium). By allowing the release
// pocket these get automatically pulled in.
Unattended-Upgrade::Allowed-Origins {
        "${distro_id}:${distro_codename}";
        "${distro_id}:${distro_codename}-security";
        // Extended Security Maintenance; doesn't necessarily exist for
        // every release and this system may not have it installed, but if
        // available, the policy for updates is such that unattended-upgrades
        // should also install from here by default.
        "${distro_id}ESMApps:${distro_codename}-apps-security";
        "${distro_id}ESM:${distro_codename}-infra-security";
//      "${distro_id}:${distro_codename}-updates";
//      "${distro_id}:${distro_codename}-proposed";
//      "${distro_id}:${distro_codename}-backports";
};

確認

手動による実行テスト

$ sudo unattended-upgrades --dry-run --debug

設定の確認

$ sudo apt-config dump | grep -i unattended | grep -i reboot
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";

実行ログの確認

$ sudo less /var/log/unattended-upgrades/unattended-upgrades.log

さいごに

かんたんでしたね

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?