Stormコンポーネントを起動・監視するMonitスクリプトを書いた

This command should be run under supervision with a tool like daemontools or monit.

https://github.com/apache/storm/blob/master/bin/storm.py#L526

などとコードの中に書いている割には、そのためのスクリプトを提供していないので、自分で書いた。

更新が止まったdaemontoolsよりはMonitの方が長く使えるだろうということで、Monitを選択した。

Stormの配置

Stormの各種コンポーネントをバックグラウンド起動するためのスクリプトと、コンポーネントを強制終了させるためのスクリプトを作成する。

$ sudo mv apache-storm-1.0.1 /opt/

$ sudo vi /opt/apache-storm-1.0.1/bin/storm_daemon.sh
#!/bin/sh
COMMAND=$1
/opt/apache-storm-1.0.1/bin/storm $COMMAND >/dev/null 2>&1 &

$ sudo chmod a+x /opt/apache-storm-1.0.1/bin/storm_daemon.sh

$ sudo vi /opt/apache-storm-1.0.1/bin/storm_killer.sh
#!/bin/sh
TARGET=$1
/usr/bin/pkill -9 -f $TARGET

$ sudo chmod a+x /opt/apache-storm-1.0.1/bin/storm_killer.sh

Monitの配置

Monit自体はsystemdにプロセス管理させる。

$ sudo mv monit-5.17.1 /opt/

あとは M/Monit | Wiki 等を参考に。

Stormコンポーネント起動スクリプト作成

コンポーネントのためのMonitスクリプトは `/opt/monit-5.17.1/conf.d` に配置している。

一般にMonitの監視はプロセスIDを記録したファイルを用いて行われるが、ここでは、プロセス名に特定の文字列が含まれるプロセスがあるかどうかによる監視を採用した。

Nimbus
check process storm_nimbus matching "org.apache.storm.daemon.nimbus"
 start program = "/opt/apache-storm-1.0.1/bin/storm_daemon.sh nimbus" with timeout 180 seconds
 stop program = "/opt/apache-storm-1.0.1/bin/storm_killer.sh 'org.apache.storm.daemon.nimbus'"
UI
check process storm_ui matching "org.apache.storm.ui.core"
 start program = "/opt/apache-storm-1.0.1/bin/storm_daemon.sh ui" with timeout 180 seconds
 stop program = "/opt/apache-storm-1.0.1/bin/storm_killer.sh 'org.apache.storm.ui.core'"
Logviewer
check process storm_logviewer matching "org.apache.storm.daemon.logviewer"
 start program = "/opt/apache-storm-1.0.1/bin/storm_daemon.sh logviewer" with timeout 180 seconds
 stop program = "/opt/apache-storm-1.0.1/bin/storm_killer.sh 'org.apache.storm.daemon.logviewer'"
Supervisor
check process storm_supervisor matching "org.apache.storm.daemon.supervisor"
 start program = "/opt/apache-storm-1.0.1/bin/storm_daemon.sh supervisor" with timeout 180 seconds
 stop program = "/opt/apache-storm-1.0.1/bin/storm_killer.sh 'org.apache.storm.daemon.supervisor'"
DRPCサーバ
check process storm_drpc matching "org.apache.storm.daemon.drpc"
 start program = "/opt/apache-storm-1.0.1/bin/storm_daemon.sh drpc" with timeout 180 seconds
 stop program = "/opt/apache-storm-1.0.1/bin/storm_killer.sh 'org.apache.storm.daemon.drpc'"
Pacemaker
check process storm_ui matching "org.apache.storm.pacemaker.pacemaker"
 start program = "/opt/apache-storm-1.0.1/bin/storm_daemon.sh pacemaker" with timeout 180 seconds
 stop program = "/opt/apache-storm-1.0.1/bin/storm_killer.sh 'org.apache.storm.pacemaker.pacemaker'"