14
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

systemdを用いたdigdag serverのデーモン化についてのメモ

Posted at

digdag serverのデーモン化について、いろんなバージョン違いの影響からか、
ネット上の記事間で記述が異なっていたりして地味に困ったので、備忘録として投稿します。
なお、今回の環境は下記の通りです。

  • OS:Amazon Linux 2
  • Java:1.8
  • digdag:0.9.35

※ digdagは、Treasure Data社が作ったOSSワークフローエンジンです
  https://www.digdag.io/

起動スクリプトの作成

systemdを使ってデーモン化します。
/etc/systemd/system/digdag.serviceを配置します。
一通り調べて、下記のように設定すればよかろう、と思ったのがこちらです(後述のように、これでもダメだったのですが・・・)。

digdag.service
[Unit]
Description=digdag

[Service]
Type=simple
User=digdag
Restart=always
RestartSec=5
TimeoutStartSec=30s
WorkingDirectory=/opt/digdag/
KillMode=process

ExecStart=/usr/local/bin/digdag server --config /opt/digdag/server.properties --log /opt/digdag/logs/digdag_server.log -b x.x.x.x -O /opt/digdag/logs/tasklogs -A /opt/digdag/logs/accesslogs

[Install]
WantedBy=multi-user.target

パスは絶対パスで記述します。
ユーザdigdagで実行されるような設定です。
これで下記コマンドを叩いてデーモン化完了です。

systemctl enable digdag
systemctl start digdag

エラー発生

それでも起動しませんでした。
システムログを見るとこのようなメッセージが。

systemd: Starting digdag...
systemd: Failed at step EXEC spawning /usr/local/bin/digdag: Exec format error
systemd: digdag.service: main process exited, code=exited, status=203/EXEC
systemd: Unit digdag.service entered failed state.
systemd: digdag.service failed.

status=203で調べてみると、権限付与のミスが原因という情報がいくつか出て来ましたが、そこはクリアしています。
もう少し調べてみると、stackoverflow等で、Shebang(ソースの冒頭に書く"#!/bin/bash"とかのこと)がないとダメだよ!という記事がちらほら出てきます。

解決策1

そこで、ExecStart=に記述したコマンドを内包するシェルスクリプトを作成し、それを実行させることに。

digdag_start.sh
#!/bin/bash

/usr/local/bin/digdag server --config /opt/digdag/server.properties --log /opt/digdag/logs/digdag_server.log -b x.x.x.x -O /opt/digdag/logs/tasklogs -A /opt/digdag/logs/accesslogs
digdag.service
[Unit]
Description=digdag

[Service]
Type=simple
User=digdag
Restart=always
RestartSec=5
TimeoutStartSec=30s
WorkingDirectory=/opt/digdag/
KillMode=process

ExecStart=/opt/digdag/digdag_start.sh

[Install]
WantedBy=multi-user.target

これでsystemctl start digdagを叩くと、無事起動しました。

解決策2

ただこの解決策1は、下記のように起動スクリプトを記述するのと同義です。
実際、これで起動させても正常に動きました。

digdag.service
[Unit]
Description=digdag

[Service]
Type=simple
User=digdag
Restart=always
RestartSec=5
TimeoutStartSec=30s
WorkingDirectory=/opt/digdag/
KillMode=process

ExecStart=/bin/bash /usr/local/bin/digdag server --config /opt/digdag/server.properties --log /opt/digdag/logs/digdag_server.log -b x.x.x.x -O /opt/digdag/logs/tasklogs -A /opt/digdag/logs/accesslogs

[Install]
WantedBy=multi-user.target

要は、インタプリタを明示しないといけなかった、ということのようです。
起動コマンドを.service内に記述するのと、別のシェルスクリプトを作成するのとで、起動コマンドのハンドリングのしやすさが異なるので、
状況によってどちらにするか判断することになるかなと思います。
(今回の場合、起動コマンドの書き換えは基本的に発生しないため、解決策2を採用しました)

digdagに限らず、systemdを用いたデーモン化で困っている方の一助になれば幸いです。

14
10
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?