Raspberry pi に watchdogをインストールする (Raspbian Jessie Lite 2017-02-16版)

Raspberry pi に watchdogをインストールする (Raspbian Jessie Lite 2017-02-16版)

最近になってRaspbian Jessie OSが2017-02-16版に新しくなったようなのでwatchdogをインストールしてみました。

以下の内容は、Raspberry pi B、Raspberry pi B+、Raspberry pi 2BにJessie Lite版をインストールし、それぞれの機種で設定とテストを行いました。

テストはSDカードにJessie OS Lite 2017-02-16版をインストールして、raspi-configを使って各種設定を行いsshで接続した状態で行いました。

結果としてはRaspberry pi B、Raspberry pi B+、Raspberry pi 2Bいずれも同じ設定内容で確認できました。

各定義ファイルの更新にはnanoを使っています。保存終了する場合にはキーボード操作でctrl-x→yで保存終了します(保存終了したく無い場合にはyの代わりにnを押します)

1.OSを最新版に更新する

pi@raspberrypi:~ $ sudo apt-get update
取得:1 http://archive.raspberrypi.org jessie InRelease [22.9 kB]
取得:2 http://archive.raspberrypi.org jessie/main armhf Packages [147 kB]
取得:3 http://archive.raspberrypi.org jessie/ui armhf Packages [57.6 kB]
取得:4 http://mirrordirector.raspbian.org jessie InRelease [14.9 kB]
取得:5 http://mirrordirector.raspbian.org jessie/main armhf Packages [8,981 kB]
無視 http://archive.raspberrypi.org jessie/main Translation-ja_JP
無視 http://archive.raspberrypi.org jessie/main Translation-ja
無視 http://archive.raspberrypi.org jessie/main Translation-en
無視 http://archive.raspberrypi.org jessie/ui Translation-ja_JP
無視 http://archive.raspberrypi.org jessie/ui Translation-ja
無視 http://archive.raspberrypi.org jessie/ui Translation-en
取得:6 http://mirrordirector.raspbian.org jessie/main armhf Packages [8,981 kB]
取得:7 http://mirrordirector.raspbian.org jessie/contrib armhf Packages [37.5 kB]
取得:8 http://mirrordirector.raspbian.org jessie/non-free armhf Packages [70.3 kB]
取得:9 http://mirrordirector.raspbian.org jessie/rpi armhf Packages [1,356 B]
無視 http://mirrordirector.raspbian.org jessie/contrib Translation-ja_JP
無視 http://mirrordirector.raspbian.org jessie/contrib Translation-ja
無視 http://mirrordirector.raspbian.org jessie/contrib Translation-en
無視 http://mirrordirector.raspbian.org jessie/main Translation-ja_JP
無視 http://mirrordirector.raspbian.org jessie/main Translation-ja
無視 http://mirrordirector.raspbian.org jessie/main Translation-en
無視 http://mirrordirector.raspbian.org jessie/non-free Translation-ja_JP
無視 http://mirrordirector.raspbian.org jessie/non-free Translation-ja
無視 http://mirrordirector.raspbian.org jessie/non-free Translation-en
無視 http://mirrordirector.raspbian.org jessie/rpi Translation-ja_JP
無視 http://mirrordirector.raspbian.org jessie/rpi Translation-ja
無視 http://mirrordirector.raspbian.org jessie/rpi Translation-en
3,967 kB を 4分 22秒 で取得しました (15.1 kB/s)
パッケージリストを読み込んでいます... 完了
pi@raspberrypi:~ $ sudo apt-get upgrade
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
アップグレードパッケージを検出しています ... 完了
以下のパッケージはアップグレードされます:
  bind9-host libbind9-90 libdns-export100 libdns100 libirs-export91
  libisc-export95 libisc95 libisccc90 libisccfg-export90 libisccfg90
  liblwres90 login passwd raspberrypi-sys-mods raspi-config
