Linux: Updating nginx to 1.22

This commit is contained in:
AxyFr 2022-11-30 09:10:03 +01:00
parent 8e31672ac5
commit 3c9574dae7
14 changed files with 105 additions and 78 deletions

View File

@ -1,7 +1,7 @@
FROM quay.io/centos/centos:stream8
ENV OS=centos
ENV NGINX_VERSION 1.20.2
ENV NGINX_VERSION 1.22.1
# Install fpm
RUN dnf install -y epel-release && \

View File

@ -1,7 +1,7 @@
FROM debian:bullseye-slim
ENV OS=debian
ENV NGINX_VERSION 1.20.2
ENV NGINX_VERSION 1.22.1
# Install fpm
RUN apt update && \

View File

@ -1,7 +1,7 @@
FROM fedora:36
ENV OS=fedora
ENV NGINX_VERSION 1.20.2
ENV NGINX_VERSION 1.22.1
# Install fpm
RUN dnf install -y ruby ruby-devel make gcc redhat-rpm-config rpm-build && \

View File

@ -1,7 +1,7 @@
FROM redhat/ubi8:8.6
ENV OS=rhel
ENV NGINX_VERSION 1.20.2
ENV NGINX_VERSION 1.22.1
# RHEL subscription
RUN subscription-manager register --username=username --password=password --auto-attach

View File

@ -1,7 +1,7 @@
FROM ubuntu:22.04
ENV OS=ubuntu
ENV NGINX_VERSION 1.20.2
ENV NGINX_VERSION 1.22.1
# Install fpm
RUN apt update && \

View File

@ -4,7 +4,7 @@ Documentation=https://docs.bunkerweb.io
After=network.target
[Service]
Restart=always
Restart=no
User=root
PIDFile=/var/tmp/bunkerweb/scheduler.pid
ExecStart=/usr/share/bunkerweb/scripts/start.sh start

View File

@ -3,7 +3,7 @@
--license agpl3
--version %VERSION%
--architecture x86_64
--depends bash --depends epel-release --depends python39 --depends 'nginx = 1:1.20.2-1.el8.ngx' --depends libcurl-devel --depends libxml2 --depends lmdb-libs --depends GeoIP-devel --depends file-libs --depends net-tools --depends gd --depends sudo
--depends bash --depends epel-release --depends python39 --depends 'nginx = 1:1.22.1-1.el8.ngx' --depends libcurl-devel --depends libxml2 --depends lmdb-libs --depends GeoIP-devel --depends file-libs --depends net-tools --depends gd --depends sudo
--description "BunkerWeb %VERSION% for CentOS Stream 8"
--url "https://www.bunkerweb.io"
--maintainer "Bunkerity <contact at bunkerity dot com>"

View File

@ -3,7 +3,7 @@
--license agpl3
--version %VERSION%
--architecture amd64
--depends bash --depends python3 --depends python3-pip --depends 'nginx = 1.20.2-1~bullseye' --depends libcurl4 --depends libgeoip-dev --depends libxml2 --depends libyajl2 --depends libmagic1 --depends net-tools --depends sudo
--depends bash --depends python3 --depends python3-pip --depends 'nginx = 1.22.1-1~bullseye' --depends libcurl4 --depends libgeoip-dev --depends libxml2 --depends libyajl2 --depends libmagic1 --depends net-tools --depends sudo
--description "BunkerWeb %VERSION% for Debian 11"
--url "https://www.bunkerweb.io"
--maintainer "Bunkerity <contact at bunkerity dot com>"

View File

@ -3,7 +3,7 @@
--license agpl3
--version %VERSION%
--architecture x86_64
--depends bash --depends python3 --depends 'nginx = 1:1.20.2-2.fc36' --depends libcurl-devel --depends libxml2 --depends lmdb-libs --depends geoip-devel --depends gd --depends sudo
--depends bash --depends python3 --depends 'nginx = 1:1.22.1-2.fc36' --depends libcurl-devel --depends libxml2 --depends lmdb-libs --depends geoip-devel --depends gd --depends sudo
--description "BunkerWeb %VERSION% for Fedora 36"
--url "https://www.bunkerweb.io"
--maintainer "Bunkerity <contact at bunkerity dot com>"

View File

@ -3,7 +3,7 @@
--license agpl3
--version %VERSION%
--architecture x86_64
--depends bash --depends epel-release --depends python39 --depends 'nginx = 1:1.20.2-1.el8.ngx' --depends libcurl-devel --depends libxml2 --depends lmdb-libs --depends GeoIP-devel --depends file-libs --depends net-tools --depends gd --depends sudo
--depends bash --depends epel-release --depends python39 --depends 'nginx = 1:1.22.1-1.el8.ngx' --depends libcurl-devel --depends libxml2 --depends lmdb-libs --depends GeoIP-devel --depends file-libs --depends net-tools --depends gd --depends sudo
--description "BunkerWeb %VERSION% for Rhel 8"
--url "https://www.bunkerweb.io"
--maintainer "Bunkerity <contact at bunkerity dot com>"

