Skip to content

Instantly share code, notes, and snippets.

@dantoncancella
Last active January 28, 2016 13:17
Show Gist options
  • Save dantoncancella/379897131fae560a5684 to your computer and use it in GitHub Desktop.
Save dantoncancella/379897131fae560a5684 to your computer and use it in GitHub Desktop.
#!/bin/bash
# To enable this hook, rename this file to "post-update".
project_folder="/var/www/example"; # Folder where the project live
project_name="Example"; # Project name
remote_upstream="origin"; # Remote server name
upstream_branch="develop"; # Remote upstream branch name
remote_branch="$remote_upstream/$upstream_branch"; # The upstream branch on remote server
apache_user=$(pstree -p | grep -E "apache|httpd" -m1 | rev | cut -d'(' -f1 | rev | tr -d ')' | xargs ps -o user h -p); # Apache user
cd $project_folder;
echo "Updating Upstream server ...";
env -i git fetch $remote_upstream -p;
echo "Forcing checkout on $upstream_branch branch ...";
env -i git checkout --force $upstream_branch;
echo "Pointing $upstream_branch branch to top of $remote_branch ...";
env -i git reset --hard $remote_branch;
# After this point, run the script that rebuild your application, with full path
echo "Building the $project_name ...";
echo "Updating Composer Libraries ...";
composer install;
echo "Installing bower libs ...";
bower --allow-root --config.interactive=false install;
echo "Clearing cache ...";
rm -rf app/cache/*;
echo "Updating database schema ...";
env -i php app/console doctrine:schema:update --force;
#echo "Loading fixtures data ...";
#env -i php app/console doctrine:fixtures:load --no-interaction;
echo "Dumping Assetics ...";
# Dump assetics to prod env
env -i php app/console assetic:dump --env=prod --no-debug;
echo "Installing Assets ...";
env -i php app/console assets:install --env=prod --symlink;
env -i php app/console cache:clear --env=prod;
echo "Fixing write permissions ...";
# Fix file permissions
chown -R jenkins:$apache_user .;
chown -R $apache_user:$apache_user app/cache app/logs app/spool web/uploads;
chmod -R 777 web/uploads;
echo "$project_name successful build;";
# Print the success message
echo "Stage server successful updated!";
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment