Skip to content

Instantly share code, notes, and snippets.

@ktaragorn
Forked from ivanxuu/puma.sh
Last active January 15, 2018 09:08

Revisions

  1. ktaragorn revised this gist Jun 25, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion puma.sh
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ PUMA_PID_FILE=`grep pidfile $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\
    PUMA_PID_FILE=`grep pidfile $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/['\"]*//g"`
    PUMA_SOCKET=`grep bind $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/unix:\/\///;s/['\"]*//g"`
    WORKING_DIR=`grep directory $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/['\"]*//g"`
    if [ $1 -a $2 ] ; then # If passed 2 params the second one should be the puma config file
    if [ "$1" -a "$2" ] ; then # If passed 2 params the second one should be the puma config file
    PUMA_CONFIG_FILE=$2
    fi
    PUMA_CONFIGFILE_OWNER=`ls -l $PUMA_CONFIG_FILE |cut -d' ' -f3`
  2. ktaragorn revised this gist Jun 25, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions puma.sh
    Original file line number Diff line number Diff line change
    @@ -36,6 +36,7 @@ if [ $1 -a $2 ] ; then # If passed 2 params the second one should be the puma co
    fi
    PUMA_CONFIGFILE_OWNER=`ls -l $PUMA_CONFIG_FILE |cut -d' ' -f3`

    PUMA_PID_FILE=$WORKING_DIR$PUMA_PID_FILE
    #------------------------ checkings -------------------------------------
    if [ ! -r $PUMA_CONFIG_FILE ] ; then # if not readable
    echo "File $PUMA_CONFIG_FILE not found or not readable"
  3. ktaragorn revised this gist Jun 25, 2014. 1 changed file with 11 additions and 14 deletions.
    25 changes: 11 additions & 14 deletions puma.sh
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ PUMA_CONFIG_FILE=/path/yourRailsApp/config/puma.rb # WRITE HERE PUMA CONFIG FILE
    # if desired write here the path to the desired file for example:
    # PUMA_PID_FILE=/path/foo.pid
    PUMA_PID_FILE=`grep pidfile $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/['\"]*//g"`
    PUMA_TCP_PORT=`grep bind $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/tcp:\/\///;s/['\"]*//g"`
    PUMA_PID_FILE=`grep pidfile $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/['\"]*//g"`
    PUMA_SOCKET=`grep bind $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/unix:\/\///;s/['\"]*//g"`
    WORKING_DIR=`grep directory $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/['\"]*//g"`
    if [ $1 -a $2 ] ; then # If passed 2 params the second one should be the puma config file
    @@ -48,14 +48,9 @@ if [ -z $PUMA_PID_FILE ] ; then # if empty string
    echo 'pidfile "/path/puma.pid"'
    exit 1
    fi
    #if [ -z $PUMA_SOCKET ] ; then # if empty string
    # echo "bind option in $PUMA_SOCKET not found. You should write something like"
    # echo 'bind "unix://path/railsAppName.sock"'
    # exit 1
    #fi
    if [ -z $PUMA_TCP_PORT ] ; then # if empty string
    echo "bind option in $PUMA_TCP_PORT not found. You should write something like"
    echo 'bind "tcp://127.0.0.1:3000"'
    if [ -z $PUMA_SOCKET ] ; then # if empty string
    echo "bind option in $PUMA_SOCKET not found. You should write something like"
    echo 'bind "unix://path/railsAppName.sock"'
    exit 1
    fi
    if [ -z $WORKING_DIR ] ; then # if empty string
    @@ -68,19 +63,21 @@ fi
    #------------------------ functions -------------------------------------
    # check if puma process is running
    puma_is_running() {
    # if [ -S $PUMA_SOCKET ] ; then # if file exist and its a socket
    if [ -S $PUMA_SOCKET ] ; then # if file exist and its a socket
    if [ -r $PUMA_PID_FILE ] ; then # if file exist and readable
    if cat $PUMA_PID_FILE | xargs pgrep -P > /dev/null ; then
    # from @spacechurro at https://gist.github.com/joneslee85/5844933, I was not able to get the original if to work either
    # if cat $PUMA_PID_FILE | xargs pgrep -P > /dev/null ; then
    if ps -p `cat $PUMA_PID_FILE` > /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
    else
    echo "No puma socket found"
    fi

    return 1
    }
  4. ktaragorn revised this gist Jun 25, 2014. 1 changed file with 13 additions and 8 deletions.
    21 changes: 13 additions & 8 deletions puma.sh
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ PUMA_CONFIG_FILE=/path/yourRailsApp/config/puma.rb # WRITE HERE PUMA CONFIG FILE
    # if desired write here the path to the desired file for example:
    # PUMA_PID_FILE=/path/foo.pid
    PUMA_PID_FILE=`grep pidfile $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/['\"]*//g"`
    PUMA_PID_FILE=`grep pidfile $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/['\"]*//g"`
    PUMA_TCP_PORT=`grep bind $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/tcp:\/\///;s/['\"]*//g"`
    PUMA_SOCKET=`grep bind $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/unix:\/\///;s/['\"]*//g"`
    WORKING_DIR=`grep directory $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/['\"]*//g"`
    if [ $1 -a $2 ] ; then # If passed 2 params the second one should be the puma config file
    @@ -48,9 +48,14 @@ if [ -z $PUMA_PID_FILE ] ; then # if empty string
    echo 'pidfile "/path/puma.pid"'
    exit 1
    fi
    if [ -z $PUMA_SOCKET ] ; then # if empty string
    echo "bind option in $PUMA_SOCKET not found. You should write something like"
    echo 'bind "unix://path/railsAppName.sock"'
    #if [ -z $PUMA_SOCKET ] ; then # if empty string
    # echo "bind option in $PUMA_SOCKET not found. You should write something like"
    # echo 'bind "unix://path/railsAppName.sock"'
    # exit 1
    #fi
    if [ -z $PUMA_TCP_PORT ] ; then # if empty string
    echo "bind option in $PUMA_TCP_PORT not found. You should write something like"
    echo 'bind "tcp://127.0.0.1:3000"'
    exit 1
    fi
    if [ -z $WORKING_DIR ] ; then # if empty string
    @@ -63,7 +68,7 @@ fi
    #------------------------ functions -------------------------------------
    # check if puma process is running
    puma_is_running() {
    if [ -S $PUMA_SOCKET ] ; then # if file exist and its a socket
    # if [ -S $PUMA_SOCKET ] ; then # if file exist and its a socket
    if [ -r $PUMA_PID_FILE ] ; then # if file exist and readable
    if cat $PUMA_PID_FILE | xargs pgrep -P > /dev/null ; then
    return 0
    @@ -73,9 +78,9 @@ puma_is_running() {
    else
    echo "No puma pid file found"
    fi
    else
    echo "No puma socket found"
    fi
    # else
    # echo "No puma socket found"
    # fi

    return 1
    }
  5. @ivanxuu ivanxuu revised this gist Jul 7, 2013. 1 changed file with 11 additions and 5 deletions.
    16 changes: 11 additions & 5 deletions puma.sh
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@

    # You need to specify a location for the PUMA_CONFIG_FILE

    PUMA_CONFIG_FILE=/path/railsapp/config/puma.rb # WRITE HERE PUMA CONFIG FILE LOCATION
    PUMA_CONFIG_FILE=/path/yourRailsApp/config/puma.rb # WRITE HERE PUMA CONFIG FILE LOCATION
    # strip out quotes, remove comments, initial spaces, and get only the filename
    # if desired write here the path to the desired file for example:
    # PUMA_PID_FILE=/path/foo.pid
    @@ -34,6 +34,7 @@ WORKING_DIR=`grep directory $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\
    if [ $1 -a $2 ] ; then # If passed 2 params the second one should be the puma config file
    PUMA_CONFIG_FILE=$2
    fi
    PUMA_CONFIGFILE_OWNER=`ls -l $PUMA_CONFIG_FILE |cut -d' ' -f3`

    #------------------------ checkings -------------------------------------
    if [ ! -r $PUMA_CONFIG_FILE ] ; then # if not readable
    @@ -87,10 +88,15 @@ case "$1" in
    rm -f $PUMA_SOCKET
    echo "removed $PUMA_SOCKET"
    fi
    if [ -e $PUMA_CONFIG_FILE ] ; then # if config file exists
    /bin/bash --login -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)"
    else
    /bin/bash --login -c "(cd $WORKING_DIR && bundle exec puma )"
    # Exec puma as the owner, so we need to be either root or the real owner"*
    if [ `whoami` = $PUMA_CONFIGFILE_OWNER ] # owner
    then
    /bin/bash --login -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)"
    elif [ `whoami` = root ] # root
    then
    su -l $PUMA_CONFIGFILE_OWNER -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)"
    else # error
    echo "you should be root or the owner of the file to have the gemset ready to start the rails stack"
    fi

    echo "done"
  6. @ivanxuu ivanxuu revised this gist Jul 7, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion puma.sh
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    # Required-Start: $remote_fs $syslog
    # Required-Stop: $remote_fs $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop:
    # Default-Stop: 0 1 6
    # Short-Description: Puma web server
    ### END INIT INFO

  7. @ivanxuu ivanxuu revised this gist Jul 7, 2013. 1 changed file with 64 additions and 22 deletions.
    86 changes: 64 additions & 22 deletions puma.sh
    Original file line number Diff line number Diff line change
    @@ -16,23 +16,54 @@
    # If you need to start puma at boot time run this in debian/ubuntu: update-rc.d pumacontrol.sh defaults
    # It will create some links to execute /etc/init.d/pumacontrol.sh start at the begining

    # I use this in a system where the rails app is running by a normal user called $USER, where puma is
    # I use this in a system where the rails app is running by a normal user, where puma is
    # configured in PUMA_CONFIG_FILE. In PUMA_CONFIG_FILE is stated to create a pid file with the PID of
    # puma in the PUMA_PID_FILE file. The socket where nginx is redirecting the web traffic and puma is
    # listening is PUMA_SOCKET

    # You need to specify a location for the PUMA_CONFIG_FILE

    PUMA_CONFIG_FILE=/path/railsapp/config/puma.rb # WRITE HERE PUMA CONFIG FILE LOCATION
    # strip out quotes, remove comments, initial spaces, and get only the filename
    # if desired write here the path to the desired file for example:
    # PUMA_PID_FILE=/path/foo.pid
    PUMA_PID_FILE=`grep pidfile $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/['\"]*//g"`
    PUMA_PID_FILE=`grep pidfile $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/['\"]*//g"`
    PUMA_SOCKET=`grep bind $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/unix:\/\///;s/['\"]*//g"`
    WORKING_DIR=`grep directory $PUMA_CONFIG_FILE | sed -e "/^#/d;/^$/d;s/^\s*//;s/\w* //;s/['\"]*//g"`
    if [ $1 -a $2 ] ; then # If passed 2 params the second one should be the puma config file
    PUMA_CONFIG_FILE=$2
    fi

    PUMA_CONFIG_FILE=/home/webuser/railsApp/current/config/puma.rb #In my case this has been deployed with
    # capistrano. If you are using rails from a local environment probably will be something
    # like /home/webuser/railsApp/config/puma.rb
    PUMA_PID_FILE=/home/webuser/puma.pid
    PUMA_SOCKET=/home/webuser/puma.sock
    WORKING_DIR=/home/webuser/railsApp/current/
    USER=webuser

    #------------------------ checkings -------------------------------------
    if [ ! -r $PUMA_CONFIG_FILE ] ; then # if not readable
    echo "File $PUMA_CONFIG_FILE not found or not readable"
    echo "You should write in pumacontrol.sh the location of your config/puma.rb"
    echo "or run this script like this 'pumacontrol.sh start /path/railsapp/config/puma.rb'"
    exit 1
    fi
    if [ -z $PUMA_PID_FILE ] ; then # if empty string
    echo "pidfile option in $PUMA_PID_FILE not found. You should write something like"
    echo 'pidfile "/path/puma.pid"'
    exit 1
    fi
    if [ -z $PUMA_SOCKET ] ; then # if empty string
    echo "bind option in $PUMA_SOCKET not found. You should write something like"
    echo 'bind "unix://path/railsAppName.sock"'
    exit 1
    fi
    if [ -z $WORKING_DIR ] ; then # if empty string
    echo "directory option in $WORKING_DIR not found. You should write something like"
    echo "directory '/path/yourRailsAppRootDir/'"
    exit 1
    fi


    #------------------------ functions -------------------------------------
    # check if puma process is running
    puma_is_running() {
    if [ -S $PUMA_SOCKET ] ; then
    if [ -e $PUMA_PID_FILE ] ; then
    if [ -S $PUMA_SOCKET ] ; then # if file exist and its a socket
    if [ -r $PUMA_PID_FILE ] ; then # if file exist and readable
    if cat $PUMA_PID_FILE | xargs pgrep -P > /dev/null ; then
    return 0
    else
    @@ -48,43 +79,43 @@ puma_is_running() {
    return 1
    }

    #------------------------ script -------------------------------------
    case "$1" in
    start)
    echo "Starting puma..."
    if [ -e $PUMA_SOCKET ] ; then
    if [ -e $PUMA_SOCKET ] ; then # if socket exists
    rm -f $PUMA_SOCKET
    echo "removed $PUMA_SOCKET"
    fi
    if [ -e $PUMA_CONFIG_FILE ] ; then
    su -l <%= @user %> -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)"
    if [ -e $PUMA_CONFIG_FILE ] ; then # if config file exists
    /bin/bash --login -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)"
    else
    su -l <%= @user %> -c "(cd $WORKING_DIR && bundle exec puma )"
    /bin/bash --login -c "(cd $WORKING_DIR && bundle exec puma )"
    fi

    echo "done"
    ;;

    stop)
    echo "Stopping puma..."
    if [ -e $PUMA_PID_FILE ] ; then
    su -l <%= @user %> -c " kill -s SIGTERM `cat $PUMA_PID_FILE` "
    if [ -e $PUMA_PID_FILE ] ; then # if pid file exists
    echo "Stopping puma..."
    /bin/bash --login -c " kill -s SIGTERM `cat $PUMA_PID_FILE` "
    echo "Killed puma PID `cat $PUMA_PID_FILE`"
    rm -f $PUMA_PID_FILE
    echo "removed $PUMA_PID_FILE"
    fi
    if [ -e $PUMA_SOCKET ] ; then
    if [ -e $PUMA_SOCKET ] ; then # if socket exists
    rm -f $PUMA_SOCKET
    echo "removed $PUMA_SOCKET"
    fi

    echo "done"
    ;;

    restart)
    if puma_is_running ; then
    echo "Hot-restarting puma..."
    if [ -e $PUMA_PID_FILE ] ; then
    su -l <%= @user %> -c " kill -s SIGUSR2 `cat $PUMA_PID_FILE` "
    /bin/bash --login -c " kill -s SIGUSR2 `cat $PUMA_PID_FILE` "
    echo "Killed puma PID `cat $PUMA_PID_FILE`"
    fi
    echo "Doublechecking the process restart..."
    @@ -94,14 +125,25 @@ case "$1" in
    exit 0
    else
    echo "Puma restart failed :/"
    exit 1 # return error
    fi
    fi

    echo "Trying cold reboot"
    $0 start
    ;;

    status)
    if puma_is_running ; then
    echo "puma is running"
    exit 0
    else
    echo "puma is not running"
    exit 1 # return error
    fi

    ;;
    *)
    echo "Usage: script/puma.sh {start|stop|restart}" >&2
    echo "Usage: script/puma.sh {start|stop|restart|status}" >&2
    ;;
    esac
  8. @ivanxuu ivanxuu revised this gist Jul 4, 2013. 1 changed file with 17 additions and 8 deletions.
    25 changes: 17 additions & 8 deletions puma.sh
    Original file line number Diff line number Diff line change
    @@ -10,15 +10,24 @@
    # Short-Description: Puma web server
    ### END INIT INFO

    # Simple move this file into your Rails `script` folder. Also make sure you `chmod +x puma.sh`.
    # Please modify the CONSTANT variables to fit your configurations.

    PUMA_CONFIG_FILE=<%= @puma_config_file %>
    PUMA_PID_FILE=<%= @puma_pid_file %>
    PUMA_SOCKET=<%= @puma_socket %>
    WORKING_DIR=<%= @app_dir %>
    USER=<%= @user %>
    # Simple move this file into /etc/init.d/pumacontrol.sh
    # Also make sure you `chmod +x pumacontrol.sh`.

    # If you need to start puma at boot time run this in debian/ubuntu: update-rc.d pumacontrol.sh defaults
    # It will create some links to execute /etc/init.d/pumacontrol.sh start at the begining

    # I use this in a system where the rails app is running by a normal user called $USER, where puma is
    # configured in PUMA_CONFIG_FILE. In PUMA_CONFIG_FILE is stated to create a pid file with the PID of
    # puma in the PUMA_PID_FILE file. The socket where nginx is redirecting the web traffic and puma is
    # listening is PUMA_SOCKET

    PUMA_CONFIG_FILE=/home/webuser/railsApp/current/config/puma.rb #In my case this has been deployed with
    # capistrano. If you are using rails from a local environment probably will be something
    # like /home/webuser/railsApp/config/puma.rb
    PUMA_PID_FILE=/home/webuser/puma.pid
    PUMA_SOCKET=/home/webuser/puma.sock
    WORKING_DIR=/home/webuser/railsApp/current/
    USER=webuser

    # check if puma process is running
    puma_is_running() {
  9. @ivanxuu ivanxuu revised this gist Jul 4, 2013. 1 changed file with 46 additions and 21 deletions.
    67 changes: 46 additions & 21 deletions puma.sh
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,25 @@
    #! /bin/sh


    ### BEGIN INIT INFO
    # Provides: pumacontrol
    # Required-Start: $remote_fs $syslog
    # Required-Stop: $remote_fs $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop:
    # Short-Description: Puma web server
    ### END INIT INFO

    # Simple move this file into your Rails `script` folder. Also make sure you `chmod +x puma.sh`.
    # Please modify the CONSTANT variables to fit your configurations.

    PUMA_CONFIG_FILE=<%= @puma_config_file %>
    PUMA_PID_FILE=<%= @puma_pid_file %>
    PUMA_SOCKET=<%= @puma_socket %>
    WORKING_DIR=<%= @app_dir %>
    USER=<%= @user %>

    PUMA_CONFIG_FILE=config/puma.rb
    PUMA_PID_FILE=tmp/pids/puma.pid
    PUMA_SOCKET=tmp/sockets/puma.sock


    # check if puma process is running
    puma_is_running() {
    if [ -S $PUMA_SOCKET ] ; then
    @@ -22,37 +35,49 @@ puma_is_running() {
    else
    echo "No puma socket found"
    fi

    return 1
    }

    case "$1" in
    start)
    echo "Starting puma..."
    rm -f $PUMA_SOCKET
    if [ -e $PUMA_SOCKET ] ; then
    rm -f $PUMA_SOCKET
    echo "removed $PUMA_SOCKET"
    fi
    if [ -e $PUMA_CONFIG_FILE ] ; then
    bundle exec puma -C $PUMA_CONFIG_FILE
    su -l <%= @user %> -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)"
    else
    bundle exec puma
    su -l <%= @user %> -c "(cd $WORKING_DIR && bundle exec puma )"
    fi

    echo "done"
    ;;

    stop)
    echo "Stopping puma..."
    kill -s SIGTERM `cat $PUMA_PID_FILE`
    rm -f $PUMA_PID_FILE
    rm -f $PUMA_SOCKET

    if [ -e $PUMA_PID_FILE ] ; then
    su -l <%= @user %> -c " kill -s SIGTERM `cat $PUMA_PID_FILE` "
    echo "Killed puma PID `cat $PUMA_PID_FILE`"
    rm -f $PUMA_PID_FILE
    echo "removed $PUMA_PID_FILE"
    fi
    if [ -e $PUMA_SOCKET ] ; then
    rm -f $PUMA_SOCKET
    echo "removed $PUMA_SOCKET"
    fi

    echo "done"
    ;;

    restart)
    if puma_is_running ; then
    echo "Hot-restarting puma..."
    kill -s SIGUSR2 `cat $PUMA_PID_FILE`

    if [ -e $PUMA_PID_FILE ] ; then
    su -l <%= @user %> -c " kill -s SIGUSR2 `cat $PUMA_PID_FILE` "
    echo "Killed puma PID `cat $PUMA_PID_FILE`"
    fi
    echo "Doublechecking the process restart..."
    sleep 5
    if puma_is_running ; then
    @@ -62,11 +87,11 @@ case "$1" in
    echo "Puma restart failed :/"
    fi
    fi

    echo "Trying cold reboot"
    script/puma.sh start
    $0 start
    ;;

    *)
    echo "Usage: script/puma.sh {start|stop|restart}" >&2
    ;;
  10. Trung Lê revised this gist Jun 23, 2013. 1 changed file with 7 additions and 13 deletions.
    20 changes: 7 additions & 13 deletions puma.sh
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,9 @@
    #! /bin/sh

    # Simple move this file into your Rails `script` folder. Also make sure you `chmod +x puma.sh`.
    # The script will try to look for the `config/puma.rb` file, so make you have one first:
    # Below is example `config/puma.rb`:
    #
    # environment 'production'
    # daemonize
    #
    # workers 2
    # threads 0, 6
    #
    # pidfile "rails_app/tmp/pids/puma.pid"
    # bind "unix://rails_app/tmp/sockets/puma.sock"

    # Please modify the CONSTANT variables to fit your configurations.

    PUMA_CONFIG_FILE=config/puma.rb
    PUMA_PID_FILE=tmp/pids/puma.pid
    PUMA_SOCKET=tmp/sockets/puma.sock

    @@ -40,7 +30,11 @@ case "$1" in
    start)
    echo "Starting puma..."
    rm -f $PUMA_SOCKET
    bundle exec puma -C config/puma.rb
    if [ -e $PUMA_CONFIG_FILE ] ; then
    bundle exec puma -C $PUMA_CONFIG_FILE
    else
    bundle exec puma
    fi

    echo "done"
    ;;
  11. Trung Lê revised this gist Jun 23, 2013. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions puma.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,19 @@
    #! /bin/sh

    # Simple move this file into your Rails `script` folder. Also make sure you `chmod +x puma.sh`.
    # The script will try to look for the `config/puma.rb` file, so make you have one first:
    # Below is example `config/puma.rb`:
    #
    # environment 'production'
    # daemonize
    #
    # workers 2
    # threads 0, 6
    #
    # pidfile "rails_app/tmp/pids/puma.pid"
    # bind "unix://rails_app/tmp/sockets/puma.sock"


    PUMA_PID_FILE=tmp/pids/puma.pid
    PUMA_SOCKET=tmp/sockets/puma.sock

  12. Trung Lê revised this gist Jun 23, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions puma.sh
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,7 @@ case "$1" in

    stop)
    echo "Stopping puma..."
    bundle exec pumactl -P $PUMA_PID_FILE stop
    kill -s SIGTERM `cat $PUMA_PID_FILE`
    rm -f $PUMA_PID_FILE
    rm -f $PUMA_SOCKET

    @@ -43,7 +43,7 @@ case "$1" in
    restart)
    if puma_is_running ; then
    echo "Hot-restarting puma..."
    bundle exec pumactl -P $PUMA_PID_FILE restart
    kill -s SIGUSR2 `cat $PUMA_PID_FILE`

    echo "Doublechecking the process restart..."
    sleep 5
  13. Trung Lê created this gist Jun 23, 2013.
    65 changes: 65 additions & 0 deletions puma.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    #! /bin/sh

    PUMA_PID_FILE=tmp/pids/puma.pid
    PUMA_SOCKET=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
    }

    case "$1" in
    start)
    echo "Starting puma..."
    rm -f $PUMA_SOCKET
    bundle exec puma -C config/puma.rb

    echo "done"
    ;;

    stop)
    echo "Stopping puma..."
    bundle exec pumactl -P $PUMA_PID_FILE stop
    rm -f $PUMA_PID_FILE
    rm -f $PUMA_SOCKET

    echo "done"
    ;;

    restart)
    if puma_is_running ; then
    echo "Hot-restarting puma..."
    bundle exec pumactl -P $PUMA_PID_FILE restart

    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"
    script/puma.sh start
    ;;

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