View File

@ -2,10 +2,12 @@
--name bunkerweb
--license agpl3
--version %VERSION%
--depends bash --depends python3 --depends python3-pip --depends 'nginx = 1.20.2-1~jammy' --depends libcurl4 --depends libgeoip-dev --depends libxml2 --depends libyajl2 --depends libmagic1 --depends net-tools --depends sudo
--depends bash --depends python3 --depends python3-pip --depends 'nginx = 1.22.1-1~jammy' --depends libcurl4 --depends libgeoip-dev --depends libxml2 --depends libyajl2 --depends libmagic1 --depends net-tools --depends sudo
--description "BunkerWeb %VERSION% for Ubuntu 22.04"
--url "https://www.bunkerweb.io"
--maintainer "Bunkerity <contact at bunkerity dot com>"
--after-install /usr/share/bunkerweb/scripts/postinstall.sh
--after-remove /usr/share/bunkerweb/scripts/afterRemove.sh
/usr/share/bunkerweb/=/usr/share/bunkerweb/ /usr/bin/bwcli=/usr/bin/bwcli /etc/bunkerweb/=/etc/bunkerweb /var/tmp/bunkerweb/=/var/tmp/bunkerweb /var/cache/bunkerweb/=/var/cache/bunkerweb /etc/systemd/system/bunkerweb.service=/etc/systemd/system/bunkerweb.service /etc/systemd/system/bunkerweb-ui.service=/etc/systemd/system/bunkerweb-ui.service
--deb-systemd-auto-start /etc/systemd/system/bunkerweb.service
--deb-systemd-auto-start /etc/systemd/system/bunkerweb-ui.service
/usr/share/bunkerweb/=/usr/share/bunkerweb/ /usr/bin/bwcli=/usr/bin/bwcli /etc/bunkerweb/=/etc/bunkerweb /var/tmp/bunkerweb/=/var/tmp/bunkerweb /var/cache/bunkerweb/=/var/cache/bunkerweb

View File

@ -22,12 +22,11 @@ export PYTHONPATH=/usr/share/bunkerweb/deps/python/
# Create user scheduler if not exists
if ! id -u scheduler > /dev/null 2>&1; then
# Create group scheduler
groupadd scheduler
# Create user scheduler
useradd scheduler -g scheduler
chown -R scheduler:scheduler /usr/share/bunkerweb /var/cache/bunkerweb /var/lib/bunkerweb /etc/bunkerweb /var/tmp/bunkerweb
chown -R scheduler:scheduler /etc/nginx
addgroup --gid 120 scheduler
# Line below it's not working on Ubuntu 22.04
# Correct way to do it is to use useradd
adduser --uid 120 --gid 120 --disabled-password --gecos "" scheduler
#adduser -h /var/cache/nginx -s /bin/sh --group scheduler -D -H -u 101 scheduler
fi
#############################################################
@ -114,41 +113,62 @@ function stop()
function reload()
{
log "ENTRYPOINT" "" "Reloading BunkerWeb service ..."
# Check if pid file exist and remove it if so
# Send signal to scheduler to reload
PID_FILE_PATH="/var/tmp/bunkerweb/scheduler.pid"
if [ -f "$PID_FILE_PATH" ];
then
var=$(cat "$PID_FILE_PATH")
log "ENTRYPOINT" "" "Sending reload signal to scheduler ..."
log "ENTRYPOINT" "" "Sending reload signal to scheduler ..."
kill -SIGHUP $var
result=$?
if [ $result -ne 0 ] ; then
log "ENTRYPOINT" "❌" "Your command exited with non-zero status $result"
exit 1
fi
result=$?
if [ $result -ne 0 ] ; then
log "ENTRYPOINT" "❌" "Your command exited with non-zero status $result"
exit 1
fi
else
log "ENTRYPOINT" "❌" "Scheduler is not running"
exit 1
fi
# Check if nginx running and if so, reload it
SERVICE="nginx"
if pgrep -x "$SERVICE" > /dev/null
then
log "ENTRYPOINT" "" "Sending reload signal to BunkerWeb ..."
nginx -s reload
result=$?
if [ $result -ne 0 ] ; then
log "ENTRYPOINT" "❌" "Your command exited with non-zero status $result"
exit 1
fi
else
log "ENTRYPOINT" "❌" "BunkerWeb is not running"
exit 1
exit 1
fi
}
# function reload()
# {
# log "ENTRYPOINT" "" "Reloading BunkerWeb service ..."
# # Check if pid file exist and remove it if so
# PID_FILE_PATH="/var/tmp/bunkerweb/scheduler.pid"
# if [ -f "$PID_FILE_PATH" ];
# then
# var=$(cat "$PID_FILE_PATH")
# log "ENTRYPOINT" "" "Sending reload signal to scheduler ..."
# kill -SIGHUP $var
# result=$?
# if [ $result -ne 0 ] ; then
# log "ENTRYPOINT" "❌" "Your command exited with non-zero status $result"
# exit 1
# fi
# else
# log "ENTRYPOINT" "❌" "Scheduler is not running"
# exit 1
# fi
# # Check if nginx running and if so, reload it
# SERVICE="nginx"
# if pgrep -x "$SERVICE" > /dev/null
# then
# log "ENTRYPOINT" "" "Sending reload signal to BunkerWeb ..."
# nginx -s reload
# result=$?
# if [ $result -ne 0 ] ; then
# log "ENTRYPOINT" "❌" "Your command exited with non-zero status $result"
# exit 1
# fi
# else
# log "ENTRYPOINT" "❌" "BunkerWeb is not running"
# exit 1
# fi
# }
# List of differents args
case $1 in
"start")

