Sha256: 6ca0b9375c3347d3f40531c8b2988f3cf73de21bc9539856808d1813dc82f398

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

#! /bin/sh

BUNDLE_BIN=/usr/local/rbenv/shims/bundle
APP_PATH=/var/www/<%= Rails.application.class.parent_name.underscore %>
PUMA_CONFIG_FILE=$APP_PATH/current/config/puma.rb
PUMA_PID_FILE=$APP_PATH/shared/tmp/pids/puma.pid
PUMA_SOCKET=$APP_PATH/shared/tmp/sockets/puma.sock

# check if puma process is running
puma_is_running() {
  if [ -S $PUMA_SOCKET ] ; then
    if [ -e $PUMA_PID_FILE ] ; then
      if cat $PUMA_PID_FILE | xargs pgrep -P > /dev/null ; then
        return 0
      else
        echo "No puma process found"
      fi
    else
      echo "No puma pid file found"
    fi
  else
    echo "No puma socket found"
  fi

  return 1
}

puma_start() {
  rm -f $PUMA_SOCKET
  if [ -e $PUMA_CONFIG_FILE ] ; then
    $BUNDLE_BIN exec puma -C $PUMA_CONFIG_FILE
  else
    $BUNDLE_BIN exec puma
  fi
}

puma_stop() {
  cat $PUMA_PID_FILE | xargs kill -31
  rm -f $PUMA_PID_FILE
  rm -f $PUMA_SOCKET
}

case "$1" in
  start)
    echo "Starting puma..."
    puma_start
    echo "done"
    ;;

  stop)
    echo "Stopping puma..."
    puma_stop
    echo "done"
    ;;

  restart)
    if puma_is_running ; then
      echo "Hot-restarting puma..."
      puma_stop
      puma_start

      echo "Doublechecking the process restart..."
      sleep 5
      if puma_is_running ; then
        echo "done"
        exit 0
      else
        echo "Puma restart failed :/"
      fi
    fi

    echo "Trying cold reboot"
    bin/puma.sh start
    ;;

  *)
    echo "Usage: script/puma.sh {start|stop|restart}" >&2
    ;;
esac

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails-ahoy-0.0.2 lib/generators/ahoy/templates/_puma.sh
rails-ahoy-0.0.1 lib/generators/ahoy/templates/_puma.sh