Skip to content

Instantly share code, notes, and snippets.

@pinglamb
Last active June 21, 2016 10:00
Show Gist options
  • Select an option

  • Save pinglamb/fc535ac839e9017848243c810179a361 to your computer and use it in GitHub Desktop.

Select an option

Save pinglamb/fc535ac839e9017848243c810179a361 to your computer and use it in GitHub Desktop.

Revisions

  1. pinglamb renamed this gist Jun 21, 2016. 1 changed file with 9 additions and 8 deletions.
    17 changes: 9 additions & 8 deletions server.sh → rails_server
    Original file line number Diff line number Diff line change
    @@ -7,21 +7,21 @@ MY_PIDFILE=tmp/pids/my.pid
    PUMA_PIDFILE=tmp/pids/puma.pid

    case $1 in
    "on")
    "start")
    if [ -e $MY_PIDFILE ]
    then
    echo "PID file $MY_PIDFILE found, please run \"server off\" first"
    echo "PID file $MY_PIDFILE found, please run \"rails_server stop\" first"
    exit 1
    fi

    if [ -e $PUMA_PIDFILE ]
    then
    echo "PID file $PUMA_PIDFILE found, please run \"server off\" first"
    echo "PID file $PUMA_PIDFILE found, please run \"rails_server stop\" first"
    exit 1
    fi

    start_server () {
    puma config.ru -d --pidfile $PUMA_PIDFILE --redirect-stdout log/puma.log --redirect-stderr log/puma.log
    bundle exec puma config.ru -d --pidfile $PUMA_PIDFILE --redirect-stdout log/puma.log --redirect-stderr log/puma.log
    }

    start_server
    @@ -32,13 +32,14 @@ case $1 in
    then
    start_server
    else
    pumactl --pidfile $PUMA_PIDFILE restart
    bundle exec pumactl --pidfile $PUMA_PIDFILE stop
    start_server
    fi
    done > log/puma.log 2>&1&

    echo $! > $MY_PIDFILE
    ;;
    "off")
    "stop")
    test -e $MY_PIDFILE && ps --pid $(cat $MY_PIDFILE) &>/dev/null
    if [ $? -eq 0 ]
    then
    @@ -52,14 +53,14 @@ case $1 in
    test -e $PUMA_PIDFILE && ps --pid $(cat $PUMA_PIDFILE) &>/dev/null
    if [ $? -eq 0 ]
    then
    pumactl --pidfile $PUMA_PIDFILE stop
    bundle exec pumactl --pidfile $PUMA_PIDFILE stop
    echo "Turned off Puma"
    else
    echo "Puma is not running"
    fi
    rm -f $PUMA_PIDFILE
    ;;
    *)
    echo "Usage: server on|off"
    echo "Usage: rails_server start|stop"
    ;;
    esac
  2. pinglamb revised this gist Jun 14, 2016. 1 changed file with 57 additions and 11 deletions.
    68 changes: 57 additions & 11 deletions server.sh
    Original file line number Diff line number Diff line change
    @@ -6,14 +6,60 @@
    MY_PIDFILE=tmp/pids/my.pid
    PUMA_PIDFILE=tmp/pids/puma.pid

    nohup inotifywait -m tmp/restart.txt -e attrib -q | while read event; do
    test -e "$PUMA_PIDFILE" && pumactl --pidfile $PUMA_PIDFILE status
    if [ $? -ne 0 ]
    then
    puma config.ru -d --pidfile $PUMA_PIDFILE --redirect-stdout log/puma.log --redirect-stderr log/puma.log
    else
    pumactl --pidfile $PUMA_PIDFILE restart
    fi
    done > log/puma.log 2>&1&

    echo $! > $MY_PIDFILE
    case $1 in
    "on")
    if [ -e $MY_PIDFILE ]
    then
    echo "PID file $MY_PIDFILE found, please run \"server off\" first"
    exit 1
    fi

    if [ -e $PUMA_PIDFILE ]
    then
    echo "PID file $PUMA_PIDFILE found, please run \"server off\" first"
    exit 1
    fi

    start_server () {
    puma config.ru -d --pidfile $PUMA_PIDFILE --redirect-stdout log/puma.log --redirect-stderr log/puma.log
    }

    start_server

    nohup inotifywait -m tmp/restart.txt -e attrib -q | while read event; do
    test -e "$PUMA_PIDFILE" && pumactl --pidfile $PUMA_PIDFILE status
    if [ $? -ne 0 ]
    then
    start_server
    else
    pumactl --pidfile $PUMA_PIDFILE restart
    fi
    done > log/puma.log 2>&1&

    echo $! > $MY_PIDFILE
    ;;
    "off")
    test -e $MY_PIDFILE && ps --pid $(cat $MY_PIDFILE) &>/dev/null
    if [ $? -eq 0 ]
    then
    kill -9 $(cat $MY_PIDFILE)
    echo "Turned off monitor"
    else
    echo "Monitor is not running"
    fi
    rm -f $MY_PIDFILE

    test -e $PUMA_PIDFILE && ps --pid $(cat $PUMA_PIDFILE) &>/dev/null
    if [ $? -eq 0 ]
    then
    pumactl --pidfile $PUMA_PIDFILE stop
    echo "Turned off Puma"
    else
    echo "Puma is not running"
    fi
    rm -f $PUMA_PIDFILE
    ;;
    *)
    echo "Usage: server on|off"
    ;;
    esac
  3. pinglamb revised this gist Jun 14, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions server.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    #!/usr/bin/env bash

    # Dependencies:
    # - inotify-tools

    MY_PIDFILE=tmp/pids/my.pid
    PUMA_PIDFILE=tmp/pids/puma.pid

  4. pinglamb created this gist Jun 14, 2016.
    16 changes: 16 additions & 0 deletions server.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/usr/bin/env bash

    MY_PIDFILE=tmp/pids/my.pid
    PUMA_PIDFILE=tmp/pids/puma.pid

    nohup inotifywait -m tmp/restart.txt -e attrib -q | while read event; do
    test -e "$PUMA_PIDFILE" && pumactl --pidfile $PUMA_PIDFILE status
    if [ $? -ne 0 ]
    then
    puma config.ru -d --pidfile $PUMA_PIDFILE --redirect-stdout log/puma.log --redirect-stderr log/puma.log
    else
    pumactl --pidfile $PUMA_PIDFILE restart
    fi
    done > log/puma.log 2>&1&

    echo $! > $MY_PIDFILE