1
0
Fork 0

Kill supervisord

This commit is contained in:
Joao M 2022-08-18 18:49:07 +00:00
parent 78e9ae3d08
commit 71119268f2
9 changed files with 24 additions and 93 deletions

View file

@ -3,9 +3,6 @@
# and commit this file to your remote git repository to share the goodness with others. # and commit this file to your remote git repository to share the goodness with others.
tasks: tasks:
- init:
make
- command: | - command: |
virtualenv -p /usr/bin/python3 venv virtualenv -p /usr/bin/python3 venv
source venv/bin/activate source venv/bin/activate

View file

@ -8,7 +8,7 @@ COPY easymapping /scripts/easymapping/
COPY tests/ /scripts/tests/ COPY tests/ /scripts/tests/
COPY assets / COPY assets /
RUN apk add --no-cache haproxy bash python3 py3-pip py-yaml supervisor docker certbot openssl \ RUN apk add --no-cache haproxy bash python3 py3-pip py-yaml docker certbot openssl \
&& ln -s /usr/bin/python3 /usr/bin/python \ && ln -s /usr/bin/python3 /usr/bin/python \
&& pip3 install --upgrade pip \ && pip3 install --upgrade pip \
&& pip install -r requirements.txt \ && pip install -r requirements.txt \
@ -16,4 +16,4 @@ RUN apk add --no-cache haproxy bash python3 py3-pip py-yaml supervisor docker ce
&& openssl dhparam -out /etc/haproxy/dhparam 2048 \ && openssl dhparam -out /etc/haproxy/dhparam 2048 \
&& openssl dhparam -out /etc/haproxy/dhparam-1024 1024 && openssl dhparam -out /etc/haproxy/dhparam-1024 1024
CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf" ] CMD ["/bin/bash", "-c", "/scripts/haproxy.sh" ]

View file

@ -51,6 +51,7 @@ The environment variables will setup the HAProxy.
| EASYHAPROXY_LABEL_PREFIX | (Optional) The key will search for matching resources. Default: `easyhaproxy`. | | EASYHAPROXY_LABEL_PREFIX | (Optional) The key will search for matching resources. Default: `easyhaproxy`. |
| EASYHAPROXY_LETSENCRYPT_EMAIL | (Optional) The email will be used to request the certificate to Letsencrypt | | EASYHAPROXY_LETSENCRYPT_EMAIL | (Optional) The email will be used to request the certificate to Letsencrypt |
| EASYHAPROXY_SSL_MODE | (Optional) `STRICT` supports only the most recent TLS version; `DEFAULT` good SSL integration with recent browsers; `LOOSE` supports all old SSL protocols for old browsers (not recommended). | | EASYHAPROXY_SSL_MODE | (Optional) `STRICT` supports only the most recent TLS version; `DEFAULT` good SSL integration with recent browsers; `LOOSE` supports all old SSL protocols for old browsers (not recommended). |
| EASYHAPROXY_REFRESH_CONF | (Optional) Check configuration every N seconds. Default: 10 |
| HAPROXY_USERNAME | (Optional) The HAProxy username to the statistics. Default: `admin` | | HAPROXY_USERNAME | (Optional) The HAProxy username to the statistics. Default: `admin` |
| HAPROXY_PASSWORD | (Optional) The HAProxy password to the statistics. If not set, statistics will be available with no password | | HAPROXY_PASSWORD | (Optional) The HAProxy password to the statistics. If not set, statistics will be available with no password |
| HAPROXY_STATS_PORT | (Optional) The HAProxy port to the statistics. Default: `1936`. If set to `false`, disable statistics | | HAPROXY_STATS_PORT | (Optional) The HAProxy port to the statistics. Default: `1936`. If set to `false`, disable statistics |

View file

@ -1,9 +0,0 @@
# do daily/weekly/monthly maintenance
# min hour day month weekday command
*/15 * * * * run-parts /etc/periodic/15min
0 * * * * run-parts /etc/periodic/hourly
0 2 * * * run-parts /etc/periodic/daily
0 3 * * 6 run-parts /etc/periodic/weekly
0 5 1 * * run-parts /etc/periodic/monthly
* * * * * /scripts/haproxy-reload.sh > /proc/$(cat /var/run/supervisord.pid)/fd/1 2>&1

View file

@ -1,45 +0,0 @@
[unix_http_server]
file=/dev/shm/supervisor.sock ; (the path to the socket file)
[supervisord]
logfile=/var/log/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
user=root ;
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///dev/shm/supervisor.sock ; use a unix:// URL for a unix socket
[program:haproxy]
command = /scripts/haproxy.sh
autostart=true
autorestart=false
priority=5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:crond]
command=/usr/sbin/crond -f
autostart=true
autorestart=false
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[eventlistener:exit_on_any_fatal]
command=/scripts/exit-event-listener.py
events=PROCESS_STATE_FATAL,PROCESS_STATE_EXITED,PROCESS_STATE_STOPPED

View file

