0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

開発環境のpumaをsystemd経由で自動起動/制御する

Last updated at Posted at 2023-12-23

はじめに

開発環境のpumaをsystemdに登録し、systemctlを使って起動・停止などの制御をするようにします。

環境

  • AlmaLinux 9.3
  • Ruby 2.7.8
  • Rails 6.1.4.7
  • puma 5.5.2
  • sd_notify 0.1.1

sd_notifyのインストール

Gemfile
gem 'sd_notify'

Gemfileにsd_notifyを追加してbundle installします。

systemdのユニットファイルを作成

/usr/lib/systemd/system/puma-app01.service
[Unit]
Description=App01 hosted by puma
After=network.target

[Service]
WorkingDirectory=/path/to/app01
ExecStart=/bin/bash -lc 'bundle exec pumactl start'
User=app01
Group=apps
Type=notify
WatchdogSec=10
Restart=always
Environment=RAILS_ENV=development

[Install]
WantedBy=multi-user.target
  • WorkingDirectory: アプリケーションルートをフルパスで指定します
  • ExecStart: 実行コマンドを指定します(フルパスでの指定が必要ですがbash -lcを挟むことで普段のコマンドに近い形で記述できます)
  • User: 実行ユーザーを指定します
  • Group: 実行グループを指定します

起動・停止など

$ sudo systemctl start puma-app01
$ sudo systemctl status puma-app01
$ sudo systemctl restart puma-app01
$ sudo systemctl stop puma-app01

自動起動設定

$ sudo systemctl enable puma-app01
$ sudo systemctl status puma-app01

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?