hugo live server as systemd service (template)

uses environment file to bring up live reload site
with uci-doc and uci-shortcode themes nested
master
David Kebler 2021-01-15 12:53:53 -08:00
parent e28d770727
commit 90868a74b0
4 changed files with 69 additions and 0 deletions

36
run Executable file
View File

@ -0,0 +1,36 @@
#!/bin/bash
[[ ! $1 ]] && echo must specify a site name to run && exit
RDIR=$(cd $(dirname $(readlink -f "$0")) >/dev/null 2>&1 ; pwd -P)
# source any environment for particular site
shopt -s extglob
ENV_FILE=$(ls $RDIR/sites/${1}* 2> /dev/null | grep -v '.off$\|.example$\|.tmpl$\|.template$')
if [[ $ENV_FILE ]]; then
source $ENV_FILE
echo '***********************'
echo "sourcing $ENV_FILE environment file for hugo run"
cat $ENV_FILE
echo '************************'
else
echo warning no environoment file set for $1 in $RDIR/sites
fi
DATA_DIR=${DATA_DIR:-${HOME}/.local/hugo}
HUGO=${HUGO:-$(command -v hugo)}
PORT=${PORT:-8096}
echo site files in $DATA_DIR/$1 listening on port $PORT
# [[ $(netstat -tulpn | grep LISTEN | grep 0.0.0.0:$PORT) ]] && echo tcp port $PORT is busy can not start hugo server && exit
CMD="$HUGO server
$([[ $BASE_URL = "https://"* ]] && echo " --liveReloadPort 443")
--bind 0.0.0.0
--themesDir $RDIR/themes
--source $DATA_DIR/$1
--port $PORT
--appendPort=$([[ $REVERSE_PROXY = true ]] && echo false || echo true)
--baseURL ${BASE_URL:-localhost}
"
# --config /mnt/data/$SRC/config.yaml
# --logFile /opt/docs-kebler-net/server.log
echo '*********** running command **********'
echo $CMD
echo '**************************************'
eval $CMD

9
sites/example.off Normal file
View File

@ -0,0 +1,9 @@
# defaults shown. uncomment and edit for your site
#PORT="8096"
# parent directory of where site files should be stored.
#DATA_DIR="${HOME}/.local/hugo"
# if using reverse proxy port will not be appended to base url
#REVERSE_PROXY=false
# be sure to use https if site is being served such, e.g. using Caddy.
# example: BASE_URL="https://site.domain.net"
#BASE_URL="localhost"

18
systemd/hugo@.service Normal file
View File

@ -0,0 +1,18 @@
[Unit]
Description=Live Hugo Server for a Site
After=network-online.target
Requires=opt.mount
After=opt.mount
Requires=mnt-data.mount
After=mnt-data.mount
[Service]
# User=sysadmin
Group=sysadmin
Type=simple
ExecStart=/bin/bash /opt/hugo/run %i
# Restart=on-failure
# RestartSec=3
[Install]
WantedBy=default.target

6
systemd/install Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
# install template system space
DIR="$(dirname "$(readlink -f "$0")")"
sudo \cp -f $DIR/hugo@.service /etc/systemd/system
echo "hugo service template copied to systemd"
cat /etc/systemd/system/hugo@.service