Last active
September 2, 2018 22:44
-
-
Save adastreamer/f1ef6989702e91c36f3a2fbdcf209200 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PORT_FILE=/home/deployer/PORT | |
APP_DIR=/var/www/cryptoprocessing | |
APP_PIDS_DIR=$APP_DIR/tmp/pids | |
UPSTREAM_CONFIG_FILE=/home/deployer/UPSTREAM_SERVERS | |
PORT=$(cat $PORT_FILE) | |
if [ "$PORT" == "3000" ] | |
then | |
NEW_PORT=3001 | |
else | |
NEW_PORT=3000 | |
fi | |
echo "$(date +%s%N) Starting new process" | |
cd $APP_DIR | |
/bin/bash -l -i -c "cd $APP_DIR && rails s -e production -P $APP_PIDS_DIR/$NEW_PORT.pid -p $NEW_PORT -d" | |
echo "Waiting" | |
sleep 2 | |
echo "$(date +%s%N) Killing old process" | |
CURRENT_PID_FILE=$APP_PIDS_DIR/$PORT.pid | |
CURRENT_PID=$(cat $CURRENT_PID_FILE) | |
kill -9 $CURRENT_PID | |
echo "$(date +%s%N) Writing new port to $PORT_FILE" | |
echo $NEW_PORT > $PORT_FILE | |
echo "$(date +%s%N) Updating config and reloading Nginx" | |
echo -e "server 127.0.0.1:$NEW_PORT;\nserver 127.0.0.1:$PORT;" > $UPSTREAM_CONFIG_FILE | |
sudo nginx -s reload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment