mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
linux - add missing API_LISTEN_IP initial setting and perform only hot reload
This commit is contained in:
parent
4fbd974d2f
commit
18d682b5a6
2 changed files with 51 additions and 32 deletions
|
|
@ -96,7 +96,7 @@ function start() {
|
|||
|
||||
# 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\nUSE_BUNKERNET=no\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"
|
||||
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
|
||||
|
||||
|
|
@ -111,6 +111,10 @@ function start() {
|
|||
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"
|
||||
|
|
@ -147,7 +151,7 @@ function start() {
|
|||
if [ "$HTTPS_PORT" = "" ] ; then
|
||||
HTTPS_PORT="443"
|
||||
fi
|
||||
sudo -E -u nginx -g nginx /bin/bash -c "echo -ne 'IS_LOADING=yes\nUSE_BUNKERNET=no\nSERVER_NAME=\nDNS_RESOLVERS=${DNS_RESOLVERS}\nAPI_HTTP_PORT=${API_HTTP_PORT}\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 "echo -ne 'IS_LOADING=yes\nUSE_BUNKERNET=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"
|
||||
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
|
||||
|
|
|
|||
|
|
@ -524,46 +524,61 @@ if __name__ == "__main__":
|
|||
else:
|
||||
logger.error("Error while reloading nginx")
|
||||
else:
|
||||
# Stop temp nginx
|
||||
logger.info("Stopping temp nginx ...")
|
||||
# Reload nginx
|
||||
logger.info("Reloading nginx ...")
|
||||
proc = subprocess_run(
|
||||
[join(sep, "usr", "sbin", "nginx"), "-s", "stop"],
|
||||
[join(sep, "usr", "sbin", "nginx"), "-s", "reload"],
|
||||
stdin=DEVNULL,
|
||||
stderr=STDOUT,
|
||||
env=env.copy(),
|
||||
check=False,
|
||||
)
|
||||
if proc.returncode == 0:
|
||||
logger.info("Successfully sent stop signal to temp nginx")
|
||||
i = 0
|
||||
while i < 20:
|
||||
if not Path(sep, "var", "run", "bunkerweb", "nginx.pid").is_file():
|
||||
break
|
||||
logger.warning("Waiting for temp nginx to stop ...")
|
||||
sleep(1)
|
||||
i += 1
|
||||
if i >= 20:
|
||||
logger.error("Timeout error while waiting for temp nginx to stop")
|
||||
else:
|
||||
# Start nginx
|
||||
logger.info("Starting nginx ...")
|
||||
proc = subprocess_run(
|
||||
[join(sep, "usr", "sbin", "nginx"), "-e", "/var/log/bunkerweb/error.log"],
|
||||
stdin=DEVNULL,
|
||||
stderr=STDOUT,
|
||||
env=env.copy(),
|
||||
check=False,
|
||||
)
|
||||
if proc.returncode == 0:
|
||||
logger.info("Successfully started nginx")
|
||||
else:
|
||||
logger.error(
|
||||
f"Error while starting nginx - returncode: {proc.returncode} - error: {proc.stderr.decode('utf-8') if proc.stderr else 'Missing stderr'}",
|
||||
)
|
||||
logger.info("Successfully sent reload signal to nginx")
|
||||
else:
|
||||
logger.error(
|
||||
f"Error while sending stop signal to temp nginx - returncode: {proc.returncode} - error: {proc.stderr.decode('utf-8') if proc.stderr else 'Missing stderr'}",
|
||||
f"Error while reloading nginx - returncode: {proc.returncode} - error: {proc.stderr.decode('utf-8') if proc.stderr else 'Missing stderr'}",
|
||||
)
|
||||
# # Stop temp nginx
|
||||
# logger.info("Stopping temp nginx ...")
|
||||
# proc = subprocess_run(
|
||||
# [join(sep, "usr", "sbin", "nginx"), "-s", "stop"],
|
||||
# stdin=DEVNULL,
|
||||
# stderr=STDOUT,
|
||||
# env=env.copy(),
|
||||
# check=False,
|
||||
# )
|
||||
# if proc.returncode == 0:
|
||||
# logger.info("Successfully sent stop signal to temp nginx")
|
||||
# i = 0
|
||||
# while i < 20:
|
||||
# if not Path(sep, "var", "run", "bunkerweb", "nginx.pid").is_file():
|
||||
# break
|
||||
# logger.warning("Waiting for temp nginx to stop ...")
|
||||
# sleep(1)
|
||||
# i += 1
|
||||
# if i >= 20:
|
||||
# logger.error("Timeout error while waiting for temp nginx to stop")
|
||||
# else:
|
||||
# # Start nginx
|
||||
# logger.info("Starting nginx ...")
|
||||
# proc = subprocess_run(
|
||||
# [join(sep, "usr", "sbin", "nginx"), "-e", "/var/log/bunkerweb/error.log"],
|
||||
# stdin=DEVNULL,
|
||||
# stderr=STDOUT,
|
||||
# env=env.copy(),
|
||||
# check=False,
|
||||
# )
|
||||
# if proc.returncode == 0:
|
||||
# logger.info("Successfully started nginx")
|
||||
# else:
|
||||
# logger.error(
|
||||
# f"Error while starting nginx - returncode: {proc.returncode} - error: {proc.stderr.decode('utf-8') if proc.stderr else 'Missing stderr'}",
|
||||
# )
|
||||
# else:
|
||||
# logger.error(
|
||||
# f"Error while sending stop signal to temp nginx - returncode: {proc.returncode} - error: {proc.stderr.decode('utf-8') if proc.stderr else 'Missing stderr'}",
|
||||
# )
|
||||
except:
|
||||
logger.error(
|
||||
f"Exception while reloading after running jobs once scheduling : {format_exc()}",
|
||||
|
|
|
|||
Loading…
Reference in a new issue