パッケージを自動更新する
Fedora にインストールしたパッケージを自動アップデートするには、dnf-automatic
を使います。まあ、それくらい、どこのブログにも書いてありますよね。とりあえず、インストールします。
$ sudo dnf -y install dnf-automatic インストール済み: dnf-automatic-4.8.0-1.fc34.noarch 完了しました! $
ちょっと dnf-automatic
でインストールされたファイルを見てみます。
$ rpm -ql dnf-automatic | grep systemd /usr/lib/systemd/system/dnf-automatic-download.service /usr/lib/systemd/system/dnf-automatic-download.timer /usr/lib/systemd/system/dnf-automatic-install.service /usr/lib/systemd/system/dnf-automatic-install.timer /usr/lib/systemd/system/dnf-automatic-notifyonly.service /usr/lib/systemd/system/dnf-automatic-notifyonly.timer /usr/lib/systemd/system/dnf-automatic.service /usr/lib/systemd/system/dnf-automatic.timer $
/etc/dnf/automatic.conf
に設定した内容に沿って動作するタイマーの他に、通知のみ、ダウンロードのみ、インストール実行というタイマーがあることが分かります。このタイマーをうまく使い分けることで、おもしろい設定ができそうです。
設定例
お題として、月曜日から土曜日はパッケージのアップデートをチェックして、通知のみ、日曜日は更新されたパッケージをインストールという設定をやってみます。
最初に、/etc/dnf/automatic.conf
を設定します。
# dnf-automatic.timer. notifyonly.timer, download.timer and # install.timer override this setting. download_updates = yes # Whether updates should be applied when they are available, by # dnf-automatic.timer. notifyonly.timer, download.timer and # install.timer override this setting. apply_updates = no # command compatible with sendmail. # Default is email,stdio. # If emit_via is None or left blank, no messages will be sent.emit_via = stdioemit_via = email [email] # The address to send email messages from.email_from = root@example.comemail_from = dnf-automatic@example.com # List of addresses to send messages to.email_to = rootemail_to = admin@example.com # Name of the host to connect to to send email messages. email_host = localhost
download_updates
と apply_updates
は、コメント部分に書いてあるとおり、設定が無視されて各タイマーの規定の動作の方が優先されるので、設定不要です。
次に、dnf-automatic-notifyonly.timer
の起動日時を設定します。systemd
のお作法として、以下のように入力します。
$ sudo systemctl edit dnf-automatic-notifyonly.timer
エディタが起動するので、以下のように色の付いている部分を入力して、タイマーを設定します。ここでは、月曜日から土曜日の 8:00 ~ 9:00 くらいに動くように設定しています。
### Editing /etc/systemd/system/dnf-automatic-notifyonly.timer.d/override.conf ### Anything between here and the comment below will become the new contents of the file [Timer] OnCalendar= OnCalendar=Mon,Tue,Wed,Thu,Fri,Sat *-*-* 8:00 RandomizedDelaySec=60m ### Lines below this comment will be discarded
ドロップインという機能で、いくつか注意点があります。セクションの宣言( [Timer]
)がないとエラーになって残りの設定が無視されますので、忘れずに書きましょう。また、元になっている /usr/lib/systemd/system/dnf-automatic-notifyonly.timer
には、OnCalendar=*-*-* 6:00
の設定が書かれています。OnCalendar=
は複数設定可ですので、このまま書くと、6:00 と 8:00 にタイマーが動いてしまいます。元の設定を無効にするために一旦、OnCalendar=
と書いて設定をクリアした後、改めてタイマーを設定します。RandomizedDelaySec=
のように一つしか値を設定できないものは、普通に上書きになります。
dnf-automatic-install.timer
の起動日時も設定します。同様に、以下のように入力します。
$ sudo systemctl edit dnf-automatic-install.timer
ここでは、日曜日の 8:00 ~ 9:00 くらいに動くように設定しています。
### Editing /etc/systemd/system/dnf-automatic-install.timer.d/override.conf ### Anything between here and the comment below will become the new contents of the file [Timer] OnCalendar= OnCalendar=Sun *-*-* 8:00 RandomizedDelaySec=60m ### Lines below this comment will be discarded
以上で準備ができたので、dnf-automatic-notifyonly.timer
と dnf-automatic-install.timer
の 2つのタイマーを有効にします。
$ systemctl start dnf-automatic-notifyonly.timer $ systemctl enable dnf-automatic-notifyonly.timer Created symlink /etc/systemd/system/timers.target.wants/dnf-automatic-notifyonly.timer → /usr/lib/systemd/system/dnf-automatic-notifyonly.timer. $ systemctl start dnf-automatic-install.timer $ systemctl enable dnf-automatic-install.timer Created symlink /etc/systemd/system/timers.target.wants/dnf-automatic-install.timer → /usr/lib/systemd/system/dnf-automatic-install.timer. $