Preparing for reloading haproxy
This commit is contained in:
parent
417db0de77
commit
eb10288717
7 changed files with 103 additions and 6 deletions
24
Dockerfile
24
Dockerfile
|
|
@ -1,12 +1,24 @@
|
|||
FROM haproxy:1.9-alpine
|
||||
|
||||
RUN apk add --no-cache bash python3 py-yaml
|
||||
WORKDIR /root
|
||||
|
||||
COPY entrypoint.* /
|
||||
COPY conf.d /etc/haproxy/conf.d
|
||||
COPY assets/errors-custom/* /etc/haproxy/errors-custom/
|
||||
RUN apk add --no-cache bash python3 py-yaml supervisor docker
|
||||
|
||||
COPY requirements.txt /root
|
||||
RUN pip3 install --upgrade pip \
|
||||
&& pip install -r requirements.txt
|
||||
|
||||
ENTRYPOINT [ "/entrypoint.sh" ]
|
||||
CMD ["haproxy", "-f", "/etc/haproxy/haproxy.cfg"]
|
||||
|
||||
COPY haproxy.cfg /etc/haproxy/haproxy.cfg
|
||||
COPY conf.d /etc/haproxy/conf.d
|
||||
COPY assets/errors-custom/* /etc/haproxy/errors-custom/
|
||||
COPY assets/supervisord.conf /etc/supervisord.conf
|
||||
COPY assets/crontab /etc/crontabs/root
|
||||
|
||||
COPY scripts/exit-event-listener.py /exit-event-listener.py
|
||||
COPY scripts/haproxy.sh /haproxy.sh
|
||||
COPY scripts/haproxy-reload.sh /haproxy-reload.sh
|
||||
|
||||
|
||||
#CMD ["haproxy", "-f", "/etc/haproxy/haproxy.cfg"]
|
||||
CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf" ]
|
||||
|
|
@ -24,6 +24,7 @@ docker run \
|
|||
-e HAPROXY_PASSWORD=password \
|
||||
-e HAPROXY_STATS_PORT=1936 \
|
||||
-e REFRESH_STATE=1 \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-d byjg/easy-haproxy
|
||||
```
|
||||
|
||||
|
|
|
|||
9
assets/crontab
Normal file
9
assets/crontab
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# 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
|
||||
* * * * * /haproxy-reload.sh
|
||||
|
||||
45
assets/supervisord.conf
Normal file
45
assets/supervisord.conf
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
[unix_http_server]
|
||||
file=/dev/shm/supervisor.sock ; (the path to the socket file)
|
||||
|
||||
[supervisord]
|
||||
logfile=/tmp/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=/tmp/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 = /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=/exit-event-listener.py
|
||||
events=PROCESS_STATE_FATAL,PROCESS_STATE_EXITED,PROCESS_STATE_STOPPED
|
||||
18
scripts/exit-event-listener.py
Executable file
18
scripts/exit-event-listener.py
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/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 not (headers['eventname'] in events):
|
||||
continue
|
||||
os.kill(os.getppid(), signal.SIGTERM)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
5
scripts/haproxy-reload.sh
Executable file
5
scripts/haproxy-reload.sh
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
echo "Reloading..."
|
||||
|
||||
/usr/local/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -x /var/run/haproxy.sock -sf $(cat /run/haproxy.pid) &
|
||||
7
scripts/haproxy.sh
Executable file
7
scripts/haproxy.sh
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
/usr/local/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /var/run/haproxy.sock
|
||||
|
||||
while true; do
|
||||
sleep 60
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue