mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
feat: add BunkerWeb Scheduler service and update backup scripts for scheduler environment
This commit is contained in:
parent
d614dad821
commit
5236e3e329
12 changed files with 381 additions and 235 deletions
19
src/linux/bunkerweb-scheduler.service
Normal file
19
src/linux/bunkerweb-scheduler.service
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
[Unit]
|
||||
Description=BunkerWeb Scheduler service
|
||||
Documentation=https://docs.bunkerweb.io
|
||||
After=bunkerweb.service
|
||||
|
||||
[Service]
|
||||
Restart=no
|
||||
User=root
|
||||
PIDFile=/var/run/bunkerweb/scheduler.pid
|
||||
ExecStart=/usr/share/bunkerweb/scripts/bunkerweb-scheduler.sh start
|
||||
ExecStop=/usr/share/bunkerweb/scripts/bunkerweb-scheduler.sh stop
|
||||
ExecReload=/usr/share/bunkerweb/scripts/bunkerweb-scheduler.sh reload
|
||||
Type=simple
|
||||
StandardOutput=journal+console
|
||||
StandardError=journal+console
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Alias=bunkerweb-scheduler.service
|
||||
|
|
@ -10,4 +10,4 @@
|
|||
--before-install /usr/share/bunkerweb/scripts/beforeInstall.sh
|
||||
--after-install /usr/share/bunkerweb/scripts/postinstall.sh
|
||||
--after-remove /usr/share/bunkerweb/scripts/afterRemoveDEB.sh
|
||||
/usr/share/bunkerweb/=/usr/share/bunkerweb/ /usr/bin/bwcli=/usr/bin/bwcli /etc/bunkerweb/=/etc/bunkerweb /var/tmp/bunkerweb/=/var/tmp/bunkerweb /var/run/bunkerweb/=/var/run/bunkerweb /var/log/bunkerweb/=/var/log/bunkerweb /var/cache/bunkerweb/=/var/cache/bunkerweb /lib/systemd/system/bunkerweb.service=/lib/systemd/system/bunkerweb.service /lib/systemd/system/bunkerweb-ui.service=/lib/systemd/system/bunkerweb-ui.service /var/lib/bunkerweb/=/var/lib/bunkerweb /etc/logrotate.d/bunkerweb=/etc/logrotate.d/bunkerweb
|
||||
/usr/share/bunkerweb/=/usr/share/bunkerweb/ /usr/bin/bwcli=/usr/bin/bwcli /etc/bunkerweb/=/etc/bunkerweb /var/tmp/bunkerweb/=/var/tmp/bunkerweb /var/run/bunkerweb/=/var/run/bunkerweb /var/log/bunkerweb/=/var/log/bunkerweb /var/cache/bunkerweb/=/var/cache/bunkerweb /lib/systemd/system/bunkerweb.service=/lib/systemd/system/bunkerweb.service /lib/systemd/system/bunkerweb-ui.service=/lib/systemd/system/bunkerweb-ui.service /lib/systemd/system/bunkerweb-scheduler.service=/lib/systemd/system/bunkerweb-scheduler.service /var/lib/bunkerweb/=/var/lib/bunkerweb /etc/logrotate.d/bunkerweb=/etc/logrotate.d/bunkerweb
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@
|
|||
--before-install /usr/share/bunkerweb/scripts/beforeInstall.sh
|
||||
--after-install /usr/share/bunkerweb/scripts/postinstall.sh
|
||||
--after-remove /usr/share/bunkerweb/scripts/afterRemoveRPM.sh
|
||||
/usr/share/bunkerweb/=/usr/share/bunkerweb/ /usr/bin/bwcli=/usr/bin/bwcli /etc/bunkerweb/=/etc/bunkerweb /var/tmp/bunkerweb/=/var/tmp/bunkerweb /var/run/bunkerweb/=/var/run/bunkerweb /var/log/bunkerweb/=/var/log/bunkerweb /var/cache/bunkerweb/=/var/cache/bunkerweb /lib/systemd/system/bunkerweb.service=/lib/systemd/system/bunkerweb.service /lib/systemd/system/bunkerweb-ui.service=/lib/systemd/system/bunkerweb-ui.service /var/lib/bunkerweb/=/var/lib/bunkerweb /etc/logrotate.d/bunkerweb=/etc/logrotate.d/bunkerweb
|
||||
/usr/share/bunkerweb/=/usr/share/bunkerweb/ /usr/bin/bwcli=/usr/bin/bwcli /etc/bunkerweb/=/etc/bunkerweb /var/tmp/bunkerweb/=/var/tmp/bunkerweb /var/run/bunkerweb/=/var/run/bunkerweb /var/log/bunkerweb/=/var/log/bunkerweb /var/cache/bunkerweb/=/var/cache/bunkerweb /lib/systemd/system/bunkerweb.service=/lib/systemd/system/bunkerweb.service /lib/systemd/system/bunkerweb-ui.service=/lib/systemd/system/bunkerweb-ui.service /lib/systemd/system/bunkerweb-scheduler.service=/lib/systemd/system/bunkerweb-scheduler.service /var/lib/bunkerweb/=/var/lib/bunkerweb /etc/logrotate.d/bunkerweb=/etc/logrotate.d/bunkerweb
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@
|
|||
--before-install /usr/share/bunkerweb/scripts/beforeInstall.sh
|
||||
--after-install /usr/share/bunkerweb/scripts/postinstall.sh
|
||||
--after-remove /usr/share/bunkerweb/scripts/afterRemoveRPM.sh
|
||||
/usr/share/bunkerweb/=/usr/share/bunkerweb/ /usr/bin/bwcli=/usr/bin/bwcli /etc/bunkerweb/=/etc/bunkerweb /var/tmp/bunkerweb/=/var/tmp/bunkerweb /var/run/bunkerweb/=/var/run/bunkerweb /var/log/bunkerweb/=/var/log/bunkerweb /var/cache/bunkerweb/=/var/cache/bunkerweb /lib/systemd/system/bunkerweb.service=/lib/systemd/system/bunkerweb.service /lib/systemd/system/bunkerweb-ui.service=/lib/systemd/system/bunkerweb-ui.service /var/lib/bunkerweb/=/var/lib/bunkerweb /etc/logrotate.d/bunkerweb=/etc/logrotate.d/bunkerweb
|
||||
/usr/share/bunkerweb/=/usr/share/bunkerweb/ /usr/bin/bwcli=/usr/bin/bwcli /etc/bunkerweb/=/etc/bunkerweb /var/tmp/bunkerweb/=/var/tmp/bunkerweb /var/run/bunkerweb/=/var/run/bunkerweb /var/log/bunkerweb/=/var/log/bunkerweb /var/cache/bunkerweb/=/var/cache/bunkerweb /lib/systemd/system/bunkerweb.service=/lib/systemd/system/bunkerweb.service /lib/systemd/system/bunkerweb-ui.service=/lib/systemd/system/bunkerweb-ui.service /lib/systemd/system/bunkerweb-scheduler.service=/lib/systemd/system/bunkerweb-scheduler.service /var/lib/bunkerweb/=/var/lib/bunkerweb /etc/logrotate.d/bunkerweb=/etc/logrotate.d/bunkerweb
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@
|
|||
--before-install /usr/share/bunkerweb/scripts/beforeInstall.sh
|
||||
--after-install /usr/share/bunkerweb/scripts/postinstall.sh
|
||||
--after-remove /usr/share/bunkerweb/scripts/afterRemoveRPM.sh
|
||||
/usr/share/bunkerweb/=/usr/share/bunkerweb/ /usr/bin/bwcli=/usr/bin/bwcli /etc/bunkerweb/=/etc/bunkerweb /var/tmp/bunkerweb/=/var/tmp/bunkerweb /var/run/bunkerweb/=/var/run/bunkerweb /var/log/bunkerweb/=/var/log/bunkerweb /var/cache/bunkerweb/=/var/cache/bunkerweb /lib/systemd/system/bunkerweb.service=/lib/systemd/system/bunkerweb.service /lib/systemd/system/bunkerweb-ui.service=/lib/systemd/system/bunkerweb-ui.service /var/lib/bunkerweb/=/var/lib/bunkerweb /etc/logrotate.d/bunkerweb=/etc/logrotate.d/bunkerweb
|
||||
/usr/share/bunkerweb/=/usr/share/bunkerweb/ /usr/bin/bwcli=/usr/bin/bwcli /etc/bunkerweb/=/etc/bunkerweb /var/tmp/bunkerweb/=/var/tmp/bunkerweb /var/run/bunkerweb/=/var/run/bunkerweb /var/log/bunkerweb/=/var/log/bunkerweb /var/cache/bunkerweb/=/var/cache/bunkerweb /lib/systemd/system/bunkerweb.service=/lib/systemd/system/bunkerweb.service /lib/systemd/system/bunkerweb-ui.service=/lib/systemd/system/bunkerweb-ui.service /lib/systemd/system/bunkerweb-scheduler.service=/lib/systemd/system/bunkerweb-scheduler.service /var/lib/bunkerweb/=/var/lib/bunkerweb /etc/logrotate.d/bunkerweb=/etc/logrotate.d/bunkerweb
|
||||
|
|
|
|||
|
|
@ -11,4 +11,4 @@
|
|||
--after-install /usr/share/bunkerweb/scripts/postinstall.sh
|
||||
--after-remove /usr/share/bunkerweb/scripts/afterRemoveDEB.sh
|
||||
--deb-no-default-config-files
|
||||
/usr/share/bunkerweb/=/usr/share/bunkerweb/ /usr/bin/bwcli=/usr/bin/bwcli /etc/bunkerweb/=/etc/bunkerweb /var/tmp/bunkerweb/=/var/tmp/bunkerweb /var/run/bunkerweb/=/var/run/bunkerweb /var/log/bunkerweb/=/var/log/bunkerweb /var/cache/bunkerweb/=/var/cache/bunkerweb /lib/systemd/system/bunkerweb.service=/lib/systemd/system/bunkerweb.service /lib/systemd/system/bunkerweb-ui.service=/lib/systemd/system/bunkerweb-ui.service /var/lib/bunkerweb/=/var/lib/bunkerweb /etc/logrotate.d/bunkerweb=/etc/logrotate.d/bunkerweb
|
||||
/usr/share/bunkerweb/=/usr/share/bunkerweb/ /usr/bin/bwcli=/usr/bin/bwcli /etc/bunkerweb/=/etc/bunkerweb /var/tmp/bunkerweb/=/var/tmp/bunkerweb /var/run/bunkerweb/=/var/run/bunkerweb /var/log/bunkerweb/=/var/log/bunkerweb /var/cache/bunkerweb/=/var/cache/bunkerweb /lib/systemd/system/bunkerweb.service=/lib/systemd/system/bunkerweb.service /lib/systemd/system/bunkerweb-ui.service=/lib/systemd/system/bunkerweb-ui.service /lib/systemd/system/bunkerweb-scheduler.service=/lib/systemd/system/bunkerweb-scheduler.service /var/lib/bunkerweb/=/var/lib/bunkerweb /etc/logrotate.d/bunkerweb=/etc/logrotate.d/bunkerweb
|
||||
|
|
|
|||
|
|
@ -11,4 +11,4 @@
|
|||
--after-install /usr/share/bunkerweb/scripts/postinstall.sh
|
||||
--after-remove /usr/share/bunkerweb/scripts/afterRemoveDEB.sh
|
||||
--deb-no-default-config-files
|
||||
/usr/share/bunkerweb/=/usr/share/bunkerweb/ /usr/bin/bwcli=/usr/bin/bwcli /etc/bunkerweb/=/etc/bunkerweb /var/tmp/bunkerweb/=/var/tmp/bunkerweb /var/run/bunkerweb/=/var/run/bunkerweb /var/log/bunkerweb/=/var/log/bunkerweb /var/cache/bunkerweb/=/var/cache/bunkerweb /lib/systemd/system/bunkerweb.service=/lib/systemd/system/bunkerweb.service /lib/systemd/system/bunkerweb-ui.service=/lib/systemd/system/bunkerweb-ui.service /var/lib/bunkerweb/=/var/lib/bunkerweb /etc/logrotate.d/bunkerweb=/etc/logrotate.d/bunkerweb
|
||||
/usr/share/bunkerweb/=/usr/share/bunkerweb/ /usr/bin/bwcli=/usr/bin/bwcli /etc/bunkerweb/=/etc/bunkerweb /var/tmp/bunkerweb/=/var/tmp/bunkerweb /var/run/bunkerweb/=/var/run/bunkerweb /var/log/bunkerweb/=/var/log/bunkerweb /var/cache/bunkerweb/=/var/cache/bunkerweb /lib/systemd/system/bunkerweb.service=/lib/systemd/system/bunkerweb.service /lib/systemd/system/bunkerweb-ui.service=/lib/systemd/system/bunkerweb-ui.service /lib/systemd/system/bunkerweb-scheduler.service=/lib/systemd/system/bunkerweb-scheduler.service /var/lib/bunkerweb/=/var/lib/bunkerweb /etc/logrotate.d/bunkerweb=/etc/logrotate.d/bunkerweb
|
||||
|
|
|
|||
|
|
@ -141,9 +141,12 @@ case "$1" in
|
|||
# Backup important files during upgrade
|
||||
remove_path "/var/tmp/variables.env" "temporary environment variables"
|
||||
remove_path "/var/tmp/ui.env" "UI environment variables"
|
||||
remove_path "/var/tmp/scheduler.env" "Scheduler environment variables"
|
||||
remove_path "/var/tmp/db.sqlite3" "database"
|
||||
do_and_check_cmd cp -f /etc/bunkerweb/variables.env /var/tmp/variables.env
|
||||
do_and_check_cmd cp -f /etc/bunkerweb/ui.env /var/tmp/ui.env
|
||||
do_and_check_cmd cp -f /etc/bunkerweb/scheduler.env /var/tmp/scheduler.env
|
||||
do_and_check_cmd cp -f /var/lib/bunkerweb/db.sqlite3 /var/tmp/db.sqlite3
|
||||
do_and_check_cmd touch /var/tmp/bunkerweb_upgrade
|
||||
;;
|
||||
esac
|
||||
|
|
|
|||
|
|
@ -140,10 +140,13 @@ case "$1" in
|
|||
# Backup important files during upgrade
|
||||
remove_path "/var/tmp/variables.env" "temporary environment variables"
|
||||
remove_path "/var/tmp/ui.env" "UI environment variables"
|
||||
remove_path "/var/tmp/scheduler.env" "Scheduler environment variables"
|
||||
remove_path "/var/tmp/db.sqlite3" "database"
|
||||
do_and_check_cmd cp -f /etc/bunkerweb/variables.env /var/tmp/variables.env
|
||||
do_and_check_cmd cp -f /etc/bunkerweb/ui.env /var/tmp/ui.env
|
||||
do_and_check_cmd cp -f /etc/bunkerweb/scheduler.env /var/tmp/scheduler.env
|
||||
do_and_check_cmd cp -f /var/lib/bunkerweb/db.sqlite3 /var/tmp/db.sqlite3
|
||||
do_and_check_cmd touch /var/tmp/bunkerweb_upgrade
|
||||
;;
|
||||
*)
|
||||
echo "❌ Invalid argument"
|
||||
|
|
|
|||
135
src/linux/scripts/bunkerweb-scheduler.sh
Normal file
135
src/linux/scripts/bunkerweb-scheduler.sh
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Source the utils helper script
|
||||
# shellcheck disable=SC1091
|
||||
source /usr/share/bunkerweb/helpers/utils.sh
|
||||
|
||||
# Set the PYTHONPATH
|
||||
export PYTHONPATH=/usr/share/bunkerweb/deps/python
|
||||
|
||||
# Create the scheduler.env file if it doesn't exist
|
||||
if [ ! -f /etc/bunkerweb/scheduler.env ]; then
|
||||
{
|
||||
echo "LOG_LEVEL=info"
|
||||
echo "LOG_TO_FILE=yes"
|
||||
echo "HEALTHCHECK_INTERVAL=30 # in seconds"
|
||||
echo "RELOAD_MIN_TIMEOUT=5 # in seconds (the minimum is calculated by the formula and whichever is greater: RELOAD_MIN_TIMEOUT or count(SERVERS) * 2))"
|
||||
} > /etc/bunkerweb/scheduler.env
|
||||
chown root:nginx /etc/bunkerweb/scheduler.env
|
||||
chmod 660 /etc/bunkerweb/scheduler.env
|
||||
fi
|
||||
|
||||
# Display usage information
|
||||
function display_help() {
|
||||
echo "Usage: $(basename "$0") [start|stop|reload]"
|
||||
echo "Options:"
|
||||
echo " start: Create configurations and run necessary jobs for the bunkerweb service."
|
||||
echo " stop: Stop the bunkerweb scheduler service."
|
||||
echo " reload: Reload the bunkerweb scheduler service."
|
||||
}
|
||||
|
||||
# Start the bunkerweb service
|
||||
function start() {
|
||||
log "SYSTEMCTL" "ℹ️" "Starting BunkerWeb Scheduler service ..."
|
||||
|
||||
# Check if the scheduler is already running
|
||||
stop
|
||||
|
||||
CUSTOM_LOG_LEVEL="$(grep "^LOG_LEVEL=" /etc/bunkerweb/scheduler.env | cut -d '=' -f 2)"
|
||||
export CUSTOM_LOG_LEVEL
|
||||
|
||||
SCHEDULER_LOG_TO_FILE="$(grep "^SCHEDULER_LOG_TO_FILE=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
if [ -z "$SCHEDULER_LOG_TO_FILE" ] ; then
|
||||
SCHEDULER_LOG_TO_FILE="$(grep "^LOG_TO_FILE=" /etc/bunkerweb/scheduler.env | cut -d '=' -f 2)"
|
||||
|
||||
if [ -z "$SCHEDULER_LOG_TO_FILE" ] ; then
|
||||
SCHEDULER_LOG_TO_FILE="yes"
|
||||
fi
|
||||
fi
|
||||
export SCHEDULER_LOG_TO_FILE
|
||||
|
||||
# Execute scheduler
|
||||
log "SYSTEMCTL" "ℹ️ " "Executing scheduler ..."
|
||||
sudo -E -u nginx -g nginx /bin/bash -c "PYTHONPATH=$PYTHONPATH /usr/share/bunkerweb/scheduler/main.py --variables /etc/bunkerweb/variables.env"
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Scheduler failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "SYSTEMCTL" "ℹ️ " "Scheduler stopped"
|
||||
}
|
||||
|
||||
function stop() {
|
||||
log "SYSTEMCTL" "ℹ️" "Stopping BunkerWeb Scheduler service ..."
|
||||
|
||||
if [ -f "/var/run/bunkerweb/scheduler.pid" ] ; then
|
||||
scheduler_pid=$(cat "/var/run/bunkerweb/scheduler.pid")
|
||||
log "SYSTEMCTL" "ℹ️ " "Stopping scheduler..."
|
||||
kill -SIGINT "$scheduler_pid"
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Error while sending stop signal to scheduler"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log "SYSTEMCTL" "ℹ️ " "Scheduler already stopped"
|
||||
return 0
|
||||
fi
|
||||
count=0
|
||||
while [ -f "/var/run/bunkerweb/scheduler.pid" ] ; do
|
||||
sleep 1
|
||||
count=$((count + 1))
|
||||
if [ $count -ge 10 ] ; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ $count -ge 10 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Timeout while waiting scheduler to stop"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "SYSTEMCTL" "ℹ️ " "BunkerWeb Scheduler service is stopped"
|
||||
}
|
||||
|
||||
function reload()
|
||||
{
|
||||
|
||||
log "SYSTEMCTL" "ℹ️" "Reloading BunkerWeb Scheduler service ..."
|
||||
|
||||
PID_FILE_PATH="/var/run/bunkerweb/scheduler.pid"
|
||||
if [ -f "$PID_FILE_PATH" ];
|
||||
then
|
||||
result=$(cat "$PID_FILE_PATH")
|
||||
# Send signal to scheduler to reload
|
||||
log "SYSTEMCTL" "ℹ️" "Sending reload signal to scheduler ..."
|
||||
kill -SIGHUP "$result"
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Your command exited with non-zero status $result"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log "SYSTEMCTL" "❌" "Scheduler is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "SYSTEMCTL" "ℹ️" "BunkerWeb Scheduler service reloaded ..."
|
||||
}
|
||||
|
||||
# List of different args
|
||||
case $1 in
|
||||
"start")
|
||||
start
|
||||
;;
|
||||
"stop")
|
||||
stop
|
||||
;;
|
||||
"reload")
|
||||
reload
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option!"
|
||||
echo "List of options availables:"
|
||||
display_help
|
||||
esac
|
||||
|
|
@ -36,7 +36,7 @@ if [ -f /var/tmp/variables.env ]; then
|
|||
echo "Removing old environment files..."
|
||||
do_and_check_cmd rm -f /var/tmp/variables.env
|
||||
do_and_check_cmd chown root:nginx /etc/bunkerweb/variables.env
|
||||
do_and_check_cmd chmod 740 /etc/bunkerweb/variables.env
|
||||
do_and_check_cmd chmod 660 /etc/bunkerweb/variables.env
|
||||
else
|
||||
echo "Old environment file not found. Skipping copy..."
|
||||
fi
|
||||
|
|
@ -45,6 +45,7 @@ fi
|
|||
# Check if old environment file exists
|
||||
if [ -f /var/tmp/ui.env ]; then
|
||||
echo "Old ui environment file found!"
|
||||
touch /var/tmp/bunkerweb_upgrade
|
||||
echo "Copying old line from ui environment file to new one..."
|
||||
while read -r line; do
|
||||
echo "$line" >> /etc/bunkerweb/ui.env
|
||||
|
|
@ -53,39 +54,25 @@ if [ -f /var/tmp/ui.env ]; then
|
|||
echo "Removing old environment files..."
|
||||
do_and_check_cmd rm -f /var/tmp/ui.env
|
||||
do_and_check_cmd chown root:nginx /etc/bunkerweb/ui.env
|
||||
do_and_check_cmd chmod 740 /etc/bunkerweb/ui.env
|
||||
do_and_check_cmd chmod 660 /etc/bunkerweb/ui.env
|
||||
else
|
||||
echo "Old ui environment file not found. Skipping copy..."
|
||||
fi
|
||||
|
||||
# Check if old db.sqlite3 file exists
|
||||
if [ -f /var/tmp/bunkerweb/db.sqlite3 ]; then
|
||||
if [ -f /var/tmp/db.sqlite3 ]; then
|
||||
echo "Old db.sqlite3 file found!"
|
||||
do_and_check_cmd cp /var/tmp/bunkerweb/db.sqlite3 /var/lib/bunkerweb/db.sqlite3
|
||||
do_and_check_cmd rm -f /var/lib/bunkerweb/db.sqlite3
|
||||
touch /var/tmp/bunkerweb_upgrade
|
||||
do_and_check_cmd cp /var/tmp/db.sqlite3 /var/lib/bunkerweb/db.sqlite3
|
||||
# Remove old db.sqlite3 file
|
||||
echo "Copying old db.sqlite3 file to new one..."
|
||||
do_and_check_cmd rm -f /var/tmp/db.sqlite3
|
||||
do_and_check_cmd chown root:nginx /var/lib/bunkerweb/db.sqlite3
|
||||
do_and_check_cmd chmod 760 /var/lib/bunkerweb/db.sqlite3
|
||||
do_and_check_cmd chmod 660 /var/lib/bunkerweb/db.sqlite3
|
||||
else
|
||||
echo "Old database file not found. Skipping copy..."
|
||||
fi
|
||||
|
||||
# Create wizard config
|
||||
if [ "$UI_WIZARD" != "no" ] ; then
|
||||
echo -ne 'DNS_RESOLVERS=9.9.9.9 8.8.8.8 8.8.4.4\nHTTP_PORT=80\nHTTPS_PORT=443\nAPI_LISTEN_IP=127.0.0.1\nMULTISITE=yes\nUI_HOST=http://127.0.0.1:7000\nSERVER_NAME=\n' > /etc/bunkerweb/variables.env
|
||||
do_and_check_cmd chown nginx:nginx /etc/bunkerweb/variables.env
|
||||
do_and_check_cmd chmod 660 /etc/bunkerweb/variables.env
|
||||
touch /etc/bunkerweb/ui.env
|
||||
do_and_check_cmd chown nginx:nginx /etc/bunkerweb/ui.env
|
||||
do_and_check_cmd chmod 660 /etc/bunkerweb/ui.env
|
||||
do_and_check_cmd systemctl enable bunkerweb-ui
|
||||
do_and_check_cmd systemctl start bunkerweb-ui
|
||||
echo "🧙 The setup wizard has been activated automatically."
|
||||
echo "Please complete the initial configuration at: https://your-ip-address-or-fqdn/setup"
|
||||
echo ""
|
||||
echo "Note: Make sure that your firewall settings allow access to this URL."
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Create /var/www/html if needed
|
||||
if [ ! -d /var/www/html ] ; then
|
||||
echo "Creating /var/www/html directory ..."
|
||||
|
|
@ -96,17 +83,62 @@ else
|
|||
echo "/var/www/html directory already exists, skipping copy..."
|
||||
fi
|
||||
|
||||
# Stop and disable nginx on boot
|
||||
echo "Stop and disable nginx on boot..."
|
||||
do_and_check_cmd systemctl stop nginx
|
||||
do_and_check_cmd systemctl disable nginx
|
||||
if [ -f /var/tmp/bunkerweb_upgrade ]; then
|
||||
# Reload bunkerweb service
|
||||
echo "Reloading bunkerweb service..."
|
||||
do_and_check_cmd systemctl reload bunkerweb
|
||||
else
|
||||
# Stop and disable nginx on boot
|
||||
echo "Stop and disable nginx on boot..."
|
||||
do_and_check_cmd systemctl stop nginx
|
||||
do_and_check_cmd systemctl disable nginx
|
||||
|
||||
# Auto start BW service on boot and start it now
|
||||
echo "Enabling and starting bunkerweb service..."
|
||||
do_and_check_cmd systemctl enable bunkerweb
|
||||
do_and_check_cmd systemctl start bunkerweb
|
||||
# Auto start BW service on boot and start it now
|
||||
echo "Enabling and starting bunkerweb service..."
|
||||
do_and_check_cmd systemctl enable bunkerweb
|
||||
do_and_check_cmd systemctl start bunkerweb
|
||||
fi
|
||||
|
||||
# Create scheduler if necessary
|
||||
if [ "$SERVICE_SCHEDULER" != "no" ] ; then
|
||||
if [ -f /var/tmp/bunkerweb_upgrade ] && systemctl is-active --quiet bunkerweb-scheduler; then
|
||||
# Reload bunkerweb-scheduler service
|
||||
echo "Reloading bunkerweb-scheduler service..."
|
||||
do_and_check_cmd systemctl restart bunkerweb-scheduler
|
||||
else
|
||||
# Auto start BW Scheduler service on boot and start it now
|
||||
echo "Enabling and starting bunkerweb service..."
|
||||
do_and_check_cmd systemctl enable bunkerweb-scheduler
|
||||
do_and_check_cmd systemctl start bunkerweb-scheduler
|
||||
fi
|
||||
|
||||
if [ -f /var/tmp/bunkerweb_upgrade ]; then
|
||||
# Reload bunkerweb-ui service if running
|
||||
if systemctl is-active --quiet bunkerweb-ui; then
|
||||
echo "Reloading bunkerweb-ui service..."
|
||||
do_and_check_cmd systemctl restart bunkerweb-ui
|
||||
fi
|
||||
elif [ "$UI_WIZARD" != "no" ] ; then
|
||||
touch /etc/bunkerweb/ui.env
|
||||
do_and_check_cmd chown root:nginx /etc/bunkerweb/ui.env
|
||||
do_and_check_cmd chmod 660 /etc/bunkerweb/ui.env
|
||||
do_and_check_cmd systemctl enable bunkerweb-ui
|
||||
do_and_check_cmd systemctl start bunkerweb-ui
|
||||
echo "🧙 The setup wizard has been activated automatically."
|
||||
echo "Please complete the initial configuration at: https://your-ip-address-or-fqdn/setup"
|
||||
echo ""
|
||||
echo "Note: Make sure that your firewall settings allow access to this URL."
|
||||
echo ""
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f /var/tmp/bunkerweb_upgrade ]; then
|
||||
rm -f /var/tmp/bunkerweb_upgrade
|
||||
echo "BunkerWeb has been successfully upgraded! 🎉"
|
||||
else
|
||||
echo "BunkerWeb has been successfully installed! 🎉"
|
||||
fi
|
||||
|
||||
echo "BunkerWeb has been successfully installed! 🎉"
|
||||
echo ""
|
||||
echo "For more information on BunkerWeb, visit:"
|
||||
echo " * Official website: https://www.bunkerweb.io"
|
||||
|
|
|
|||
|
|
@ -5,18 +5,153 @@
|
|||
source /usr/share/bunkerweb/helpers/utils.sh
|
||||
|
||||
# Set the PYTHONPATH
|
||||
export PYTHONPATH=/usr/share/bunkerweb/deps/python/
|
||||
export PYTHONPATH=/usr/share/bunkerweb/deps/python
|
||||
|
||||
# Display usage information
|
||||
function display_help() {
|
||||
echo "Usage: $(basename "$0") [start|stop|reload]"
|
||||
echo "Options:"
|
||||
echo " start: Create configurations and run necessary jobs for the bunkerweb service."
|
||||
echo " start: Create configurations and start the bunkerweb service."
|
||||
echo " stop: Stop the bunkerweb service."
|
||||
echo " reload: Reload the bunkerweb service."
|
||||
}
|
||||
|
||||
function stop_nginx() {
|
||||
# Start the bunkerweb service
|
||||
function start() {
|
||||
|
||||
# Set the PYTHONPATH
|
||||
export PYTHONPATH=/usr/share/bunkerweb/deps/python
|
||||
|
||||
log "SYSTEMCTL" "ℹ️" "Starting BunkerWeb service ..."
|
||||
|
||||
setcap 'CAP_NET_BIND_SERVICE=+eip' /usr/sbin/nginx
|
||||
chown -R nginx:nginx /etc/nginx
|
||||
|
||||
# Create dummy variables.env
|
||||
if [ ! -f /etc/bunkerweb/variables.env ]; then
|
||||
{
|
||||
echo "# remove IS_LOADING=yes when your config is ready"
|
||||
echo "IS_LOADING=yes"
|
||||
echo "SERVER_NAME="
|
||||
echo "DNS_RESOLVERS=9.9.9.9 149.112.112.112 8.8.8.8 8.8.4.4" # Quad9, Google
|
||||
echo "HTTP_PORT=80"
|
||||
echo "HTTPS_PORT=443"
|
||||
echo "API_LISTEN_IP=127.0.0.1"
|
||||
} > /etc/bunkerweb/variables.env
|
||||
chown root:nginx /etc/bunkerweb/variables.env
|
||||
chmod 660 /etc/bunkerweb/variables.env
|
||||
log "SYSTEMCTL" "ℹ️" "Created dummy variables.env file"
|
||||
fi
|
||||
|
||||
# Create PID folder
|
||||
if [ ! -f /var/run/bunkerweb ] ; then
|
||||
mkdir -p /var/run/bunkerweb
|
||||
chown nginx:nginx /var/run/bunkerweb
|
||||
fi
|
||||
|
||||
# Create TMP folder
|
||||
if [ ! -f /var/tmp/bunkerweb ] ; then
|
||||
mkdir -p /var/tmp/bunkerweb
|
||||
chown nginx:nginx /var/tmp/bunkerweb
|
||||
fi
|
||||
|
||||
# Create LOG folder
|
||||
if [ ! -f /var/log/bunkerweb ] ; then
|
||||
mkdir -p /var/log/bunkerweb
|
||||
chown nginx:nginx /var/log/bunkerweb
|
||||
fi
|
||||
|
||||
# Stop nginx if it's running
|
||||
stop
|
||||
|
||||
# Generate temp conf for nginx
|
||||
# Default values
|
||||
declare -A defaults=(
|
||||
[DNS_RESOLVERS]="9.9.9.9 149.112.112.112 8.8.8.8 8.8.4.4" # Quad9, Google
|
||||
[API_LISTEN_IP]="127.0.0.1"
|
||||
[API_HTTP_PORT]="5000"
|
||||
[API_SERVER_NAME]="bwapi"
|
||||
[API_WHITELIST_IP]="127.0.0.0/8"
|
||||
[USE_REAL_IP]="no"
|
||||
[USE_PROXY_PROTOCOL]="no"
|
||||
[REAL_IP_FROM]="192.168.0.0/16 172.16.0.0/12 10.0.0.0/8"
|
||||
[REAL_IP_HEADER]="X-Forwarded-For"
|
||||
[HTTP_PORT]="80"
|
||||
[HTTPS_PORT]="443"
|
||||
)
|
||||
|
||||
# File containing the environment variables
|
||||
env_file="/etc/bunkerweb/variables.env"
|
||||
|
||||
# Load variables safely
|
||||
if [ -f "$env_file" ]; then
|
||||
while IFS='=' read -r key value; do
|
||||
# Skip empty lines and comments
|
||||
[[ -z "$key" || "$key" =~ ^# ]] && continue
|
||||
# Trim whitespace
|
||||
key=$(echo "$key" | xargs)
|
||||
value=$(echo "$value" | xargs)
|
||||
# Only process recognized keys
|
||||
if [[ -n "${defaults[$key]}" ]]; then
|
||||
# Set variable if defined and non-empty in the file
|
||||
[[ -n "$value" ]] && eval "${key}=\"$value\""
|
||||
fi
|
||||
done < "$env_file"
|
||||
fi
|
||||
|
||||
# Assign default values for unset variables
|
||||
for key in "${!defaults[@]}"; do
|
||||
eval "value=\${${key}:-}"
|
||||
if [ -z "$value" ]; then
|
||||
eval "${key}=\"${defaults[$key]}\""
|
||||
fi
|
||||
done
|
||||
|
||||
sudo -E -u nginx -g nginx /bin/bash -c "echo -ne 'IS_LOADING=yes\nUSE_BUNKERNET=no\nSEND_ANONYMOUS_REPORT=no\nSERVER_NAME=\nDNS_RESOLVERS=${DNS_RESOLVERS}\nAPI_HTTP_PORT=${API_HTTP_PORT}\nAPI_LISTEN_IP=${API_LISTEN_IP}\nAPI_SERVER_NAME=${API_SERVER_NAME}\nAPI_WHITELIST_IP=${API_WHITELIST_IP}\nUSE_REAL_IP=${USE_REAL_IP}\nUSE_PROXY_PROTOCOL=${USE_PROXY_PROTOCOL}\nREAL_IP_FROM=${REAL_IP_FROM}\nREAL_IP_HEADER=${REAL_IP_HEADER}\nHTTP_PORT=${HTTP_PORT}\nHTTPS_PORT=${HTTPS_PORT}\n' > /var/tmp/bunkerweb/tmp.env"
|
||||
chown root:nginx /var/tmp/bunkerweb/tmp.env
|
||||
chmod 660 /var/tmp/bunkerweb/tmp.env
|
||||
|
||||
sudo -E -u nginx -g nginx /bin/bash -c "PYTHONPATH=/usr/share/bunkerweb/deps/python /usr/share/bunkerweb/gen/main.py --variables /var/tmp/bunkerweb/tmp.env --no-linux-reload"
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Error while generating config from /var/tmp/bunkerweb/tmp.env"
|
||||
exit 1
|
||||
fi
|
||||
# Start nginx
|
||||
log "SYSTEMCTL" "ℹ️" "Starting nginx ..."
|
||||
sudo -E -u nginx -g nginx /usr/sbin/nginx -e /var/log/bunkerweb/error.log
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Error while executing temp 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)"
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -eq 0 ] && [ "$check" = "ok" ] ; then
|
||||
break
|
||||
fi
|
||||
count=$((count + 1))
|
||||
sleep 1
|
||||
log "SYSTEMCTL" "ℹ️" "Waiting for nginx to start ..."
|
||||
done
|
||||
if [ $count -ge 10 ] ; then
|
||||
log "SYSTEMCTL" "❌" "nginx is not started"
|
||||
exit 1
|
||||
fi
|
||||
log "SYSTEMCTL" "ℹ️" "nginx started ..."
|
||||
|
||||
log "SYSTEMCTL" "ℹ️" "BunkerWeb service started ..."
|
||||
|
||||
while [ -f /var/run/bunkerweb/nginx.pid ] ; do
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
function stop() {
|
||||
log "SYSTEMCTL" "ℹ️" "Stopping BunkerWeb service ..."
|
||||
|
||||
pgrep nginx > /dev/null 2>&1
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -eq 0 ] ; then
|
||||
|
|
@ -52,212 +187,31 @@ function stop_nginx() {
|
|||
exit 1
|
||||
fi
|
||||
log "SYSTEMCTL" "ℹ️ " "nginx is stopped"
|
||||
}
|
||||
|
||||
function stop_scheduler() {
|
||||
if [ -f "/var/run/bunkerweb/scheduler.pid" ] ; then
|
||||
scheduler_pid=$(cat "/var/run/bunkerweb/scheduler.pid")
|
||||
log "SYSTEMCTL" "ℹ️ " "Stopping scheduler..."
|
||||
kill -SIGINT "$scheduler_pid"
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Error while sending stop signal to scheduler"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log "SYSTEMCTL" "ℹ️ " "Scheduler already stopped"
|
||||
return 0
|
||||
fi
|
||||
count=0
|
||||
while [ -f "/var/run/bunkerweb/scheduler.pid" ] ; do
|
||||
sleep 1
|
||||
count=$((count + 1))
|
||||
if [ $count -ge 10 ] ; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ $count -ge 10 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Timeout while waiting scheduler to stop"
|
||||
exit 1
|
||||
fi
|
||||
log "SYSTEMCTL" "ℹ️ " "Scheduler is stopped"
|
||||
}
|
||||
|
||||
# Start the bunkerweb service
|
||||
function start() {
|
||||
|
||||
# Set the PYTHONPATH
|
||||
export PYTHONPATH=/usr/share/bunkerweb/deps/python
|
||||
|
||||
log "SYSTEMCTL" "ℹ️" "Starting BunkerWeb service ..."
|
||||
|
||||
setcap 'CAP_NET_BIND_SERVICE=+eip' /usr/sbin/nginx
|
||||
chown -R nginx:nginx /etc/nginx
|
||||
|
||||
# Create dummy variables.env
|
||||
if [ ! -f /etc/bunkerweb/variables.env ]; then
|
||||
sudo -E -u nginx -g nginx /bin/bash -c "echo -ne '# remove IS_LOADING=yes when your config is ready\nIS_LOADING=yes\nDNS_RESOLVERS=8.8.8.8 8.8.4.4\nHTTP_PORT=80\nHTTPS_PORT=443\nAPI_LISTEN_IP=127.0.0.1\nSERVER_NAME=\n' > /etc/bunkerweb/variables.env"
|
||||
log "SYSTEMCTL" "ℹ️" "Created dummy variables.env file"
|
||||
fi
|
||||
|
||||
# Create PID folder
|
||||
if [ ! -f /var/run/bunkerweb ] ; then
|
||||
mkdir -p /var/run/bunkerweb
|
||||
chown nginx:nginx /var/run/bunkerweb
|
||||
fi
|
||||
|
||||
# Create TMP folder
|
||||
if [ ! -f /var/tmp/bunkerweb ] ; then
|
||||
mkdir -p /var/tmp/bunkerweb
|
||||
chown nginx:nginx /var/tmp/bunkerweb
|
||||
fi
|
||||
|
||||
# Create LOG folder
|
||||
if [ ! -f /var/log/bunkerweb ] ; then
|
||||
mkdir -p /var/log/bunkerweb
|
||||
chown nginx:nginx /var/log/bunkerweb
|
||||
fi
|
||||
|
||||
# Stop scheduler if it's running
|
||||
stop_scheduler
|
||||
|
||||
# Stop nginx if it's running
|
||||
stop_nginx
|
||||
|
||||
# Check if we are in slave/master mode
|
||||
MASTER_MODE="$(grep "^MASTER_MODE=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
export MASTER_MODE
|
||||
SLAVE_MODE="$(grep "^SLAVE_MODE=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
export SLAVE_MODE
|
||||
|
||||
CUSTOM_LOG_LEVEL="$(grep "^CUSTOM_LOG_LEVEL=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
export CUSTOM_LOG_LEVEL
|
||||
LOG_LEVEL="$(grep "^LOG_LEVEL=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
export LOG_LEVEL
|
||||
|
||||
if [ "$MASTER_MODE" != "yes" ] ; then
|
||||
# Generate temp conf for jobs and start nginx
|
||||
DNS_RESOLVERS="$(grep "^DNS_RESOLVERS=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
if [ "$DNS_RESOLVERS" = "" ] ; then
|
||||
DNS_RESOLVERS="8.8.8.8 8.8.4.4"
|
||||
fi
|
||||
API_LISTEN_IP="$(grep "^API_LISTEN_IP=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
if [ "$API_LISTEN_IP" = "" ] ; then
|
||||
API_LISTEN_IP="127.0.0.1"
|
||||
fi
|
||||
API_HTTP_PORT="$(grep "^API_HTTP_PORT=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
if [ "$API_HTTP_PORT" = "" ] ; then
|
||||
API_HTTP_PORT="5000"
|
||||
fi
|
||||
API_SERVER_NAME="$(grep "^API_SERVER_NAME=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
if [ "$API_SERVER_NAME" = "" ] ; then
|
||||
API_SERVER_NAME="bwapi"
|
||||
fi
|
||||
API_WHITELIST_IP="$(grep "^API_WHITELIST_IP=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
if [ "$API_WHITELIST_IP" = "" ] ; then
|
||||
API_WHITELIST_IP="127.0.0.0/8"
|
||||
fi
|
||||
USE_REAL_IP="$(grep "^USE_REAL_IP=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
if [ "$USE_REAL_IP" = "" ] ; then
|
||||
USE_REAL_IP="no"
|
||||
fi
|
||||
USE_PROXY_PROTOCOL="$(grep "^USE_PROXY_PROTOCOL=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
if [ "$USE_PROXY_PROTOCOL" = "" ] ; then
|
||||
USE_PROXY_PROTOCOL="no"
|
||||
fi
|
||||
REAL_IP_FROM="$(grep "^REAL_IP_FROM=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
if [ "$REAL_IP_FROM" = "" ] ; then
|
||||
REAL_IP_FROM="192.168.0.0/16 172.16.0.0/12 10.0.0.0/8"
|
||||
fi
|
||||
REAL_IP_HEADER="$(grep "^REAL_IP_HEADER=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
if [ "$REAL_IP_HEADER" = "" ] ; then
|
||||
REAL_IP_HEADER="X-Forwarded-For"
|
||||
fi
|
||||
HTTP_PORT="$(grep "^HTTP_PORT=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
if [ "$HTTP_PORT" = "" ] ; then
|
||||
HTTP_PORT="80"
|
||||
fi
|
||||
HTTPS_PORT="$(grep "^HTTPS_PORT=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
if [ "$HTTPS_PORT" = "" ] ; then
|
||||
HTTPS_PORT="443"
|
||||
fi
|
||||
MODSECURITY_CRS_VERSION="$(grep "^MODSECURITY_CRS_VERSION=" /etc/bunkerweb/variables.env | cut -d '=' -f 2)"
|
||||
if [ "$MODSECURITY_CRS_VERSION" = "" ] ; then
|
||||
MODSECURITY_CRS_VERSION="3"
|
||||
fi
|
||||
sudo -E -u nginx -g nginx /bin/bash -c "echo -ne 'IS_LOADING=yes\nUSE_BUNKERNET=no\nSEND_ANONYMOUS_REPORT=no\nSERVER_NAME=\nMODSECURITY_CRS_VERSION=${MODSECURITY_CRS_VERSION}\nDNS_RESOLVERS=${DNS_RESOLVERS}\nAPI_HTTP_PORT=${API_HTTP_PORT}\nAPI_LISTEN_IP=${API_LISTEN_IP}\nAPI_SERVER_NAME=${API_SERVER_NAME}\nAPI_WHITELIST_IP=${API_WHITELIST_IP}\nUSE_REAL_IP=${USE_REAL_IP}\nUSE_PROXY_PROTOCOL=${USE_PROXY_PROTOCOL}\nREAL_IP_FROM=${REAL_IP_FROM}\nREAL_IP_HEADER=${REAL_IP_HEADER}\nHTTP_PORT=${HTTP_PORT}\nHTTPS_PORT=${HTTPS_PORT}\n' > /var/tmp/bunkerweb/tmp.env"
|
||||
sudo -E -u nginx -g nginx /bin/bash -c "PYTHONPATH=/usr/share/bunkerweb/deps/python/ /usr/share/bunkerweb/gen/main.py --variables /var/tmp/bunkerweb/tmp.env --no-linux-reload"
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Error while generating config from /var/tmp/bunkerweb/tmp.env"
|
||||
exit 1
|
||||
fi
|
||||
# Start nginx
|
||||
log "SYSTEMCTL" "ℹ️" "Starting nginx ..."
|
||||
sudo -E -u nginx -g nginx /usr/sbin/nginx -e /var/log/bunkerweb/error.log
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Error while executing temp 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)"
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -eq 0 ] && [ "$check" = "ok" ] ; then
|
||||
break
|
||||
fi
|
||||
count=$((count + 1))
|
||||
sleep 1
|
||||
log "SYSTEMCTL" "ℹ️" "Waiting for nginx to start ..."
|
||||
done
|
||||
if [ $count -ge 10 ] ; then
|
||||
log "SYSTEMCTL" "❌" "nginx is not started"
|
||||
exit 1
|
||||
fi
|
||||
log "SYSTEMCTL" "ℹ️" "nginx started ..."
|
||||
fi
|
||||
|
||||
# Execute scheduler
|
||||
log "SYSTEMCTL" "ℹ️ " "Executing scheduler ..."
|
||||
export SCHEDULER_LOG_TO_FILE=yes
|
||||
sudo -E -u nginx -g nginx /bin/bash -c "PYTHONPATH=/usr/share/bunkerweb/deps/python/ /usr/share/bunkerweb/scheduler/main.py --variables /etc/bunkerweb/variables.env"
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Scheduler failed"
|
||||
exit 1
|
||||
fi
|
||||
log "SYSTEMCTL" "ℹ️ " "Scheduler stopped"
|
||||
}
|
||||
|
||||
function stop() {
|
||||
log "SYSTEMCTL" "ℹ️" "Stopping BunkerWeb service ..."
|
||||
|
||||
stop_nginx
|
||||
stop_scheduler
|
||||
|
||||
log "SYSTEMCTL" "ℹ️" "BunkerWeb service stopped"
|
||||
}
|
||||
|
||||
function reload()
|
||||
{
|
||||
|
||||
log "SYSTEMCTL" "ℹ️" "Reloading BunkerWeb service ..."
|
||||
|
||||
PID_FILE_PATH="/var/run/bunkerweb/scheduler.pid"
|
||||
if [ -f "$PID_FILE_PATH" ];
|
||||
then
|
||||
result=$(cat "$PID_FILE_PATH")
|
||||
# Send signal to scheduler to reload
|
||||
log "SYSTEMCTL" "ℹ️" "Sending reload signal to scheduler ..."
|
||||
kill -SIGHUP "$result"
|
||||
pgrep nginx > /dev/null 2>&1
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -eq 0 ] ; then
|
||||
log "SYSTEMCTL" "ℹ️" "Reloading nginx ..."
|
||||
nginx -s reload
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Your command exited with non-zero status $result"
|
||||
exit 1
|
||||
log "SYSTEMCTL" "❌" "Error while sending reload signal to nginx"
|
||||
log "SYSTEMCTL" "ℹ️" "Reloading nginx (force) ..."
|
||||
kill -HUP "$(cat /var/run/bunkerweb/nginx.pid)"
|
||||
# shellcheck disable=SC2181
|
||||
if [ $? -ne 0 ] ; then
|
||||
log "SYSTEMCTL" "❌" "Error while sending hup signal to nginx"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
log "SYSTEMCTL" "❌" "Scheduler is not running"
|
||||
log "SYSTEMCTL" "❌" "nginx is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue