Zabbix Server が停止できずシャットダウンできない
Ubuntu をリモートでリブートしたら、いつまで待っても立ち上がらないので、サーバーのコンソールを確認しに行くと、シャットダウンの途中で「A stop job is running for Zabbix Server」と表示されたまま10分以上経過していて、シャットダウンされていませんでした。
ネットで調べてみると、systemd の設定ファイル /etc/systemd/system.conf の DefaultTimeoutStopSec
を指定するとタイムアウトが設定できる、という記事がいくつか出てきました。
system.conf を開くと以下の記述が。
:
# Use 'systemd-analyze cat-config systemd/system.conf' to display the full config.
#
# See systemd-system.conf(5) for details.
[Manager]
:
#DefaultTimeoutStartSec=90s
#DefaultTimeoutStopSec=90s
#DefaultTimeoutAbortSec=
#DefaultDeviceTimeoutSec=90s
:
これがデフォルト値で、90秒になっているならば、別の値を設定したところで効果ないんじゃないか?と疑問に思ってとりあえずマニュアルを確認してみます。
$ man systemd-system.conf
:
DefaultTimeoutStartSec=, DefaultTimeoutStopSec=,
DefaultTimeoutAbortSec=, DefaultRestartSec=
Configures the default timeouts for starting, stopping and aborting
of units, as well as the default time to sleep between automatic
restarts of units, as configured per-unit in TimeoutStartSec=,
TimeoutStopSec=, TimeoutAbortSec= and RestartSec= (for services,
see systemd.service(5) for details on the per-unit settings). For
non-service units, DefaultTimeoutStartSec= sets the default
TimeoutSec= value.
DefaultTimeoutStartSec= and DefaultTimeoutStopSec= default to 90 s
in the system manager and 90 s in the user manager.
DefaultTimeoutAbortSec= is not set by default so that all units
fall back to TimeoutStopSec=. DefaultRestartSec= defaults to 100
ms.
Added in version 209.
やっぱり90秒ですよね。なんで10分経ってもタイムアウトしないのよ?と思いますよね。
他にタイムアウト値を設定している箇所があるんじゃないか?と調べてみます。
$ man systemd
:
CONCEPTS
systemd provides a dependency system between various entities called
"units" of 11 different types. Units encapsulate various objects that
are relevant for system boot-up and maintenance. The majority of units
are configured in unit configuration files, whose syntax and basic set
of options is described in systemd.unit(5), however some are created
automatically from other configuration files, dynamically from system
state or programmatically at runtime.
ユニット単位の設定ファイルがあって、詳しくは systemd.unit(5) に書いてあるよっつうこってすな。
$ man 5 systemd.unit
:
System Unit Search Path
/etc/systemd/system.control/*
/run/systemd/system.control/*
/run/systemd/transient/*
/run/systemd/generator.early/*
/etc/systemd/system/*
/etc/systemd/system.attached/*
/run/systemd/system/*
/run/systemd/system.attached/*
/run/systemd/generator/*
...
/usr/lib/systemd/system/*
/run/systemd/generator.late/*
ありました。このなかから Zabbix の設定ファイルを探してみます。
$ for i in /etc/systemd/system.control /run/systemd/system.control /run/systemd/transient /run/systemd/generator.early /etc/systemd/system /etc/systemd/system.attached /run/systemd/system /run/systemd/system.attached /run/systemd/generator /usr/lib/systemd/system /run/systemd/generator.late; do [ -f $i/*zabbix-server* ] && ls -l $i/*zabbix-server* ; done
-rw-r--r-- 1 root root 554 4月 22 18:07 /usr/lib/systemd/system/zabbix-server.service
$ grep Timeout /usr/lib/systemd/system/zabbix-server.service
TimeoutSec=infinity
$
ビンゴ! Zabbix はタイムアウトしないようになってました。
ということで、/usr/lib/systemd/system/zabbix-server.service のTimeoutSec
の行をコメントアウトしときました。忘れずにリロードもしましょう。
$ sudo systemctl daemon-reload
動作確認していませんが、これで一安心だと思います。
なお、Zabbix が終了しなかった原因は、おそらく直前に MariaDB がおかしくなったことに起因していると思われます。リブート前に WordPress でDBに接続できないというエラーメッセージが表示されるようになったので、MariaDB を再起動しようとしたのですができなかったので、一回リブートしてみるかとなったときにこの現象が発生しました。
zabbix-server.service に以下のような依存関係の記載があるので、mariadb.service の終了をずっと待っていたんではないかと思われます。
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
After=mysql.service
After=mysqld.service
After=mariadb.service
mariadb.service を確認すると、
$ grep Timeout /usr/lib/systemd/system/mariadb.service
TimeoutStartSec=900
TimeoutStopSec=900
900秒=15分なので、あと5分くらい待てば終わったのかもしれません。もっと早くしてもいいのですが、レアケースなのでひとまずこのままに。