View File

@ -108,7 +108,9 @@ class JobScheduler(ApiCaller):
success = True
try:
proc = run(
f"{path}/jobs/{file}",
# ["python3", f"{path}/{file}"],
f"{path}jobs/{file}",
#f"{path}/jobs/{file}",
stdin=DEVNULL,
stderr=STDOUT,
env=self.__env,

View File

@ -17,7 +17,7 @@ from os import (
)
from os.path import dirname, exists, isdir, isfile, islink, join
from shutil import chown, copy, rmtree
from signal import SIGINT, SIGTERM, signal
from signal import SIGINT, SIGTERM, signal, SIGHUP
from subprocess import run as subprocess_run, DEVNULL, STDOUT
from sys import path as sys_path
from time import sleep
@ -60,10 +60,11 @@ def imerge(a, b):
yield j
def handle_reload(env):
def handle_reload(signum, frame, env):
global run, scheduler, reloading
try:
if scheduler is not None and run:
# Loading the environment variables from the .env file.
if scheduler.reload(dotenv_values(env)):
logger.info("Reload successful")
else:
@ -76,7 +77,7 @@ def handle_reload(env):
logger.error(
f"Exception while reloading scheduler : {format_exc()}",
)
signal(SIGHUP, handle_reload)
def stop(status):
remove("/var/tmp/bunkerweb/scheduler.pid")
@ -373,7 +374,9 @@ if __name__ == "__main__":
# Reloading the nginx server.
# Had to use this instead of the nginx reload command because it was not working
proc = subprocess_run(
["nginx", "-s", "reload"],
# Reload nginx
["/etc/init.d/nginx", "reload"],
#["nginx", "-s", "reload"],
stdin=DEVNULL,
stderr=STDOUT,
env=deepcopy(env),
@ -403,39 +406,39 @@ if __name__ == "__main__":
scheduler.run_pending()
sleep(1)
# check if the custom configs have changed since last time
tmp_custom_configs = db.get_custom_configs()
if custom_configs != tmp_custom_configs:
logger.info("Custom configs changed, generating ...")
logger.debug(f"{tmp_custom_configs}")
logger.debug(f"{custom_configs}")
custom_configs = tmp_custom_configs
original_path = "/data/configs"
# # check if the custom configs have changed since last time
# tmp_custom_configs = db.get_custom_configs()
# if custom_configs != tmp_custom_configs:
# logger.info("Custom configs changed, generating ...")
# logger.debug(f"{tmp_custom_configs}")
# logger.debug(f"{custom_configs}")
# custom_configs = tmp_custom_configs
# original_path = "/data/configs"
# Remove old custom configs files
logger.info("Removing old custom configs files ...")
files = glob(f"{original_path}/*")
for file in files:
if islink(file):
unlink(file)
elif isfile(file):
remove(file)
elif isdir(file):
rmtree(file, ignore_errors=False)
# # Remove old custom configs files
# logger.info("Removing old custom configs files ...")
# files = glob(f"{original_path}/*")
# for file in files:
# if islink(file):
# unlink(file)
# elif isfile(file):
# remove(file)
# elif isdir(file):
# rmtree(file, ignore_errors=False)
logger.info("Generating new custom configs ...")
generate_custom_configs(custom_configs, integration, api_caller)
# logger.info("Generating new custom configs ...")
# generate_custom_configs(custom_configs, integration, api_caller)
# check if the config have changed since last time
tmp_env = (
dotenv_values(args.variables) if args.variables else db.get_config()
)
if env != tmp_env:
logger.info("Config changed, generating ...")
logger.debug(f"{tmp_env=}")
logger.debug(f"{env=}")
env = deepcopy(tmp_env)
break
# # check if the config have changed since last time
# tmp_env = (
# dotenv_values(args.variables) if args.variables else db.get_config()
# )
# if env != tmp_env:
# logger.info("Config changed, generating ...")
# logger.debug(f"{tmp_env=}")
# logger.debug(f"{env=}")
# env = deepcopy(tmp_env)
# break
except:
logger.error(
f"Exception while executing scheduler : {format_exc()}",