Refactor how the project is run, using nginx
instead of hugo server
, a cron job to pull git changes, and a start script to ensure the correct services are started each run and are monitored to stay up.
This commit is contained in:
10
Config/HugoExample/files/hugo.cronjob.sh
Normal file
10
Config/HugoExample/files/hugo.cronjob.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd /var/www/hugo/site
|
||||
|
||||
git pull
|
||||
|
||||
hugo --gc --minify
|
||||
|
||||
rm -rfv /var/www/html/*
|
||||
cp -rfv public/* /var/www/html/
|
1
Config/HugoExample/files/hugo.crontab
Normal file
1
Config/HugoExample/files/hugo.crontab
Normal file
@@ -0,0 +1 @@
|
||||
* * * * * hugo /var/www/hugo/cronjob.sh
|
58
Config/HugoExample/files/main.sh
Normal file
58
Config/HugoExample/files/main.sh
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/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
|
||||
|
||||
echo "*** Copying Static Files to NGINX ***"
|
||||
sudo -u hugo /var/www/hugo/cronjob.sh
|
||||
|
||||
echo "*** Starting Cron ***"
|
||||
service cron start
|
||||
|
||||
if [[ "$PROD" == "Y"* || "$PROD" == "T"* ]]; then
|
||||
echo "*** Starting Production Server Loop ***"
|
||||
|
||||
while true; do
|
||||
curl -sS http://localhost:80 > /dev/null || {
|
||||
echo "* Prod server not detected, starting..."
|
||||
service nginx start
|
||||
}
|
||||
sleep 30
|
||||
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
|
||||
curl -sS http://localhost:1380 > /dev/null || {
|
||||
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 &
|
||||
}
|
||||
sleep 10
|
||||
done &
|
||||
fi
|
||||
|
||||
cd
|
||||
|
||||
echo "*** Finished $0 ***"
|
||||
|
||||
wait -n
|
||||
|
||||
exit $?
|
Reference in New Issue
Block a user