Compare commits

..

4 Commits

3 changed files with 37 additions and 11 deletions

View File

@@ -11,17 +11,20 @@ RUN apt-get update && apt-get install -y git hugo nginx cron curl bash sudo htop
RUN groupadd -r hugo && useradd -r -g hugo hugo RUN groupadd -r hugo && useradd -r -g hugo hugo
# Hugo Directory Tree # Hugo Directory Tree
RUN mkdir -pv /var/www/hugo && chown -Rv hugo:hugo /var/www/hugo RUN mkdir -pv /var/www/hugo/
# NGINX Directory Tree # NGINX Directory Tree
RUN mkdir -pv /var/www/html/ && chown -Rv hugo:hugo /var/www/html/ RUN mkdir -pv /var/www/html/
# Copy Cron Job to Update Git Repo # Copy Cron Job to Update Git Repo
COPY files/hugo.crontab /etc/cron.d/hugo COPY files/hugo.crontab /etc/cron.d/hugo
COPY files/hugo.cronjob.sh /var/www/hugo/cronjob.sh COPY files/hugo.cronjob.sh /var/www/hugo/cronjob.sh
RUN chmod +x /var/www/hugo/cronjob.sh
RUN crontab /etc/cron.d/hugo RUN crontab /etc/cron.d/hugo
# Hugo User Permissions
RUN chown -Rv hugo:hugo /var/www/
RUN chmod +x /var/www/hugo/cronjob.sh
# Copy Start Script # Copy Start Script
COPY files/main.sh /root/main.sh COPY files/main.sh /root/main.sh
RUN chmod +x /root/main.sh RUN chmod +x /root/main.sh

View File

@@ -2,9 +2,25 @@
cd /var/www/hugo/site cd /var/www/hugo/site
git pull echo "*** Running cronjob @ `date` ***"
# Pull any updates, and if the project is already up to date, exit successfully.
git pull | grep -v "up to date"
status="$?"
echo "* Pull status is '$status'."
if [[ $status != 0 && -e /var/www/html/index.html ]]; then
echo "* Site is already up to date and copied, exiting."
exit 0
fi
# If the project was not already up to date, build the new files for NGINX.
hugo --gc --minify hugo --gc --minify
status="$?"
echo "* Hugo status is '$status'."
if [[ $status == 0 && -e public/index.html ]]; then
echo "* Copying files..."
rm -rfv /var/www/html/*
mv -v public/* /var/www/html/
fi
rm -rfv /var/www/html/* exit 0
cp -rfv public/* /var/www/html/

View File

@@ -21,21 +21,27 @@ if [[ $status != 0 || ! -d /var/www/hugo/site/.git ]]; then
echo "Aborting." echo "Aborting."
exit 1 exit 1
fi fi
echo "* Site exists!"
echo "*** Copying Static Files to NGINX ***" echo "*** Copying Static Files to NGINX ***"
rm -rfv /var/www/html/*
sudo -u hugo /var/www/hugo/cronjob.sh sudo -u hugo /var/www/hugo/cronjob.sh
echo "*** Starting Cron ***" echo "*** Starting Cron ***"
service cron start service cron start
service cron status
if [[ "$PROD" == "Y"* || "$PROD" == "T"* ]]; then if [[ "$PROD" == "Y"* || "$PROD" == "T"* ]]; then
echo "*** Starting Production Server Loop ***" echo "*** Starting Production Server Loop ***"
while true; do while true; do
curl -sS http://localhost:80 > /dev/null || { http_code="`curl -sS http://localhost:80 -o /dev/null -w "%{http_code}"`"
if [[ $http_code != 200 ]]; then
echo "* Prod server not detected, starting..." echo "* Prod server not detected, starting..."
service nginx status
service nginx start service nginx start
} service nginx status
fi
sleep 15 sleep 15
done & done &
@@ -47,19 +53,20 @@ if [[ "$DEV" == "Y"* || "$DEV" == "T"* ]]; then
echo "*** Starting Development Server Loop ***" echo "*** Starting Development Server Loop ***"
while true; do while true; do
curl -sS http://localhost:1380 > /dev/null || { http_code="`curl -sS http://localhost:1380 -o /dev/null -w "%{http_code}"`"
if [[ $http_code != 200 ]]; then
echo "* Dev server not detected, starting..." echo "* Dev server not detected, starting..."
cd /var/www/hugo/site cd /var/www/hugo/site
killall hugo 2>/dev/null killall hugo 2>/dev/null
sudo -u hugo hugo server -D --noBuildLock --bind 0.0.0.0 -p 1380 & sudo -u hugo hugo server -D --noBuildLock --bind 0.0.0.0 -p 1380 &
} fi
sleep 30 sleep 30
done & done &
fi fi
cd cd
echo "*** Finished $0 ***" echo "*** Finished $0 @ `date` ***"
wait -n wait -n