From 19870f154cf1e6f2f46e6a6de5d76c2d6d117d21 Mon Sep 17 00:00:00 2001 From: bunkerity Date: Fri, 24 Mar 2023 17:50:20 +0100 Subject: [PATCH] various fixes for linux and get ui tests exit code from container --- src/linux/scripts/postinstall.sh | 15 +++++++++++++++ src/linux/scripts/start.sh | 23 +++++++++++++++++++++-- src/scheduler/main.py | 4 ++-- tests/ui/tests.sh | 2 +- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/linux/scripts/postinstall.sh b/src/linux/scripts/postinstall.sh index 203db47e..20f848cd 100644 --- a/src/linux/scripts/postinstall.sh +++ b/src/linux/scripts/postinstall.sh @@ -25,6 +25,11 @@ function do_and_check_cmd() { echo "Setting ownership for all necessary directories to nginx user and group..." do_and_check_cmd chown -R nginx:nginx /usr/share/bunkerweb /var/cache/bunkerweb /var/lib/bunkerweb /etc/bunkerweb /var/tmp/bunkerweb +# Stop and disable nginx on boot +echo "Stop and disable nginx on boot..." +do_and_check_cmd systemctl stop bunkerweb +do_and_check_cmd systemctl disable bunkerweb + # Auto start BW service on boot and start it now echo "Enabling and starting bunkerweb service..." do_and_check_cmd systemctl enable bunkerweb @@ -80,4 +85,14 @@ else echo "Old database file not found. Skipping copy..." fi +# Create /var/www/html if needed +if [ ! -d /var/www/html ] ; then + echo "Creating /var/www/html directory ..." + do_and_check_cmd mkdir -p /var/www/html + do_and_check_cmd chmod 750 /var/www/html + do_and_check_cmd chown root:nginx /var/www/html +else + echo "/var/www/html directory already exists, skipping copy..." +fi + echo "Postinstall successful !" \ No newline at end of file diff --git a/src/linux/scripts/start.sh b/src/linux/scripts/start.sh index db986f61..ba1d219e 100644 --- a/src/linux/scripts/start.sh +++ b/src/linux/scripts/start.sh @@ -28,7 +28,6 @@ function stop_nginx() { while [ 1 ] ; do pgrep nginx if [ $? -ne 0 ] ; then - log "SYSTEMCTL" "ℹ️ " "nginx is stopped" break fi log "SYSTEMCTL" "ℹ️ " "Waiting for nginx to stop..." @@ -84,6 +83,9 @@ function start() { # Setup and check /data folder /usr/share/bunkerweb/helpers/data.sh "ENTRYPOINT" + # Stop scheduler if it's running + stop_scheduler + # Stop nginx if it's running stop_nginx @@ -96,11 +98,29 @@ function start() { log "ENTRYPOINT" "❌" "Error while generating config from /var/tmp/bunkerweb/tmp.env" exit 1 fi + + # Start nginx + log "ENTRYPOINT" "ℹ️" "Starting nginx ..." nginx if [ $? -ne 0 ] ; then log "ENTRYPOINT" "❌" "Error while executing nginx" exit 1 fi + count=0 + while [ $count -lt 10 ] ; do + check="$(curl -s -H "Host: healthcheck.bunkerweb.io" http://127.0.0.1:6000/healthz 2>&1)" + if [ $? -eq 0 ] && [ "$check" = "ok" ] ; then + break + fi + count=$(($count + 1)) + sleep 1 + log "ENTRYPOINT" "ℹ️" "Waiting for nginx to start ..." + done + if [ $count -ge 10 ] ; then + log "ENTRYPOINT" "❌" "nginx is not started" + exit 1 + fi + log "ENTRYPOINT" "ℹ️" "nginx started ..." # Create dummy variables.env if [ ! -f /etc/bunkerweb/variables.env ]; then @@ -119,7 +139,6 @@ function start() { fi # Execute scheduler - stop_scheduler log "ENTRYPOINT" "ℹ️ " "Executing scheduler ..." /usr/share/bunkerweb/scheduler/main.py --variables /etc/bunkerweb/variables.env if [ "$?" -ne 0 ] ; then diff --git a/src/scheduler/main.py b/src/scheduler/main.py index 1068ca98..c86e96c9 100644 --- a/src/scheduler/main.py +++ b/src/scheduler/main.py @@ -388,7 +388,7 @@ if __name__ == "__main__": # Reloading the nginx server. proc = subprocess_run( # Reload nginx - ["/etc/init.d/nginx", "reload"], + ["/usr/sbin/nginx", "-s", "reload"], stdin=DEVNULL, stderr=STDOUT, env=deepcopy(env), @@ -446,7 +446,7 @@ if __name__ == "__main__": # Reloading the nginx server. proc = subprocess_run( # Reload nginx - ["/etc/init.d/nginx", "reload"], + ["/usr/sbin/nginx", "-s", "reload"], stdin=DEVNULL, stderr=STDOUT, env=deepcopy(env), diff --git a/tests/ui/tests.sh b/tests/ui/tests.sh index ca9c3951..9c30e586 100755 --- a/tests/ui/tests.sh +++ b/tests/ui/tests.sh @@ -49,7 +49,7 @@ if [ $? -ne 0 ] ; then echo "❌ Build failed" exit 1 fi -docker-compose -f docker-compose.tests.yml up +docker-compose -f docker-compose.tests.yml up --abort-on-container-exit --exit-code-from ui-tests # Exit exit $? \ No newline at end of file