-
-
Save rimusz/fbe61b8834c03092ec26c6a1fb0244ae to your computer and use it in GitHub Desktop.
Bash script to poll Github and rebuild and restart a jekyll site
This file contains 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/sh | |
#This is a simple bash script that will poll github for changes to your repo, | |
#if found pull them down, and then rebuild and restart a Jekyll site running | |
#in Nginx. Note, we cannot use cron to schedule a job every 5 seconds, so we create | |
#a script that executes an infinite loop that sleeps every 5 seconds | |
#We run the script with nohup so it executes as a background process: $nohup ./update-jekyll | |
while true | |
do | |
#move into your git repo where your jekyll site is | |
cd ~/a_folder_created_off_home/the_git_repo_folder_you_cloned_in; | |
git fetch; | |
LOCAL=$(git rev-parse HEAD); | |
REMOTE=$(git rev-parse @{u}); | |
#if our local revision id doesn't match the remote, we will need to pull the changes | |
if [ $LOCAL != $REMOTE ]; then | |
#pull and merge changes | |
git pull origin master; | |
#build the new site, you must install jekyll on the server, alternatively you could put the built _site | |
#repo under version control and just update based off the changes in that folder. Jekyll outputs build into /_site | |
jekyll build; | |
#change back to home directory | |
cd | |
sudo service nginx stop | |
#remove current site directory | |
sudo rm -rf /var/www/site.com/public_html; | |
#copy the newly built site into the directory nginx will serve it from | |
sudo cp -r a_folder_created_off_home/the_git_repo_folder_you_cloned_in/_site /var/www/site.com/public_html | |
sudo service nginx start; | |
fi | |
sleep 5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment