Files
env-docker/Config/HugoExample/files/main.sh

74 lines
1.5 KiB
Bash

#!/usr/bin/env bash
REPO="$1"
echo "REPO=$REPO"
PROD="$2"
typeset -u PROD
echo "PROD=$PROD"
DEV="$3"
typeset -u DEV
echo "DEV=$DEV"
echo "*** Creating Git Repo ***"
sudo -u hugo git clone --recurse-submodules $REPO /var/www/hugo/site
status="$?"
echo "*** Validating Git Repo ***"
if [[ $status != 0 || ! -d /var/www/hugo/site/.git ]]; then
echo "ERROR: Hugo project may not have cloned correctly. status='$status'"
echo "Aborting."
exit 1
fi
echo "* Site exists!"
echo "*** Copying Static Files to NGINX ***"
rm -rfv /var/www/html/*
sudo -u hugo /var/www/hugo/cronjob.sh
echo "*** Starting Cron ***"
service cron start
service cron status
if [[ "$PROD" == "Y"* || "$PROD" == "T"* ]]; then
echo "*** Starting Production Server Loop ***"
while true; do
http_code="`curl -sS http://localhost:80 -o /dev/null -w "%{http_code}"`"
if [[ $http_code != 200 ]]; then
echo "* Prod server not detected, starting..."
service nginx status
service nginx start
service nginx status
fi
sleep 15
done &
cd /var/log/nginx
tail -f access.log error.log &
fi
if [[ "$DEV" == "Y"* || "$DEV" == "T"* ]]; then
echo "*** Starting Development Server Loop ***"
while true; do
http_code="`curl -sS http://localhost:1380 -o /dev/null -w "%{http_code}"`"
if [[ $http_code != 200 ]]; then
echo "* Dev server not detected, starting..."
cd /var/www/hugo/site
killall hugo 2>/dev/null
sudo -u hugo hugo server -D --noBuildLock --bind 0.0.0.0 -p 1380 &
fi
sleep 30
done &
fi
cd
echo "*** Finished $0 @ `date` ***"
wait -n
exit $?