linux - started work on bunkerized-nginx command

This commit is contained in:
bunkerity
2021-06-22 21:19:12 +02:00
parent b448d91ca8
commit d0366fcc0d
10 changed files with 100 additions and 6 deletions

50
helpers/bunkerized-nginx Normal file
View File

@@ -0,0 +1,50 @@
#!/bin/bash
function do_and_check_cmd() {
if [ "$CHANGE_DIR" != "" ] ; then
cd "$CHANGE_DIR"
fi
output=$(su -s "/bin/bash" -c "$@" nginx 2>&1)
ret="$?"
if [ $ret -ne 0 ] ; then
echo "[!] Error from command : $*"
echo "$output"
exit $ret
fi
echo "$output"
return 0
}
# Check if we are root
if [ $(id -u) -ne 0 ] ; then
echo "[!] Run me as root"
exit 1
fi
# Check if variables.env is present
if [ ! -f "/opt/bunkerized-nginx/variables.env" ] ; then
echo "[!] Missing /opt/bunkerized-nginx/variables.env"
exit 1
fi
# Run generator
echo "[*] Generate configuration files"
do_and_check_cmd /opt/bunkerized-nginx/gen/main.py --settings /opt/bunkerized-nginx/settings.json --templates /opt/bunkerized-nginx/confs --output /etc/nginx --variables /opt/bunkerized-nginx/variables.env
# Run pre-jobs
echo "[*] Run pre-jobs"
do_and_check_cmd /opt/bunkerized-nginx/entrypoint/pre-jobs.sh
# Reload nginx if it's running
if [ -f "/tmp/nginx.pid" ] ; then
echo "[*] Reload nginx"
do_and_check_cmd nginx -s reload
# Otherwise start it
else
echo "[*] Start nginx"
do_and_check_cmd nginx -g 'daemon off;'
fi
# Run post-jobs
echo "[*] Run post-jobs"
do_and_check_cmd /opt/bunkerized-nginx/entrypoint/post-jobs.sh

View File

@@ -130,6 +130,10 @@ do_and_check_cmd cp -r /tmp/bunkerized-nginx/defaults /opt/bunkerized-nginx
echo "[*] Copy settings"
do_and_check_cmd cp /tmp/bunkerized-nginx/settings.json /opt/bunkerized-nginx
# Copy bunkerized-nginx
echo "[*] Copy bunkerized-nginx"
do_and_check_cmd cp /tmp/bunkerized-nginx/helpers/bunkerized-nginx /usr/local/bin
# Create nginx user
if [ "$(grep "nginx:" /etc/passwd)" = "" ] ; then
echo "[*] Add nginx user"
@@ -200,6 +204,10 @@ do_and_check_cmd chmod 770 /opt/bunkerized-nginx/acme-challenge
do_and_check_cmd chmod 750 /opt/bunkerized-nginx/scripts/*
do_and_check_cmd chmod 750 /opt/bunkerized-nginx/entrypoint/*
# Set permissions for /usr/local/bin/bunkerized-nginx
do_and_check_cmd chown root:root /usr/local/bin/bunkerized-nginx
do_and_check_cmd chmod 750 /usr/local/bin/bunkerized-nginx
# Install cron
echo "[*] Add jobs to crontab"
if [ "$OS" = "debian" ] || [ "$OS" = "ubuntu" ] ; then