fixed stop and reload operations
This commit is contained in:
parent
c65b78b1cc
commit
06f688fe97
@ -12,6 +12,7 @@ done
|
|||||||
|
|
||||||
# trap SIGTERM and SIGINT
|
# trap SIGTERM and SIGINT
|
||||||
function trap_exit() {
|
function trap_exit() {
|
||||||
|
rm -f "/opt/running" 2> /dev/null
|
||||||
echo "[*] Catched stop operation"
|
echo "[*] Catched stop operation"
|
||||||
echo "[*] Stopping crond ..."
|
echo "[*] Stopping crond ..."
|
||||||
pkill -TERM crond
|
pkill -TERM crond
|
||||||
@ -25,7 +26,7 @@ function trap_exit() {
|
|||||||
pkill -TERM rsyslogd
|
pkill -TERM rsyslogd
|
||||||
pkill -TERM tail
|
pkill -TERM tail
|
||||||
}
|
}
|
||||||
trap "trap_exit" TERM INT
|
trap "trap_exit" TERM INT QUIT
|
||||||
|
|
||||||
# trap SIGHUP
|
# trap SIGHUP
|
||||||
function trap_reload() {
|
function trap_reload() {
|
||||||
@ -37,7 +38,7 @@ function trap_reload() {
|
|||||||
echo "[*] Reloading nginx ..."
|
echo "[*] Reloading nginx ..."
|
||||||
/usr/sbin/nginx -s reload
|
/usr/sbin/nginx -s reload
|
||||||
if [ $? -eq 0 ] ; then
|
if [ $? -eq 0 ] ; then
|
||||||
echo "[*] Reload succesfull"
|
echo "[*] Reload successfull"
|
||||||
else
|
else
|
||||||
echo "[!] Reload failed"
|
echo "[!] Reload failed"
|
||||||
fi
|
fi
|
||||||
@ -83,6 +84,11 @@ if [ -f "/tmp/nginx-temp.pid" ] ; then
|
|||||||
fi
|
fi
|
||||||
echo "[*] Running nginx ..."
|
echo "[*] Running nginx ..."
|
||||||
su -s "/usr/sbin/nginx" 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
|
# list of log files to display
|
||||||
LOGS="/var/log/access.log /var/log/error.log /var/log/jobs.log"
|
LOGS="/var/log/access.log /var/log/error.log /var/log/jobs.log"
|
||||||
@ -113,7 +119,10 @@ fi
|
|||||||
|
|
||||||
# display logs
|
# display logs
|
||||||
tail -F $LOGS &
|
tail -F $LOGS &
|
||||||
wait $!
|
pid="$!"
|
||||||
|
while [ -f "/opt/running" ] ; do
|
||||||
|
wait "$pid"
|
||||||
|
done
|
||||||
|
|
||||||
# sigterm trapped
|
# sigterm trapped
|
||||||
echo "[*] bunkerized-nginx stopped"
|
echo "[*] bunkerized-nginx stopped"
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import utils, config
|
import utils, config
|
||||||
import docker, os, stat, sys, subprocess
|
import docker, os, stat, sys, subprocess, shutil
|
||||||
|
|
||||||
def get_client() :
|
def get_client() :
|
||||||
endpoint = "/var/run/docker.sock"
|
endpoint = "/var/run/docker.sock"
|
||||||
@ -46,7 +46,7 @@ def reload_instances(client) :
|
|||||||
if not check :
|
if not check :
|
||||||
return check, instances
|
return check, instances
|
||||||
i = 0
|
i = 0
|
||||||
for instance in intances :
|
for instance in instances :
|
||||||
try :
|
try :
|
||||||
instance.kill(signal="SIGHUP")
|
instance.kill(signal="SIGHUP")
|
||||||
except docker.errors.APIError as e :
|
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)
|
proc = subprocess.run(["/opt/entrypoint/site-config.sh", env["SERVER_NAME"]], env=env, capture_output=True)
|
||||||
if proc.returncode != 0 :
|
if proc.returncode != 0 :
|
||||||
return False, "Error code " + str(proc.returncode) + " while generating config."
|
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)
|
check, nb = reload_instances(client)
|
||||||
if not check :
|
if not check :
|
||||||
return check, nb
|
return check, nb
|
||||||
@ -82,6 +83,7 @@ def delete_service(client, server_name) :
|
|||||||
shutil.rmtree("/etc/nginx/" + server_name)
|
shutil.rmtree("/etc/nginx/" + server_name)
|
||||||
except Exception as e :
|
except Exception as e :
|
||||||
return False, str(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)
|
check, nb = reload_instances(client)
|
||||||
if not check :
|
if not check :
|
||||||
return check, nb
|
return check, nb
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user