もぐてっく

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

Mac OS Xでmikutterの通知とサウンドが使えるようになるプラグイン

何これ?

OS Xでmikutterの通知ポップアップとサウンドを使えるようにします。
RubyからMacの通知を出すgem(terminal-notifier)を見つけた記念です。

インストール

GitHubからzipファイルをダウンロードして適当なディレクトリに展開して下さい。

moguno/mikutter-notifier-osx · GitHub

※mikutterプラグインマネージャ"Packaged"で"moguno"を検索してインストールするのもおすすめです。

もしかするとmikutterディレクトリでbundle installしないといけないかもしれません。

使い方

他のOS同様に、設定画面の「通知」メニューから有効にしたい通知とサウンドファイルを設定してください。

f:id:moguno:20151018221201p:plain

加えて、「サウンド」メニューから「Mac OS X」を選択してください。

f:id:moguno:20151018221213p:plain

こんな感じで通知が出て来ればOKです。

f:id:moguno:20151018221535p:plain

タイトルのターミナルっぽいアイコンはOS Xの仕様でterminal-notifierのアイコンから変更できないそうです。残念。

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も同様に修正しておきましょう。

mikutter on Mac OS XのためにCairoとPangoのオレオレPortfileを作った話

OS X El Capitanへのアップグレードに伴いMacPortsをアップデートしたところ、cairoのQuartzサポートが悪さをする事象が再発しました。

moguno.hatenablog.jp

MacPortsのアップデートでactivateしていた古いパッケージが破棄された模様。

今使ってるsvnから古いPortfileを持ってくる技も今後使えなくなる可能性があるので、いい感じのPortfileを書いて、オレオレで抱え込むようにします。

方針

variantの+quartzが悪さをしているのは確実なのだけれど、+quartzがデフォルトで無効化出来ないようになっているので、その辺りをハックしたPortfileを作ります。

MacPortsにオレオレツリーを追加する。

ここでは、自分のホームディレクトリにmacportディレクトリを作ってそれをオレオレツリーにします。

mkdir ~/macports

vi /opt/local/etc/macports/sources.conf

・sources.conf

  8 # To add a local source, add a "file://" entry.
  9 #
 10 #   Example: file:///Users/landonf/misc/MacPorts/ports
 11 #
 12 # To prevent a source from synchronizing when `port sync` is used,
 13 # append "[nosync]" at the end.
 14 #
 15 #   Example: file:///Users/landonf/misc/MacPorts/ports [nosync]
 16 #
 17 # Note that MacPorts parses source URLs in order; when a port appears in
 18 # multiple sources, it installs the first occurrence. For local sources
 19 # to shadow remote ones, "file://" URLs must come before other URLs.
 20 file:///Users/moguno/macports             ←オレオレツリーのパスを追加

ハックするPortfileをもらってくる。

CairoとPangoを本家ツリーから頂いてきます。

cd /opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports/

tar cf - graphics/cairo | tar xf - -C ~/macports/
tar cf - x11/pango | tar xf - -C ~/macports/

Portfileの編集

デフォルトで有効になる+quartzをぶっ潰します。

cairo

118     #default_variants        +quartz     ←コメントアウト
119     # Don't allow Quartz support to be disabled. Keep the variant for awhile in
120     # case any dependents are using the active_variants portgroup to check for it.
121     #variant_set             quartz     ←コメントアウト

pango

 62     #default_variants    +quartz     ←コメントアウト
 63     # Don't allow Quartz support to be disabled. Keep the variant for awhile in
 64     # case any dependents are using the active_variants portgroup to check for it.
 65     #variant_set         quartz     ←コメントアウト

最後にPortIndexファイルを作って完成です。

cd /Users/moguno/macports
portindex

インストール

通常通りインストールすると、オレオレツリーを優先して使ってくれます。

sudo port install cairo
sudo port install pango

こんな感じで、x11にのみ+がついていればOKです。

sudo port info cairo pango

cairo @1.14.2_1 (graphics)
Variants:             opengl, quartz, universal, [+]x11     ←これ

Description:          Cairo is a vector graphics library with cross-device output support. It is designed to produce identical output on all output media while taking advantage of
                      display hardware acceleration when available (e.g. through the X Render Extension).
Homepage:             http://cairographics.org/

Extract Dependencies: xz
Build Dependencies:   pkgconfig
Library Dependencies: libpixman, glib2, fontconfig, freetype, libpng, zlib, expat, xrender, xorg-libXext, xorg-xcb-util
Conflicts with:       cairo-devel
Platforms:            darwin, macosx
License:              LGPL-2.1 MPL-1.1
Maintainers:          ryandesign@macports.org
--
pango @1.38.0 (x11)
Variants:             quartz, universal, [+]x11     ←これ

Description:          The goal of the Pango project is to provide an open-source framework for the layout and rendering of internationalized text.
Homepage:             http://www.pango.org/

Extract Dependencies: xz
Build Dependencies:   pkgconfig
Library Dependencies: glib2, cairo, harfbuzz, gobject-introspection, Xft2
Conflicts with:       pango-devel
Platforms:            darwin
License:              LGPL-2
Maintainers:          ryandesign@macports.org, openmaintainer@macports.org

これで安定してMacでmikutter出来ますね。