Skip to content

Instantly share code, notes, and snippets.

@jeremyrajan
Forked from runlevel5/puma.sh
Last active August 29, 2015 14:15
Show Gist options
  • Save jeremyrajan/26003e3a92f3c7a90335 to your computer and use it in GitHub Desktop.
Save jeremyrajan/26003e3a92f3c7a90335 to your computer and use it in GitHub Desktop.

Revisions

  1. Trung Lê revised this gist Jul 10, 2013. 1 changed file with 10 additions and 8 deletions.
    18 changes: 10 additions & 8 deletions puma.sh
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,10 @@
    #! /bin/sh
    #!/usr/bin/env bash

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

    # The script will start with config set by $PUMA_CONFIG_FILE by default

    PUMA_CONFIG_FILE=config/puma.rb
    PUMA_PID_FILE=tmp/pids/puma.pid
    PUMA_SOCKET=tmp/sockets/puma.sock
    @@ -29,12 +31,12 @@ puma_is_running() {
    case "$1" in
    start)
    echo "Starting puma..."
    rm -f $PUMA_SOCKET
    if [ -e $PUMA_CONFIG_FILE ] ; then
    bundle exec puma -C $PUMA_CONFIG_FILE
    else
    bundle exec puma
    fi
    rm -f $PUMA_SOCKET
    if [ -e $PUMA_CONFIG_FILE ] ; then
    bundle exec puma --config $PUMA_CONFIG_FILE
    else
    bundle exec puma --daemon --bind unix://$PUMA_SOCKET --pidfile $PUMA_PID_FILE
    fi

    echo "done"
    ;;
    @@ -70,4 +72,4 @@ case "$1" in
    *)
    echo "Usage: script/puma.sh {start|stop|restart}" >&2
    ;;
    esac
    esac
  2. 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"
    ;;
  3. 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

  4. 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
  5. 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