@ -2,7 +2,7 @@
# Semaphore # Semaphore
if [ -f /tmp/certbot-lock ]; then if [ -f /tmp/certbot-lock ]; then
echo "[CERTBOT_JOB] Another process is running" echo "[CERTBOT_JOB] $(date +"$EASYHAPROXY_DATEFORMAT") Another process is running"
exit 0 exit 0
fi fi
@ -26,7 +26,7 @@ for domain in $(cat /scripts/letsencrypt_hosts.txt); do
done done
if [ -n "$REQUEST_CERTS" ]; then if [ -n "$REQUEST_CERTS" ]; then
echo "[CERTBOT_JOB] Requesting certificates for $REQUEST_CERTS" echo "[CERTBOT_JOB] $(date +"$EASYHAPROXY_DATEFORMAT") Requesting certificates for $REQUEST_CERTS"
certbot certonly \ certbot certonly \
--standalone \ --standalone \
--preferred-challenges http \ --preferred-challenges http \
@ -41,7 +41,7 @@ if [ -n "$REQUEST_CERTS" ]; then
fi fi
if [ -n "$RENEW_CERTS" ]; then if [ -n "$RENEW_CERTS" ]; then
echo "[CERTBOT_JOB] Resquesting renew certificated fort $RENEW_CERTS" echo "[CERTBOT_JOB] $(date +"$EASYHAPROXY_DATEFORMAT") Resquesting renew certificated fort $RENEW_CERTS"
certbot renew --post-hook "/scripts/certbot_to_haproxy.sh" certbot renew --post-hook "/scripts/certbot_to_haproxy.sh"
fi fi

View file

@ -1,23 +0,0 @@
#!/usr/bin/env python
import os
import signal
from supervisor import childutils
def main():
while True:
headers, payload = childutils.listener.wait()
childutils.listener.ok()
events = ['PROCESS_STATE_FATAL', 'PROCESS_STATE_EXITED', 'PROCESS_STATE_STOPPED']
if headers['eventname'] not in events:
continue
print(headers)
print(payload)
os.kill(os.getppid(), signal.SIGTERM)
if __name__ == "__main__":
main()

View file

@ -35,7 +35,7 @@ else
RELOAD="false" RELOAD="false"
else else
python3 swarm.py > /etc/haproxy/haproxy.cfg python3 swarm.py > /etc/haproxy/haproxy.cfg
echo "[CONF_CHECK] New configuration found" echo "[CONF_CHECK] $(date +"$EASYHAPROXY_DATEFORMAT") New configuration found"
fi fi
fi fi
@ -44,23 +44,23 @@ if cmp -s ${CONTROL_FILE} ${CONTROL_FILE}.old ; then
fi fi
if [[ ! -z "$1" ]]; then if [[ ! -z "$1" ]]; then
echo "[CONF_CHECK] Initial configuration. Skip certbot." echo "[CONF_CHECK] $(date +"$EASYHAPROXY_DATEFORMAT") Initial configuration. Skip certbot."
else else
/scripts/certbot.sh /scripts/certbot.sh
fi fi
# If Certbot reloads successfully will create the file /tmp/force-reload # If Certbot reloads successfully will create the file /tmp/force-reload
if [ -f /tmp/force-reload ]; then if [ -f /tmp/force-reload ]; then
echo "[CONF_CHECK] New certificates found..." echo "[CONF_CHECK] $(date +"$EASYHAPROXY_DATEFORMAT") New certificates found..."
RELOAD="true" RELOAD="true"
rm /tmp/force-reload rm /tmp/force-reload
fi fi
if [[ ! -z "$1" ]]; then if [[ ! -z "$1" ]]; then
echo "[CONF_CHECK] Starting haproxy..." echo "[CONF_CHECK] $(date +"$EASYHAPROXY_DATEFORMAT") Starting haproxy..."
/usr/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg $(ls /etc/haproxy/conf.d/*.cfg 2>/dev/null | xargs -I{} echo -f {}) -p /run/haproxy.pid -S /var/run/haproxy.sock & /usr/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg $(ls /etc/haproxy/conf.d/*.cfg 2>/dev/null | xargs -I{} echo -f {}) -p /run/haproxy.pid -S /var/run/haproxy.sock &
elif [[ "$RELOAD" == "true" ]]; then elif [[ "$RELOAD" == "true" ]]; then
echo "[CONF_CHECK] Reloading..." echo "[CONF_CHECK] $(date +"$EASYHAPROXY_DATEFORMAT") Reloading..."
/usr/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg $(ls /etc/haproxy/conf.d/*.cfg 2>/dev/null | xargs -I{} echo -f {}) -p /run/haproxy.pid -x /var/run/haproxy.sock -sf $(cat /run/haproxy.pid) & /usr/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg $(ls /etc/haproxy/conf.d/*.cfg 2>/dev/null | xargs -I{} echo -f {}) -p /run/haproxy.pid -x /var/run/haproxy.sock -sf $(cat /run/haproxy.pid) &
fi fi

View file

@ -2,8 +2,18 @@
/usr/sbin/haproxy -v /usr/sbin/haproxy -v
source /scripts/haproxy-reload.sh initial if [ -z "$EASYHAPROXY_DATEFORMAT" ]; then
export EASYHAPROXY_DATEFORMAT="%Y-%m-%d %H:%M:%S %Z"
fi
if [ -z "$EASYHAPROXY_REFRESH_CONF" ]; then
export EASYHAPROXY_REFRESH_CONF=10
fi
/scripts/haproxy-reload.sh initial
while true; do while true; do
sleep 60 sleep $EASYHAPROXY_REFRESH_CONF
echo "[CONF_CHECK] $(date +"$EASYHAPROXY_DATEFORMAT") - Heartbeat."
/scripts/haproxy-reload.sh
done done