HAproxy softreload: mudanças entre as edições
Ir para navegação
Ir para pesquisar
(Criou página com '/usr/lib/systemd/system/haproxy.service <pre> [Unit] Description=HAProxy Load Balancer After=syslog.target network.target [Service] User=root ExecStart=/etc/init.d/haproxy sta...') |
Sem resumo de edição |
(Uma revisão intermediária pelo mesmo usuário não está sendo mostrada) | |
(Sem diferença)
|
Edição atual tal como às 20h51min de 31 de janeiro de 2022
/usr/lib/systemd/system/haproxy.service
[Unit] Description=HAProxy Load Balancer After=syslog.target network.target [Service] User=root ExecStart=/etc/init.d/haproxy start_systemd ExecStop=/etc/init.d/haproxy stop_systemd ExecReload=/etc/init.d/haproxy reload_systemd #Restart=on-abnormal Type=forking [Install] WantedBy=multi-user.target
/etc/init.d/haproxy
#!/bin/bash -x
function TEMPFILE() {
case $1 in
create) mktemp
;;
delete)
rm -fr $2
;;
esac
}
function SETUP_QDISC() {
# Set up the queuing discipline
tc qdisc add dev lo root handle 1: prio bands 4
tc qdisc add dev lo parent 1:1 handle 10: pfifo limit 1000
tc qdisc add dev lo parent 1:2 handle 20: pfifo limit 1000
tc qdisc add dev lo parent 1:3 handle 30: pfifo limit 1000
# Create a plug qdisc with 1 meg of buffer
nl-qdisc-add --dev=lo --parent=1:4 --id=40: plug --limit 1048576
# Release the plug
nl-qdisc-add --dev=lo --parent=1:4 --id=40: --update plug --release-indefinite
# Set up the filter, any packet marked with "1" will be
# directed to the plug
tc filter add dev lo protocol ip parent 1:0 prio 1 handle 1 fw classid 1:4
}
function SOFT_RELOAD_HA() {
/usr/local/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -sf $(/bin/cat /var/run/haproxy.pid)
}
function RELOAD_IPTABLES() {
nl-qdisc-add --dev=lo --parent=1:4 --id=40: --update plug --buffer
SOFT_RELOAD_HA
nl-qdisc-add --dev=lo --parent=1:4 --id=40: --update plug --release-indefinite
}
function ADD_IP_PLUG_QUEUE() {
iptables -t mangle -I OUTPUT -p tcp -s $1 --syn -j MARK --set-mark 1
}
function KILL_HA_OLDPIDS() {
/bin/sleep 15
/bin/kill $(/bin/ps -ef | /bin/grep "haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -sf" | /bin/grep -v grep | /bin/awk '{print $2}')
}
function IPTABLES_HA_RELOAD() {
iptables -I INPUT -p tcp --dport 16000 --syn -j DROP
sleep 0.2
SOFT_RELOAD_HA
iptables -D INPUT -p tcp --dport 16000 --syn -j DROP
sleep 1
KILL_HA_OLDPIDS
}
function QDISC_HA_RELOAD() {
nl-qdisc-add --dev=lo --parent=1:4 --id=40: --update plug --buffer &> /dev/null
SOFT_RELOAD_HA
nl-qdisc-add --dev=lo --parent=1:4 --id=40: --update plug--release-indefinite &> /dev/null
sleep 0.100
# KILL_HA_OLDPIDS
}
if [ $# -ne 1 ]
then
/bin/echo erro
exit 1
else
case $1 in
start_systemd)
SETUP_QDISC
ADD_IP_PLUG_QUEUE <local interface ip>
ADD_IP_PLUG_QUEUE <local interface ip>
SOFT_RELOAD_HA
;;
reload_systemd)
QDISC_HA_RELOAD
;;
setup)
SETUP_QDISC
ADD_IP_PLUG_QUEUE <local interface ip>
ADD_IP_PLUG_QUEUE <local interface ip>
;;
stop_systemd)
killall haproxy
;;
start)
systemctl start haproxy
;;
stop)
systemctl stop haproxy
;;
restart)
systemctl restart haproxy
;;
reload)
systemctl restart haproxy
;;
status)
systemctl status haproxy
;;
esac
fi