update init and unit for support /etc/haproxy/conf.d

This commit is contained in:
Алексей Шабалин 2023-01-26 18:45:45 +03:00
parent 45b64adbd0
commit 83b94095cc
3 changed files with 23 additions and 9 deletions

View File

@ -25,16 +25,20 @@ WITHOUT_RC_COMPAT=1
. /etc/init.d/functions
NAME=haproxy
PIDFILE=/var/run/${NAME}.pid
PIDFILE=/run/${NAME}.pid
CONFIG=/etc/${NAME}/${NAME}.cfg
CFGDIR=/etc/${NAME}/conf.d
EXTRAOPTS="" #"-S /run/haproxy-master.sock"
LOCKFILE=/var/lock/subsys/${NAME}
BINARY=/usr/sbin/${NAME}
RETVAL=0
SourceIfNotEmpty /etc/sysconfig/${NAME}
check()
{
action "Checking configuration sanity for $name: " \
$BINARY -c -q -f ${CONFIG}
$BINARY -f ${CONFIG} -f $CFGDIR -c -q $EXTRAOPTS
RETVAL=$?
return $RETVAL
}
@ -43,7 +47,7 @@ start()
{
check || exit
start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user _haproxy -- $BINARY \
-D -f ${CONFIG} -p ${PIDFILE}
-D -f ${CONFIG} -f $CFGDIR -p ${PIDFILE} ${EXTRAOPTS}
RETVAL=$?
return $RETVAL
}
@ -66,7 +70,7 @@ reload()
{
check || exit
msg_reloading $NAME
$BINARY -p "$PIDFILE" -f $CONFIG -sf `cat $PIDFILE`
$BINARY -p "$PIDFILE" -f $CONFIG -f $CFGDIR ${EXTRAOPTS} -sf `cat $PIDFILE`
RETVAL=$?
return $RETVAL
}

View File

@ -1,14 +1,15 @@
[Unit]
Description=HAProxy Load Balancer
Documentation=man:haproxy(1)
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid" "CFGDIR=/etc/haproxy/conf.d" "EXTRAOPTS=-S /run/haproxy-master.sock"
EnvironmentFile=-/etc/sysconfig/haproxy
Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid" "EXTRAOPTS=-S /run/haproxy-master.sock"
ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS
ExecStart=/usr/sbin/haproxy -Ws -f $CONFIG -p $PIDFILE $EXTRAOPTS
ExecReload=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS
ExecStartPre=/usr/sbin/haproxy -f $CONFIG -f $CFGDIR -c -q $EXTRAOPTS
ExecStart=/usr/sbin/haproxy -Ws -f $CONFIG -f $CFGDIR -p $PIDFILE $EXTRAOPTS
ExecReload=/usr/sbin/haproxy -f $CONFIG -f $CFGDIR -c -q $EXTRAOPTS
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
@ -25,3 +26,4 @@ SystemCallFilter=~@cpu-emulation @keyring @module @obsolete @raw-io @reboot @swa
[Install]
WantedBy=multi-user.target

8
haproxy.sysconfig Normal file
View File

@ -0,0 +1,8 @@
# Add extra options to the haproxy daemon here. This can be useful for
# specifying multiple configuration files with multiple -f options.
# See haproxy(1) for a complete list of options.
#CONFIG="/etc/haproxy/haproxy.cfg"
#PIDFILE="/run/haproxy.pid"
#CFGDIR="/etc/haproxy/conf.d"
#EXTRAOPTS="-S /run/haproxy-master.sock"