From d6e1186d86a06c09ff0ec6f58aa79db68520ab18 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Sun, 17 Aug 2025 11:01:10 -0700 Subject: [PATCH] Modify script to remove NGINX default files and check HTTP codes rather than curl response status. --- Config/HugoExample/files/main.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Config/HugoExample/files/main.sh b/Config/HugoExample/files/main.sh index 7a78f39..77049d0 100644 --- a/Config/HugoExample/files/main.sh +++ b/Config/HugoExample/files/main.sh @@ -21,21 +21,27 @@ if [[ $status != 0 || ! -d /var/www/hugo/site/.git ]]; then 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 - 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..." + service nginx status service nginx start - } + service nginx status + fi sleep 15 done & @@ -47,19 +53,20 @@ if [[ "$DEV" == "Y"* || "$DEV" == "T"* ]]; then echo "*** Starting Development Server Loop ***" 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..." 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 ***" +echo "*** Finished $0 @ `date` ***" wait -n