embulk × digdag の即席環境
というわけで前回の続き。
embulkをジョブ管理するためのフレームワークとして、digdagを入れてみたのですが、コンソール上で起動できたけど、バックグラウンドじゃなきゃ使えないw
というわけで、バックグラウンドプロセスとして起動させる方法を探してみました。
今回のオチを先に書くと、ぶっちゃけCentOSのsystemdでも、やりたいことできたと思うんですよね。 supervisorってのを入れてデーモン化したんですが、いらないひと手間だった気がします。 とりあえず、やった手順で書きますがsystemdのバージョンのほうが絶対いいいような気がするけど・・・。
まず下準備。
今回Web調べてて見つけたのが"supervisor"で"digdag"を管理するというもの。 安易に飛びついたのがいけなかったですね。 でも、まぁ仕方ないので書いていきます。
supervisorとは!
- プロセスのデーモン化ツール
はい、それだけ。 細かいことは気にしないのがなんちゃって流。←
まず、導入。参考にした手順のOSが違ったので適当にWeb散策して以下の手順で導入。
EPELリポジトリを使えるようにする。
supervisor入れる。
digdagをデーモン化する。
そんな感じ。 あ、wget入ってないから入れておこう。 的なコマンドを交えて、えいや。
$ sudo yum install wget
$ wget http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/epel-release-latest-7.noarch.rpm
$ sudo rpm -ivh epel-release-latest-7.noarch.rpm
$ sudo yum install supervisor --enablerepo=epel
問題なく成功。 で、確認。
$ ll /etc/supervisord.conf
-rw-r--r--. 1 root root 7953 Jul 28 23:32 /etc/supervisord.conf
できてるできてる。
で、こやつをサービス化。
この時に気づけばよかったのでは・・・
$ sudo vi supervisord.service
[Unit]
Description=Supervisor process control system for UNIX
Documentation=http://supervisord.org
After=network.target
[Service]
ExecStart=/usr/bin/supervisord -n -c /etc/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=50s
[Install]
WantedBy=multi-user.target
で、起動。
$ sudo systemctl start supervisord
$ sudo systemctl status supervisord
Nov 11 18:03:29 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal systemd[1]: Started Supervisor process control system for UNIX.
Nov 11 18:03:29 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal systemd[1]: Starting Supervisor process control system for UNIX...
Nov 11 18:03:29 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[1268]: 2017-11-11 18:03:29,213 CRIT Supervisor running as root (no user in config file)
Nov 11 18:03:29 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[1268]: 2017-11-11 18:03:29,213 WARN No file matches via include "/etc/supervisord.d/*.ini"
Nov 11 18:03:29 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[1268]: 2017-11-11 18:03:29,233 INFO RPC interface 'supervisor' initialized
Nov 11 18:03:29 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[1268]: 2017-11-11 18:03:29,233 CRIT Server 'inet_http_server' running without any HTTP authentication checking
Nov 11 18:03:29 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[1268]: 2017-11-11 18:03:29,234 INFO RPC interface 'supervisor' initialized
Nov 11 18:03:29 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[1268]: 2017-11-11 18:03:29,234 CRIT Server 'unix_http_server' running without any HTTP authentication checking
Nov 11 18:03:29 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[1268]: 2017-11-11 18:03:29,234 INFO supervisord started with pid 1268
なんかいくつか文句言われてるけど、とりあえず起動したっぽい。 続けて、supervisorからdigdagを起動するためのファイルを準備。
$ cat /etc/supervisord.d/digdag.ini
[program:digdag]
command=/usr/local/bin/exec-digdag.sh
stdout_logfile=/var/log/supervisor/digdag-stdout.log
stderr_logfile=/var/log/supervisor/digdag-stderr.log
定義したshの中身は、こんな感じ。 この辺はwebで拾ったものを使わせていただいています。
$ cat /usr/local/bin/exec-digdag.sh
#!/bin/sh
export PATH=$PATH:/opt/jre/bin
exec /home/centos/bin/digdag server --memory
というわけで。 これでsupervisorを再起動すると・・・
Nov 11 18:14:31 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal systemd[1]: Starting Supervisor process control system for UNIX...
Nov 11 18:14:31 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[8656]: 2017-11-11 18:14:31,326 CRIT Supervisor running as root (no user in config file)
Nov 11 18:14:31 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[8656]: 2017-11-11 18:14:31,326 WARN Included extra file "/etc/supervisord.d/digdag.ini" during parsing
Nov 11 18:14:31 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[8656]: 2017-11-11 18:14:31,346 INFO RPC interface 'supervisor' initialized
Nov 11 18:14:31 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[8656]: 2017-11-11 18:14:31,346 CRIT Server 'inet_http_server' running without any HTTP authentication checking
Nov 11 18:14:31 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[8656]: 2017-11-11 18:14:31,346 INFO RPC interface 'supervisor' initialized
Nov 11 18:14:31 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[8656]: 2017-11-11 18:14:31,346 CRIT Server 'unix_http_server' running without any HTTP authentication checking
Nov 11 18:14:31 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[8656]: 2017-11-11 18:14:31,346 INFO supervisord started with pid 8656
Nov 11 18:14:32 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[8656]: 2017-11-11 18:14:32,349 INFO spawned: 'digdag' with pid 8659
Nov 11 18:14:33 ip-XXX-XXX-XXX-XXX.ap-northeast-1.compute.internal supervisord[8656]: 2017-11-11 18:14:33,700 INFO success: digdag entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
どうも動いているようだ。
$ digdag schedules
2017-11-11 18:26:53 +0000: Digdag v0.9.20
Schedules:
0 entries.
Use `digdag workflows [project-name] [workflow-name]` to show workflow details.
うんうん。起動している。 これで、とりあえず、環境が整いましたね。
ん?せきゅりてぃ?けいこく?えらー?細かい設定は各自でお願いします。←
ってわけで、ジョブを定義してembulk使ってみますかね。