fixed stop and reload operations

This commit is contained in:
bunkerity 2020-12-27 22:25:07 +01:00
parent c65b78b1cc
commit 06f688fe97
No known key found for this signature in database
GPG Key ID: 654FFF51CEF7CC47
2 changed files with 16 additions and 5 deletions

View File

@ -12,6 +12,7 @@ done
# trap SIGTERM and SIGINT
function trap_exit() {
rm -f "/opt/running" 2> /dev/null
echo "[*] Catched stop operation"
echo "[*] Stopping crond ..."
pkill -TERM crond
@ -25,7 +26,7 @@ function trap_exit() {
pkill -TERM rsyslogd
pkill -TERM tail
}
trap "trap_exit" TERM INT
trap "trap_exit" TERM INT QUIT
# trap SIGHUP
function trap_reload() {
@ -37,7 +38,7 @@ function trap_reload() {
echo "[*] Reloading nginx ..."
/usr/sbin/nginx -s reload
if [ $? -eq 0 ] ; then
echo "[*] Reload succesfull"
echo "[*] Reload successfull"
else
echo "[!] Reload failed"
fi
@ -83,6 +84,11 @@ if [ -f "/tmp/nginx-temp.pid" ] ; then
fi
echo "[*] Running nginx ..."
su -s "/usr/sbin/nginx" nginx
if [ "$?" -eq 0 ] ; then
touch "/opt/running"
else
rm -f "/opt/running" 2> /dev/null
fi
# list of log files to display
LOGS="/var/log/access.log /var/log/error.log /var/log/jobs.log"
@ -113,7 +119,10 @@ fi
# display logs
tail -F $LOGS &
wait $!
pid="$!"
while [ -f "/opt/running" ] ; do
wait "$pid"
done
# sigterm trapped
echo "[*] bunkerized-nginx stopped"

View File

@ -1,7 +1,7 @@
#!/usr/bin/python3
import utils, config
import docker, os, stat, sys, subprocess
import docker, os, stat, sys, subprocess, shutil
def get_client() :
endpoint = "/var/run/docker.sock"
@ -46,7 +46,7 @@ def reload_instances(client) :
if not check :
return check, instances
i = 0
for instance in intances :
for instance in instances :
try :
instance.kill(signal="SIGHUP")
except docker.errors.APIError as e :
@ -58,6 +58,7 @@ def new_service(client, env) :
proc = subprocess.run(["/opt/entrypoint/site-config.sh", env["SERVER_NAME"]], env=env, capture_output=True)
if proc.returncode != 0 :
return False, "Error code " + str(proc.returncode) + " while generating config."
utils.replace_in_file("/etc/nginx/nginx.conf", "}", "include /etc/nginx/" + env["SERVER_NAME"] + "/server.conf;\n}")
check, nb = reload_instances(client)
if not check :
return check, nb
@ -82,6 +83,7 @@ def delete_service(client, server_name) :
shutil.rmtree("/etc/nginx/" + server_name)
except Exception as e :
return False, str(e)
utils.replace_in_file("/etc/nginx/nginx.conf", "include /etc/nginx/" + server_name + "/server.conf;\n", "")
check, nb = reload_instances(client)
if not check :
return check, nb