もぐてっく

人は1つ歳をとるたび、1ビットづつ大きくなれると信じてた。

Proxmox VEのLXCコンテナにavahi-daemonを入れようとしてハマった話

Proxmox VEが4.0にバージョンアップしてLXCベースのコンテナが使えるようになったので、コンテナをぽこぽこ作っててハマったメモです。

コンテナのテンプレートはみんな大好きUbuntu Serverの15.04(ubuntu-15.04-standard_15.04-1.amd64.tar.gz)です。

2コンテナ目からavahi-daemonのインストールがコケる

IPアドレスお手軽解決のavahi-daemonを各コンテナにインストールしていたところ、2つ目のコンテナでapt-getが失敗する怪現象が発生しました。

root@FileServer:~# apt-get install avahi-daemon
・・・
Setting up avahi-daemon (0.6.31-4ubuntu4) ...
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
Job for avahi-daemon.service failed. See "systemctl status avahi-daemon.service" and "journalctl -xe" for details.
invoke-rc.d: initscript avahi-daemon, action "start" failed.
dpkg: error processing package avahi-daemon (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of libnss-mdns:amd64:
 libnss-mdns:amd64 depends on avahi-daemon (>= 0.6.16-1); however:
  Package avahi-daemon is not configured yet.

dpkg: error processing package libnss-mdns:amd64 (--configure):
 dependency problems - leaving unconfigured
Processing triggers for dbus (1.8.12-1ubuntu5) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (219-7ubuntu6) ...
Errors were encountered while processing:
 avahi-daemon
 libnss-mdns:amd64
E: Sub-process /usr/bin/dpkg returned an error code (1)

インストール後の自動起動がコケた結果、パッケージのインストールに失敗しているようです。
ファイルのインストール自体は済んでるみたいなので、試しに手動で起動してみます。

root@FileServer:~# avahi-daemon

Found user 'avahi' (UID 109) and group 'avahi' (GID 119).
Successfully dropped root privileges.
chroot.c: fork() failed: Resource temporarily unavailable
failed to start chroot() helper daemon.

なんでかふわっとした理由でfork()が失敗してますね。

ここまでの情報を使ってググると、ズバリの英語ページが見つかりました。

Avahi, setrlimit NPROC and lxc | Playing on the frontier

どうやら、avahi-daemonの中で作れるプロセス数の条件が制限されている模様です。

その制限がなぜかコンテナ間で共有されていて、複数コンテナの合計でこの制限に引っかかるっぽいですね。実際、1つめのコンテナを落とすと起動に成功しました。

# Linuxのネームスペースのサポートが未だ完璧でないんでしょうか。
# 応用したら別のコンテナをDoS出来そうでヤバいすね。

対策

avahi-daemonのインストール失敗後、/etc/avahi/avahi-daemon.confのプロセス数制限を無効にします。

     61 [rlimits]
     62 #rlimit-as=
     63 rlimit-core=0
     64 rlimit-data=4194304
     65 rlimit-fsize=0
     66 rlimit-nofile=768
     67 rlimit-stack=4194304
     68 #rlimit-nproc=3   ←コメントアウト。

avahi-daemon.conf編集後、再度apt-get install avahi-daemonしてインストールを成功させればOKです。
既にインストール済みのコンテナのavahi-daemon.confも同様に修正しておきましょう。