Table of Contents
- 1. Ubuntu 16.04をインストールしたままの場合
- 2. apt.systemd.daily
- 3. unattended-upgradesパッケージ
- 4. /etc/apt/apt.conf.d/10periodic(unattended-upgrades利用時は不要)
- 5. /etc/apt/apt.conf.d/20auto-upgrades
- 6. /etc/apt/apt.conf.d/50unattended-upgrades
- 7. dpkgデータベースのロックを防ぎたい
- 8. 自動アップグレードがあった場合はスケジュールに従って再起動したい
1 Ubuntu 16.04をインストールしたままの場合
Ubuntu 16.04を起動した時と毎日6時と18時(ランダムなディレイあり)に自動アップデートと自動アップグレードが実行がされます。
デフォルトでは、セキュリティアップグレードのみ実行され、自動再起動は実行されません。
2 apt.systemd.daily
aptの自動実行を可能にするフレームワークです。
以下の2種類のsystemdスクリプトが存在します。
apt-daily.service システム起動時に実行 apt-daily.timer 毎日6時と18時に実行
上記のsystemdスクリプト経由でapt autocleanの実行やunattended-upgradeを実行します。
3 unattended-upgradesパッケージ
自動アップグレードを実行するパッケージです。
デフォルトだとセキュリティアップデートのみをアップグレードする設定になっています。
アップデート後にシステム再起動が必要な場合に再起動させることも設定できます。
サーバ運用している場合はアップグレード作業が不要になるので便利なツールです。
4 /etc/apt/apt.conf.d/10periodic(unattended-upgrades利用時は不要)
/etc/apt/apt.conf.d/20auto-upgradesと同様の内容のファイルで、/etc/apt/apt.conf.d/20auto-upgradesの項目が全て無効になっております。
5 /etc/apt/apt.conf.d/20auto-upgrades
自動アップデートと自動アップグレードを実行する設定ファイルです。Ubuntu 16.04インストール時にデフォルトで項目が有効になっています。
$ cat /etc/apt/apt.conf.d/20auto-upgradesAPT::Periodic::Update-Package-Lists “1”;APT::Periodic::Unattended-Upgrade “1”;
APT::Periodic::Update-Package-Listsが/etc/apt/apt.conf.d/10periodicと被っています。
APT::Periodic::Update-Package-Lists 0だと自動アップデート無効 APT::Periodic::Unattended-Upgrade 0だと自動アップグレード無効 APT::Periodic::Download-Upgradeable-Packages 0だと自動アップグレード無効 (パッケージのダウンロードのみ) APT::Periodic::AutocleanInterval 0だと自動autoclean無効
unattended-upgradesのpostinstall処理で自動生成されます。
20auto-upgradesと50unattended-upgradesはdpkg-reconfigureコマンドで再生成できます。
$ sudo dpkg-reconfigure –priority=low unattended-upgrades
なお、以下の設定項目は意味を持ちません(”origin=Debian,codename=${distro_codename},label=Debian-Security”を別の文字列に置換しようとする設定ですが、置換前の文字列が現在の50unattended-upgradesに存在しない)。
Origins-Pattern that packages must match to be upgraded:”origin=Debian,codename=${distro_codename},label=Debian-Security”
5.1 GUIから/etc/apt/apt.conf.d/20auto-upgradesを設定
ソフトウェアとアップデートの画面から設定できます。
システム設定 -> ソフトウェアとアップデート -> アップデート
上記の内容だと以下のようになります。
APT::Periodic::Update-Package-Lists “14”;APT::Periodic::Download-Upgradeable-Packages “1”;APT::Periodic::AutocleanInterval “0”;APT::Periodic::Unattended-Upgrade “1”;
6 /etc/apt/apt.conf.d/50unattended-upgrades
自動アップグレードの設定ファイルです。アップグレード対象をセキュリティのみに絞ったり、アップグレード後に再起動するかどうか等を設定します。
Unattended-Upgrade::Allowed-Origins { “${distro_id}:${distro_codename}-security”;// “${distro_id}:${distro_codename}-updates”;// “${distro_id}:${distro_codename}-proposed”;// “${distro_id}:${distro_codename}-backports”;};<snip>// Automatically reboot *WITHOUT CONFIRMATION*// if the file /var/run/reboot-required is found after the upgrade//Unattended-Upgrade::Automatic-Reboot “false”;// If automatic reboot is enabled and need
ed, reboot at the specific// time instead of immediately// Default: “now”//Unattended-Upgrade::Automatic-Reboot-Time “02:00”;
Unattended-Upgrade::Allowed-Origins 自動アップグレード対象 Unattended-Upgrade::Automatic-Reboot 再起動が必要な場合に実行 Unattended-Upgrade::Automatic-Reboot-Time 再起動の時刻
unattended-upgradesのpostinstall処理で自動生成されます。
7 dpkgデータベースのロックを防ぎたい
apt-daily.serviceとapt-daily.timerを実行しないようにします。
その代わり自分でsudo apt updateとsudo apt upgradeを実行する必要があります。
sudo systemctl disable apt-daily.service # disable boot time runsudo systemctl disable apt-daily.timer # disable timer run
8 自動アップグレードがあった場合はスケジュールに従って再起動したい
再起動の時刻は/etc/apt/apt.conf.d/50unattended-upgradesのUnattended-Upgrade::Automatic-Rebootをtrueにして、Unattended-Upgrade::Automatic-Reboot-Timeをスケジュールに従った時刻にします。