Sha256: 81e60bb40f0c0432e6e137234bb6a9181ba42e0c5bfb3a843d5c3f5f27327459

Contents?: true

Size: 1.98 KB

Versions: 3

Compression:

Stored size: 1.98 KB

Contents

#!/usr/bin/env bash

### BEGIN INIT INFO
# Provides:          puma
# Required-Start:
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: puma rails server
# Description:       puma serves rails fast
### END INIT INFO


# This monit wrapper script will be called by monit as root
# Edit these variables to your liking

USER={{ deployer_user.name }}
APP_DIR={{ be_app_path }}
PUMA_CONFIG_FILE=$APP_DIR/config/puma.production.rb
PUMA_PID_FILE={{ puma_pidfile }}
PUMA_SOCKET={{ puma_sockfile }}

# 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
}

case "$1" in
  start)
    echo "Starting puma..."
    rm -f $PUMA_SOCKET

    if [ -e $PUMA_CONFIG_FILE ] ; then
      echo "cd $APP_DIR && bundle exec puma -C $PUMA_CONFIG_FILE --daemon"
      /bin/su - $USER -c "cd $APP_DIR && bundle exec puma -C $PUMA_CONFIG_FILE --daemon"
    else
      echo "ERROR: No config file found in $PUMA_CONFIG_FILE"
    fi

    echo "done"
    ;;

  stop)
    echo "Stopping puma..."
      echo "cd $APP_DIR && bundle exec pumactl stop"
      /bin/su - $USER -c "cd $APP_DIR && bundle exec pumactl --config-file $PUMA_CONFIG_FILE stop"
      rm -f $PUMA_PID_FILE
      rm -f $PUMA_SOCKET

    echo "done"
    ;;

  restart)
    if puma_is_running ; then
      echo "Hot-restarting puma..."
      /bin/su - $USER -c "cd $APP_DIR && bundle exec pumactl --config-file $PUMA_CONFIG_FILE restart"

      echo "Doublechecking the process restart..."
      sleep 15
      if puma_is_running ; then
        echo "done"
        exit 0
      else
        echo "Puma restart failed :/"
      fi
    fi
    ;;
  *)
    echo "Usage: puma {start|stop|restart}" >&2
    ;;
esac

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
taperole-2.1.1 roles/install_puma/templates/puma_init.j2
taperole-2.1.0 roles/install_puma/templates/puma_init.j2
taperole-2.0.7 roles/puma_install/templates/puma_init.j2