LoginSignup
0
0

More than 1 year has passed since last update.

rails6 systemdの書き方について

Posted at

はじめに

初めてsystemdを書いた時の自分への戒めとして、こちらを書こうと思います。

環境

ruby 3.0.2
rails 6.1.4
puma 5.4

参考URL

エラー

$ sudo journalctl -fp err
systemd:Failed at step CHDIR spawning /home/ec2-user/.rbenv/shims/bundle: No such file or directory

単純に「bundleのファイルかディレクトリがありません」と思い確認してみた所、存在しています。

対象コード

[Unit]
Description=Puma HTTP Server
After=network.target

[Service]

Type=notify

WatchdogSec=10

User=tomo

WorkingDirectory=/var/www/my_app/current

Environment=RAILS_ENV=production
Environment=RAILS_SERVE_STATIC_FILES=1

ExecStart=/home/ec2-user/.rbenv/shims/bundle exec puma -C /var/www/my_app/current/config/puma.rb

Restart=always

[Install]
WantedBy=multi-user.target

参考URLのコードを確認してみましたが、スペルミスもなく間違えがないと思いました。

CHDIR

CHDIRが何かというと
「自分の今いるディレクトリを移動するときに使うコマンド」みたいです。

原因

WorkingDirectoryが
アプリケーションコードのルートディレクトリへのパスになるのですが、
本来は、WorkingDirectory=/var/www/my_appになる所を間違えてmy_appの後に存在しないcurrentを付け加えていました。

反省

今回みたいに、WorkingDirectoryなどコードの意味を理解してないとエラーでハマることを改めて再認識しました。

0
0
0

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
0
0