Skip to content

Instantly share code, notes, and snippets.

@moh8med
Last active October 26, 2016 00:04
Show Gist options
  • Save moh8med/27f4437a559ec862635f7d9f2593588e to your computer and use it in GitHub Desktop.
Save moh8med/27f4437a559ec862635f7d9f2593588e to your computer and use it in GitHub Desktop.
Simple Lumen deployment using lumen-deploy.sh
#!/bin/bash
#
# Variables
#
# DOCUMENT_ROOT="/path/to/lumen"
DOCUMENT_ROOT=$(dirname "$0")
supervisord -v > /dev/null 2>&1
SUPERVISORD_IS_INSTALLED=$?
ps aux | grep -v grep | grep 'supervisord' > /dev/null 2>&1
SUPERVISORD_IS_RUNNING=$?
# Stop supervisor service if it exists and running.
if [[ "$SUPERVISORD_IS_INSTALLED" -eq 0 && "$SUPERVISORD_IS_RUNNING" -eq 0 ]]; then
echo -e "\n$(tput setaf 2)>>> Stopping all Supervisord processes$(tput sgr0)"
sudo service supervisor stop
fi
#
# Enable Maintenance Mode
#
# Make sure that your web server is configured to serve index.html if index.php is not exists.
# NGINX example: location / { index index.php index.html; }
#
echo -e "\n$(tput setaf 2)>>> Enabling maintenance mode (use index.html)$(tput sgr0)"
mv "$DOCUMENT_ROOT/public/index.php" "$DOCUMENT_ROOT/public/index_.php"
echo -e "\n$(tput setaf 2)>>> Starting the ssh-agent in the background$(tput sgr0)"
eval "$(ssh-agent -s)"
echo -e "\n$(tput setaf 2)>>> Adding SSH key to the ssh-agent$(tput sgr0)"
ssh-add ~/.ssh/id_rsa
echo -e "\n$(tput setaf 2)>>> Changing directory to the project path ($DOCUMENT_ROOT)$(tput sgr0)"
cd $DOCUMENT_ROOT
echo -e "\n$(tput setaf 2)>>> Fetching new changes in the remote repository$(tput sgr0)"
git checkout master
git pull
echo -e "\n$(tput setaf 2)>>> Updating Composer$(tput sgr0)"
composer self-update
composer update
composer dump-autoload
if [ -f "$DOCUMENT_ROOT/.env.deployment" ]; then
echo -e "\n$(tput setaf 2)>>> Using deployment configuration file (.env.deployment)$(tput sgr0)"
mv "$DOCUMENT_ROOT/.env" "$DOCUMENT_ROOT/.env.production"
mv "$DOCUMENT_ROOT/.env.deployment" "$DOCUMENT_ROOT/.env"
fi
echo -e "\n$(tput setaf 2)>>> Disabling maintenance mode (use index.php)$(tput sgr0)"
if [ ! -f "$DOCUMENT_ROOT/public/index.php" ]
then
mv "$DOCUMENT_ROOT/public/index_.php" "$DOCUMENT_ROOT/public/index.php"
else
rm "$DOCUMENT_ROOT/public/index_.php"
fi
echo -e "\n$(tput setaf 2)>>> Running the database migrations$(tput sgr0)"
php "$DOCUMENT_ROOT/artisan" migrate
if [ -f "$DOCUMENT_ROOT/.env.production" ]; then
echo -e "\n$(tput setaf 2)>>> Using production configuration file (.env.production)$(tput sgr0)"
mv "$DOCUMENT_ROOT/.env" "$DOCUMENT_ROOT/.env.deployment"
mv "$DOCUMENT_ROOT/.env.production" "$DOCUMENT_ROOT/.env"
fi
# Start supervisor service if it exists.
if [ "$SUPERVISORD_IS_INSTALLED" -eq 0 ]; then
echo -e "\n$(tput setaf 2)>>> Starting Supervisord processes again$(tput sgr0)"
sudo service supervisor start
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment