From 83b94095cc243d64e835a181d9b607986aebd949 Mon Sep 17 00:00:00 2001 From: Alexey Shabalin Date: Thu, 26 Jan 2023 18:45:45 +0300 Subject: [PATCH] update init and unit for support /etc/haproxy/conf.d --- haproxy.init | 12 ++++++++---- haproxy.service | 12 +++++++----- haproxy.sysconfig | 8 ++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 haproxy.sysconfig diff --git a/haproxy.init b/haproxy.init index 8a9fd1cf5..334f24037 100644 --- a/haproxy.init +++ b/haproxy.init @@ -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 } diff --git a/haproxy.service b/haproxy.service index 328c787d6..f9b64f4ec 100644 --- a/haproxy.service +++ b/haproxy.service @@ -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 + diff --git a/haproxy.sysconfig b/haproxy.sysconfig new file mode 100644 index 000000000..4f8f3e1e5 --- /dev/null +++ b/haproxy.sysconfig @@ -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" +