2
2

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 3 years have passed since last update.

pumaをdevelopment環境でもバックグラウンドで実行する

Posted at

puma 5.0.0からデーモン化機能が削除されてしまったので、production環境ではsystemdで動かす事になった。
development環境ではrails sなどで実行すればいいのだが、ターミナルを専有されるのが嫌なのでdevelopment環境でもrails sではなくバックグラウンドで実行するための自分用のメモ。
バックグラウンドで実行したいだけなら単純に&をつけて実行すればいいだけなので簡単。

結論

さっそくだが、こんなシェルスクリプトをプロジェクト直下のbin/ディレクトリに配置して実行権限を付与する(chmod +x)。

そしてこう使う。

bin/pumactl.sh start
bin/pumactl.sh stop
  • bin/pumactl.sh
#!/bin/bash

current_dir=`(cd $(dirname $0); pwd)`
rails_root=`(cd "$current_dir/../"; pwd)`
log_file="$rails_root/log/puma.log"
pid_dir="${rails_root}/tmp/pids"
pid_file="${pid_dir}/puma.pid"

start() {
  echo "starting puma"

  mkdir -p $pid_dir
  cd $rails_root
  bundle exec pumactl start >> $log_file  2>&1 &
}

stop() {
  echo "stopping puma"
  cd $rails_root

  if [ -f $pid_file ]; then
    bundle exec pumactl stop
  else
    echo "pid file not found: $pid_file"
  fi
}

restart() {
  echo "restarting puma"
  stop
  start
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  *)
    echo $"Usage: $prog {start|stop|restart}"
esac
2
2
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?