Created
July 10, 2014 18:17
-
-
Save vparihar01/01e9a676111235d9dfa8 to your computer and use it in GitHub Desktop.
Unicorn Bash script for Zero DownTime Deployment. We can deploy as many as time on production environment without showing application down page. This gives us one extra hand to do continuos deployment and integration on live server. Things like this can't be achieved using the passenger.
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 | |
| ### BEGIN INIT INFO | |
| # Provides: unicorn | |
| # Required-Start: $local_fs $remote_fs $network $syslog | |
| # Required-Stop: $local_fs $remote_fs $network $syslog | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Short-Description: starts the unicorn web server | |
| # Description: starts unicorn | |
| ### END INIT INFO | |
| APP_ROOT="/var/www/www.example.com" | |
| USER="deploy" | |
| DAEMON=unicorn_rails | |
| DAEMON_OPTS="-c $APP_ROOT/shared/config/unicorn.rb -E production -D" | |
| NAME=unicorn | |
| DESC="Unicorn app for $USER" | |
| PID=/var/www/www.example.com/shared/pids/unicorn.pid | |
| case "$1" in | |
| start) | |
| CD_TO_APP_DIR="cd $APP_ROOT/current" | |
| START_DAEMON_PROCESS="$DAEMON $DAEMON_OPTS" | |
| echo -n "Starting $DESC: " | |
| if [ `whoami` = root ]; then | |
| su - $USER -c "$CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS" | |
| else | |
| $CD_TO_APP_DIR && $START_DAEMON_PROCESS | |
| fi | |
| echo "$NAME." | |
| ;; | |
| stop) | |
| echo -n "Stopping $DESC: " | |
| kill -QUIT `cat $PID` | |
| echo "$NAME." | |
| ;; | |
| restart) | |
| echo -n "Restarting $DESC: " | |
| kill -s USR2 `cat $PID` | |
| echo "$NAME." | |
| ;; | |
| reload) | |
| echo -n "Reloading $DESC configuration: " | |
| kill -HUP `cat $PID` | |
| echo "$NAME." | |
| ;; | |
| *) | |
| echo "Usage: $NAME {start|stop|restart|reload}" >&2 | |
| exit 1 | |
| ;; | |
| esac | |
| exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment