November 23, 2016 · Linux Server

Hot deploy script

#swap directory creation
echo "Creating Swap Directory"
cp -r ~/public_html/ ~/public_html/www.example.com_swap

#updating repository
echo "Updating Repository in swap directory"
cd ~/public_html/www.example.com_swap
ps axo user:20,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,args | grep artisan | grep livevotefb | awk '{print $2}' | xargs kill
git checkout master
git pull origin master --force
composer update --no-scripts
php artisan migrate --force --env=production
bower install
gulp --production

#file permission
echo "Updating File Permission.."
find ~/public_html/www.example.com_swap -type d -exec chmod 755 {} \;
find ~/public_html/www.example.com_swap -type d -exec chmod ug+s {} \;
find  ~/public_html/www.example.com_swap -type f -exec chmod 644 {} \;
chmod -R 777 ~/public_html/www.example.com_swap/storage
chmod -R 777 ~/public_html/www.example.com_swap/bootstrap/cache/

#upload permission
echo "Creating Upload Folder and setting permissions..."
mkdir ~/public_html/www.example.com_swap/public/uploads
chmod 777 ~/public_html/www.example.com_swap/public/uploads

echo "Completed! Please check the directory in  ~/public_html/www.example.com_swap"
echo "If you are confirmed, please also run the swap command:"
echo "mv ~/public_html/ ~/public_html/www.example.com_bak"
echo "mv ~/public_html/www.example.com_swap ~/public_html/"