アップグレード: 15 個、新規インストール: 0 個、削除: 0 個、保留: 0 個。
3,255 kB のアーカイブを取得する必要があります。
この操作後に追加で 9,216 B のディスク容量が消費されます。
続行しますか? [Y/n] Y
取得:1 http://archive.raspberrypi.org/debian/ jessie/main raspberrypi-sys-mods all 20170302 [8,306 B]
取得:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main login armhf 1:4.2-3+deb8u3 [716 kB]
取得:3 http://archive.raspberrypi.org/debian/ jessie/main raspi-config all 20170228 [18.5 kB]
取得:4 http://mirrordirector.raspbian.org/raspbian/ jessie/main libisc-export95 armhf 1:9.9.5.dfsg-9+deb8u10 [124 kB]
取得:5 http://mirrordirector.raspbian.org/raspbian/ jessie/main libdns-export100 armhf 1:9.9.5.dfsg-9+deb8u10 [399 kB]
取得:6 http://mirrordirector.raspbian.org/raspbian/ jessie/main libisccfg-export90 armhf 1:9.9.5.dfsg-9+deb8u10 [37.9 kB]
取得:7 http://mirrordirector.raspbian.org/raspbian/ jessie/main libirs-export91 armhf 1:9.9.5.dfsg-9+deb8u10 [36.6 kB]
取得:8 http://mirrordirector.raspbian.org/raspbian/ jessie/main passwd armhf 1:4.2-3+deb8u3 [926 kB]
取得:9 http://mirrordirector.raspbian.org/raspbian/ jessie/main bind9-host armhf 1:9.9.5.dfsg-9+deb8u10 [65.6 kB]
取得:10 http://mirrordirector.raspbian.org/raspbian/ jessie/main libisc95 armhf 1:9.9.5.dfsg-9+deb8u10 [149 kB]
取得:11 http://mirrordirector.raspbian.org/raspbian/ jessie/main libdns100 armhf 1:9.9.5.dfsg-9+deb8u10 [600 kB]
取得:12 http://mirrordirector.raspbian.org/raspbian/ jessie/main libisccc90 armhf 1:9.9.5.dfsg-9+deb8u10 [34.4 kB]
取得:13 http://mirrordirector.raspbian.org/raspbian/ jessie/main libisccfg90 armhf 1:9.9.5.dfsg-9+deb8u10 [50.3 kB]
取得:14 http://mirrordirector.raspbian.org/raspbian/ jessie/main libbind9-90 armhf 1:9.9.5.dfsg-9+deb8u10 [41.3 kB]
取得:15 http://mirrordirector.raspbian.org/raspbian/ jessie/main liblwres90 armhf 1:9.9.5.dfsg-9+deb8u10 [47.8 kB]
3,255 kB を 12秒 で取得しました (271 kB/s)
changelog を読んでいます... 完了
(データベースを読み込んでいます ... 現在 31364 個のファイルとディレクトリがイン ストールされています。)
.../login_1%3a4.2-3+deb8u3_armhf.deb を展開する準備をしています ...
login (1:4.2-3+deb8u3) で (1:4.2-3+deb8u1 に) 上書き展開しています ...
man-db (2.7.0.2-5) のトリガを処理しています ...
login (1:4.2-3+deb8u3) を設定しています ...
(データベースを読み込んでいます ... 現在 31364 個のファイルとディレクトリがイン ストールされています。)
.../libisc-export95_1%3a9.9.5.dfsg-9+deb8u10_armhf.deb を展開する準備をしていま す ...
libisc-export95 (1:9.9.5.dfsg-9+deb8u10) で (1:9.9.5.dfsg-9+deb8u9 に) 上書き展 開しています ...
.../libdns-export100_1%3a9.9.5.dfsg-9+deb8u10_armhf.deb を展開する準備をしています ...
libdns-export100 (1:9.9.5.dfsg-9+deb8u10) で (1:9.9.5.dfsg-9+deb8u9 に) 上書き展開しています ...
.../libisccfg-export90_1%3a9.9.5.dfsg-9+deb8u10_armhf.deb を展開する準備をしています ...
libisccfg-export90 (1:9.9.5.dfsg-9+deb8u10) で (1:9.9.5.dfsg-9+deb8u9 に) 上書き展開しています ...
.../libirs-export91_1%3a9.9.5.dfsg-9+deb8u10_armhf.deb を展開する準備をしていま す ...
libirs-export91 (1:9.9.5.dfsg-9+deb8u10) で (1:9.9.5.dfsg-9+deb8u9 に) 上書き展 開しています ...
.../passwd_1%3a4.2-3+deb8u3_armhf.deb を展開する準備をしています ...
passwd (1:4.2-3+deb8u3) で (1:4.2-3+deb8u1 に) 上書き展開しています ...
man-db (2.7.0.2-5) のトリガを処理しています ...
passwd (1:4.2-3+deb8u3) を設定しています ...
(データベースを読み込んでいます ... 現在 31364 個のファイルとディレクトリがイン ストールされています。)
.../bind9-host_1%3a9.9.5.dfsg-9+deb8u10_armhf.deb を展開する準備をしています ...
bind9-host (1:9.9.5.dfsg-9+deb8u10) で (1:9.9.5.dfsg-9+deb8u9 に) 上書き展開しています ...
.../libisc95_1%3a9.9.5.dfsg-9+deb8u10_armhf.deb を展開する準備をしています ...
libisc95 (1:9.9.5.dfsg-9+deb8u10) で (1:9.9.5.dfsg-9+deb8u9 に) 上書き展開しています ...
.../libdns100_1%3a9.9.5.dfsg-9+deb8u10_armhf.deb を展開する準備をしています ...
libdns100 (1:9.9.5.dfsg-9+deb8u10) で (1:9.9.5.dfsg-9+deb8u9 に) 上書き展開して います ...
.../libisccc90_1%3a9.9.5.dfsg-9+deb8u10_armhf.deb を展開する準備をしています ...
libisccc90 (1:9.9.5.dfsg-9+deb8u10) で (1:9.9.5.dfsg-9+deb8u9 に) 上書き展開しています ...
.../libisccfg90_1%3a9.9.5.dfsg-9+deb8u10_armhf.deb を展開する準備をしています ...
libisccfg90 (1:9.9.5.dfsg-9+deb8u10) で (1:9.9.5.dfsg-9+deb8u9 に) 上書き展開し ています ...
.../libbind9-90_1%3a9.9.5.dfsg-9+deb8u10_armhf.deb を展開する準備をしています ...
libbind9-90 (1:9.9.5.dfsg-9+deb8u10) で (1:9.9.5.dfsg-9+deb8u9 に) 上書き展開し ています ...
.../liblwres90_1%3a9.9.5.dfsg-9+deb8u10_armhf.deb を展開する準備をしています ...
liblwres90 (1:9.9.5.dfsg-9+deb8u10) で (1:9.9.5.dfsg-9+deb8u9 に) 上書き展開しています ...
.../raspberrypi-sys-mods_20170302_all.deb を展開する準備をしています ...
raspberrypi-sys-mods (20170302) で (20170127 に) 上書き展開しています ...
.../raspi-config_20170228_all.deb を展開する準備をしています ...
raspi-config (20170228) で (20170214 に) 上書き展開しています ...
man-db (2.7.0.2-5) のトリガを処理しています ...
systemd (215-17+deb8u6) のトリガを処理しています ...
libisc-export95 (1:9.9.5.dfsg-9+deb8u10) を設定しています ...
libdns-export100 (1:9.9.5.dfsg-9+deb8u10) を設定しています ...
libisccfg-export90 (1:9.9.5.dfsg-9+deb8u10) を設定しています ...
libirs-export91 (1:9.9.5.dfsg-9+deb8u10) を設定しています ...
libisc95 (1:9.9.5.dfsg-9+deb8u10) を設定しています ...
libdns100 (1:9.9.5.dfsg-9+deb8u10) を設定しています ...
libisccc90 (1:9.9.5.dfsg-9+deb8u10) を設定しています ...
libisccfg90 (1:9.9.5.dfsg-9+deb8u10) を設定しています ...
libbind9-90 (1:9.9.5.dfsg-9+deb8u10) を設定しています ...
liblwres90 (1:9.9.5.dfsg-9+deb8u10) を設定しています ...
bind9-host (1:9.9.5.dfsg-9+deb8u10) を設定しています ...
raspberrypi-sys-mods (20170302) を設定しています ...
raspi-config (20170228) を設定しています ...
libc-bin (2.19-18+deb8u7) のトリガを処理しています ...
pi@raspberrypi:~ $ 

2.watchdogをインストールする

以降の処理はスーパーユーザー(sudo su)に移行して処理を行います。

pi@raspberrypi:~ $ sudo su
root@raspberrypi:/home/pi# apt-get install watchdog
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下のパッケージが新たにインストールされます:
  watchdog
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
78.1 kB のアーカイブを取得する必要があります。
この操作後に追加で 179 kB のディスク容量が消費されます。
取得:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main watchdog armhf 5.14-3 [78.1 kB]
78.1 kB を 2秒 で取得しました (32.3 kB/s)
パッケージを事前設定しています ...
以前に未選択のパッケージ watchdog を選択しています。
(データベースを読み込んでいます ... 現在 31366 個のファイルとディレクトリがイン ストールされています。)
.../watchdog_5.14-3_armhf.deb を展開する準備をしています ...
watchdog (5.14-3) を展開しています...
systemd (215-17+deb8u6) のトリガを処理しています ...
man-db (2.7.0.2-5) のトリガを処理しています ...
watchdog (5.14-3) を設定しています ...
/run/udev or .udevdb or .udev presence implies active udev.  Aborting MAKEDEV invocation.
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
systemd (215-17+deb8u6) のトリガを処理しています ...
root@raspberrypi:/home/pi# 

3、/lib/systemd/system/watchdog.serviceの[Install]に”WantedBy=multi-user.target”(最後の行)を追加する

root@raspberrypi:/home/pi# nano /lib/systemd/system/watchdog.service
[Unit]
Description=watchdog daemon
Conflicts=wd_keepalive.service
After=multi-user.target
OnFailure=wd_keepalive.service
[Service]
Type=forking
EnvironmentFile=/etc/default/watchdog
ExecStartPre=/bin/sh -c '[ -z "${watchdog_module}" ] || [ "${watchdog_module}" $
ExecStart=/bin/sh -c '[ $run_watchdog != 1 ] || exec /usr/sbin/watchdog $watchd$
ExecStopPost=/bin/sh -c '[ $run_wd_keepalive != 1 ] || false'
[Install]
WantedBy=multi-user.target

4、update-rc.d watchdog enableの実行

root@raspberrypi:/home/pi# update-rc.d watchdog enable

5、modprobe bcm2835_wdtの実行

(modprobe bcm2708_wdogの実行だとmodprobe: FATAL: Module bcm2708_wdog not found.のエラー表示となる)

root@raspberrypi:/home/pi# modprobe bcm2835_wdt

6、/etc/watchdog.confの以下の3行を変更する

12行目 #max-load-1 = 24 の#を外す
26行目 #watchdog-device = /dev/watchdog の#を外す
28行目 watchdog-timeout = 10 の行を追加する

[root@raspberry:/home/pi]# nano /etc/watchdog.conf

#ping                   = 172.31.14.1
#ping                   = 172.26.1.255
#interface              = eth0
#file                   = /var/log/messages
#change                 = 1407

# Uncomment to enable test. Setting one of these values to '0' disables it.
# These values will hopefully never reboot your machine during normal use
# (if your machine is really hung, the loadavg will go much higher than 25)
max-load-1              = 24
#max-load-5             = 18
#max-load-15            = 12

# Note that this is the number of pages!
# To get the real size, check how large the pagesize is on your machine.
#min-memory             = 1
#allocatable-memory     = 1

#repair-binary          = /usr/sbin/repair
#repair-timeout         =
#test-binary            =
#test-timeout           =

watchdog-device = /dev/watchdog

watchdog-timeout = 10
# Defaults compiled into the binary
#temperature-device     =
#max-temperature        = 120

# Defaults compiled into the binary
#admin                  = root
#interval               = 1
#logtick                = 1
#log-dir         = /var/log/watchdog

# This greatly decreases the chance that watchdog won't be scheduled before
# your machine is really loaded
realtime                = yes
priority                = 1

# Check if rsyslogd is still running by enabling the following line
#pidfile                = /var/run/rsyslogd.pid

7、再起動する

root@raspberrypi:/home/pi# reboot

8、再起動したら再度ログインし以下のエラー誘発コマンドを入力し再起動されることを確認する

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Mar  3 23:04:12 2017 from 192.168.11.6
pi@raspberrypi:~ $ :(){ :|:& };:
[1] 623
pi@raspberrypi:~ $

しばらくするとコンソールが落ちて自動的に再起動するはずです。