ksaitoの日記

日々試したことの覚え書き

aptの自動更新

移転しました。

自動的にリダイレクトします。

cron-aptというパッケージを使ってaptパッケージの更新を自動化することができます。

インストール

下記でインストールします。

$ sudo aptitude install cron-apt

設定

デフォルトでは、パッケージのアップデートとダウンロードしかしないのでsafe-upgradeでパッケージ更新まで実行するようにします。

$ sudo hg diff cron-apt
diff -r 8f14f4dd8a31 cron-apt/action.d/3-download
--- a/cron-apt/action.d/3-download	Sat Jan 23 00:42:47 2010 +0900
+++ b/cron-apt/action.d/3-download	Sat Jan 23 01:11:16 2010 +0900
@@ -1,2 +1,2 @@
 autoclean -y
-dist-upgrade -d -y -o APT::Get::Show-Upgraded=true
+safe-upgrade -y -o APT::Get::Show-Upgraded=true
diff -r 8f14f4dd8a31 cron-apt/config
--- a/cron-apt/config	Sat Jan 23 00:42:47 2010 +0900
+++ b/cron-apt/config	Sat Jan 23 01:11:16 2010 +0900
@@ -12,7 +12,7 @@
 # have full support for noninteractive upgrades. You may have to tune options
 # to not create infinit logfiles for example.
 # APTCOMMAND=/usr/bin/apt-get
-# APTCOMMAND=/usr/bin/aptitude
+APTCOMMAND=/usr/bin/aptitude
 # APTCOMMAND=/usr/bin/apt-file
 
 # A path is needed for this to work. This is the default PATH.
@@ -29,7 +29,7 @@
 # MINTMPDIRSIZE=10
 
 # The directory where the actions is stored.
-# ACTIONDIR="/etc/cron-apt/action.d"
+ACTIONDIR="/etc/cron-apt/action.d"
 
 # The directory where configuration per action is stored. The message file
 # must have the same name as the action file.
$

動作確認

/usr/sbin/cron-aptを実行します。
ログは、/var/log/cron-apt/logに出力されるのでモニタしておきます。

$ sudo tail -f /var/log/cron-apt/log

実行時間の調整

デフォルトでは、/etc/cron.d/cron-aptで毎日午前4時に実行されるように設定されています。
必要に応じて修正します。

通知

勝手に変更されるのも気持ち悪いので、パッケージが更新されたらメールが届くようにします。

$ sudo hg diff -r 109:tip . | grep MAIL | grep \^+
+MAILTO="root"
+MAILON="upgrade"