16
12

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.

Pumaをsystemdで起動するメモ

Last updated at Posted at 2016-06-03

これは

pumaをcentos7のsystemdで起動させたメモです。

スニペット

/etc/systemd/system/puma.service
[Unit]
Description=Puma HTTP Server
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/opt/rails
Environment=RAILS_ENV=production
ExecStart=/usr/local/rvm/bin/rvm-exec 2.2.3 bundle exec puma -b tcp://0.0.0.0 -e production -p 80
TimeoutSec=300
Restart=always

[Install]
WantedBy=multi-user.target

実行

# systemctl enable puma.service
# systemctl start puma.service
# systemctl status puma.service
● puma.service - Puma HTTP Server
   Loaded: loaded (/etc/systemd/system/puma.service; enabled; vendor preset: disabled)
   Active: active (running) since 金 2016-06-03 10:43:04 JST; 10min ago
 Main PID: 6125 (ruby)
   CGroup: /system.slice/puma.service
           └─6125 puma 3.4.0 (tcp://0.0.0.0,tcp://0.0.0.0:80) [rails]

 6月 03 10:43:04 localhost.localdomain systemd[1]: Started Puma HTTP Server.
 6月 03 10:43:04 localhost.localdomain systemd[1]: Starting Puma HTTP Server...
 6月 03 10:43:05 localhost.localdomain rvm-exec[6125]: Puma starting in single mode...
 6月 03 10:43:05 localhost.localdomain rvm-exec[6125]: * Version 3.4.0 (ruby 2.2.3-p173), codename: Owl Bowl Brawl
 6月 03 10:43:05 localhost.localdomain rvm-exec[6125]: * Min threads: 8, max threads: 250
 6月 03 10:43:05 localhost.localdomain rvm-exec[6125]: * Environment: production
 6月 03 10:43:10 localhost.localdomain rvm-exec[6125]: * Listening on tcp://0.0.0.0
 6月 03 10:43:10 localhost.localdomain rvm-exec[6125]: * Listening on tcp://0.0.0.0:80
 6月 03 10:43:10 localhost.localdomain rvm-exec[6125]: Use Ctrl-C to stop

メモ

  • ExecStartの一番初めのコマンドはフルパスで記述する必要がある
    • パスをつけないとsystemdがエラーを出して起動しない
  • WorkingDirectoryでカレントパスを明示できる
    • bundlerを使っている場合カレントパスが重要なので指定が必要
  • プロセスをデーモンに明示的にする必要はない
    • systemdが勝手にバックグラウンドにしてくれるっぽい
  • 設定ファイルを変更したらsystemctl daemon-reloadを実行しないと反映されない
  • rvmを使ってるのでrvm-execでRubyのバージョンを指定する必要がある
16
12
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
16
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?