[fix] proxy and certbot now exit properly with code 0
- also fixed (currently not used) saving log to file
This commit is contained in:
@@ -11,6 +11,7 @@ log_file="" # leave empty for stdout
|
||||
# variables
|
||||
domain_file="$temp_path/domains.txt"
|
||||
certs_updated="$cert_root_path/.updated"
|
||||
certs_daemon_pid=-1
|
||||
|
||||
#functions
|
||||
function log()
|
||||
@@ -35,11 +36,36 @@ function log()
|
||||
echo "[$time]:[$prefix]:[$0][$func]: $@" 2>&1
|
||||
;;
|
||||
*)
|
||||
echo "[$time]:[$prefix]:[$0][$func]: $@" >> log_path
|
||||
echo "[$time]:[$prefix]:[$0][$func]: $@" >> $log_file
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function sleep_wait()
|
||||
{
|
||||
# waiting on sleep to be able to handle SIGTERM
|
||||
sleep $1 &
|
||||
wait $!
|
||||
}
|
||||
|
||||
function exit_handler()
|
||||
{
|
||||
# TODO: because nginx is started in foreground and replaces
|
||||
# the shell via exec, this handler is never called, however as there
|
||||
# is no cleanup for the certs_daemon it doesn't really matter
|
||||
if [ $certs_daemon_pid -gt 0 ] ; then
|
||||
log exit_handler "stopping certs_daemon"
|
||||
kill -SIGTERM $certs_daemon_pid
|
||||
fi
|
||||
log exit_handler "shutting down nginx"
|
||||
nginx -s quit
|
||||
log exit_handler "container shutting down"
|
||||
exit
|
||||
}
|
||||
|
||||
trap "exit_handler" SIGINT
|
||||
trap "exit_handler" SIGTERM
|
||||
|
||||
function var_to_file()
|
||||
{
|
||||
local var=$1
|
||||
@@ -89,13 +115,13 @@ function certs_daemon()
|
||||
# wait for nginx to start
|
||||
while [ ! -f "$nginx_pid" ]; do
|
||||
log certs_daemon "Waiting for nginx to start"
|
||||
sleep 1
|
||||
sleep_wait 1
|
||||
done
|
||||
|
||||
# wait for inital cert update
|
||||
while [ ! -f "$certs_updated" ]; do
|
||||
log certs_daemon "Waiting for initial cert update"
|
||||
sleep 1
|
||||
sleep_wait 1
|
||||
done
|
||||
|
||||
# reload nginx
|
||||
@@ -107,6 +133,7 @@ function certs_daemon()
|
||||
nginx -s reload
|
||||
done
|
||||
) &
|
||||
certs_daemon_pid=$!
|
||||
}
|
||||
|
||||
function nginx_handler()
|
||||
@@ -121,13 +148,12 @@ function nginx_handler()
|
||||
while ! read_file cert_exists "$domain_file" && [ "$retries" -lt "$server_retries" ]; do
|
||||
log nginx_handler "Waiting for certs to be created"
|
||||
retries=$(( retries+1 ))
|
||||
sleep 1
|
||||
sleep_wait 1
|
||||
done
|
||||
|
||||
# starting nginx in foreground
|
||||
log nginx_handler "Starting nginx in foreground"
|
||||
nginx -g "daemon off;"
|
||||
|
||||
exec nginx -g "daemon off;"
|
||||
}
|
||||
|
||||
function main()
|
||||
|
||||
Reference in New Issue
Block a user