Question about restarting the service

At present, I just need to restart the haproxy command, I found that the program can not get up and stop running

systemctl reload haproxy

Occurred error:

root@korea:~# systemctl status haproxy
● haproxy.service - SYSV: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments.
   Loaded: loaded (/etc/init.d/haproxy; generated; vendor preset: enabled)
   Active: failed (Result: signal) since Thu 2019-08-01 15:21:53 CDT; 14s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3141 ExecStop=/etc/init.d/haproxy stop (code=exited, status=3)
  Process: 3133 ExecReload=/etc/init.d/haproxy reload (code=exited, status=0/SUCCESS)
 Main PID: 3140 (code=killed, signal=KILL)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/haproxy.service
           └─27903 /usr/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid

Aug 01 15:21:53 korea.vps.com haproxy[3141]: /etc/init.d/haproxy: 6: /etc/network/interfaces: auto: not found
Aug 01 15:21:53 korea.vps.com haproxy[3141]: /etc/init.d/haproxy: 7: /etc/network/interfaces: iface: not found
Aug 01 15:21:53 korea.vps.com haproxy[3141]: /etc/init.d/haproxy: 8: /etc/network/interfaces: address: not found
Aug 01 15:21:53 korea.vps.com haproxy[3141]: /etc/init.d/haproxy: 9: /etc/network/interfaces: gateway: not found
Aug 01 15:21:53 korea.vps.com haproxy[3141]: /etc/init.d/haproxy: 10: /etc/network/interfaces: netmask: not found
Aug 01 15:21:53 korea.vps.com haproxy[3141]: /etc/init.d/haproxy: 11: /etc/network/interfaces: dns-nameservers: not found
Aug 01 15:21:53 korea.vps.com haproxy[3141]: Shutting down haproxy:
Aug 01 15:21:53 korea.vps.com systemd[1]: haproxy.service: Control process exited, code=exited status=3
Aug 01 15:21:53 korea.vps.com systemd[1]: haproxy.service: Unit entered failed state.
Aug 01 15:21:53 korea.vps.com systemd[1]: haproxy.service: Failed with result 'signal'.

Then I need to enable the following command before the program can start up.

sudo systemctl start haproxy

Re-execute “start” but normal:

root@korea:~# sudo systemctl status haproxy
● haproxy.service - SYSV: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments.
   Loaded: loaded (/etc/init.d/haproxy; generated; vendor preset: enabled)
   Active: active (running) since Thu 2019-08-01 15:33:20 CDT; 7s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3141 ExecStop=/etc/init.d/haproxy stop (code=exited, status=3)
  Process: 3133 ExecReload=/etc/init.d/haproxy reload (code=exited, status=0/SUCCESS)
  Process: 8894 ExecStart=/etc/init.d/haproxy start (code=exited, status=0/SUCCESS)
 Main PID: 8900 (haproxy)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/haproxy.service
           └─8900 /usr/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid

Aug 01 15:33:20 korea.vps.com haproxy[8894]: /etc/init.d/haproxy: 3: /etc/network/interfaces: auto: not found
Aug 01 15:33:20 korea.vps.com haproxy[8894]: /etc/init.d/haproxy: 4: /etc/network/interfaces: iface: not found
Aug 01 15:33:20 korea.vps.com haproxy[8894]: /etc/init.d/haproxy: 6: /etc/network/interfaces: auto: not found
Aug 01 15:33:20 korea.vps.com haproxy[8894]: /etc/init.d/haproxy: 7: /etc/network/interfaces: iface: not found
Aug 01 15:33:20 korea.vps.com haproxy[8894]: /etc/init.d/haproxy: 8: /etc/network/interfaces: address: not found
Aug 01 15:33:20 korea.vps.com haproxy[8894]: /etc/init.d/haproxy: 9: /etc/network/interfaces: gateway: not found
Aug 01 15:33:20 korea.vps.com haproxy[8894]: /etc/init.d/haproxy: 10: /etc/network/interfaces: netmask: not found
Aug 01 15:33:20 korea.vps.com haproxy[8894]: /etc/init.d/haproxy: 11: /etc/network/interfaces: dns-nameservers: not found
Aug 01 15:33:20 korea.vps.com haproxy[8894]: Starting haproxy:
Aug 01 15:33:20 korea.vps.com systemd[1]: Started SYSV: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited for high availability en

But the prompt "ExecStop=/etc/init.d/haproxy stop (code=exited, status=3)
“, I need to restart to solve this problem.”

● haproxy.service - SYSV: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments.
   Loaded: loaded (/etc/init.d/haproxy; generated; vendor preset: enabled)
   Active: active (running) since Thu 2019-08-01 15:34:43 CDT; 6s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 9677 ExecStop=/etc/init.d/haproxy stop (code=exited, status=0/SUCCESS)
  Process: 3133 ExecReload=/etc/init.d/haproxy reload (code=exited, status=0/SUCCESS)
  Process: 9692 ExecStart=/etc/init.d/haproxy start (code=exited, status=0/SUCCESS)
 Main PID: 9699 (haproxy)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/haproxy.service
           └─9699 /usr/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid

Aug 01 15:34:43 korea.vps.com haproxy[9692]: /etc/init.d/haproxy: 3: /etc/network/interfaces: auto: not found
Aug 01 15:34:43 korea.vps.com haproxy[9692]: /etc/init.d/haproxy: 4: /etc/network/interfaces: iface: not found
Aug 01 15:34:43 korea.vps.com haproxy[9692]: /etc/init.d/haproxy: 6: /etc/network/interfaces: auto: not found
Aug 01 15:34:43 korea.vps.com haproxy[9692]: /etc/init.d/haproxy: 7: /etc/network/interfaces: iface: not found
Aug 01 15:34:43 korea.vps.com haproxy[9692]: /etc/init.d/haproxy: 8: /etc/network/interfaces: address: not found
Aug 01 15:34:43 korea.vps.com haproxy[9692]: /etc/init.d/haproxy: 9: /etc/network/interfaces: gateway: not found
Aug 01 15:34:43 korea.vps.com haproxy[9692]: /etc/init.d/haproxy: 10: /etc/network/interfaces: netmask: not found
Aug 01 15:34:43 korea.vps.com haproxy[9692]: /etc/init.d/haproxy: 11: /etc/network/interfaces: dns-nameservers: not found
Aug 01 15:34:43 korea.vps.com haproxy[9692]: Starting haproxy:
Aug 01 15:34:43 korea.vps.com systemd[1]: Started SYSV: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited for high availability en
lines 1-22/22 (END)

At present, the following two commands will not cause an error to haproxy, but reload seems to stop the program. What should I do?

$ sudo systemctl status haproxy
$ sudo systemctl restart haproxy

error !collapse!

$ sudo systemctl reload haproxy

/etc/init.d/haproxy
Debian 9

#!/bin/sh
#
# chkconfig: - 85 15
# description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited \
#              for high availability environments.
# processname: haproxy
# config: /etc/haproxy/haproxy.cfg
# pidfile: /var/run/haproxy.pid

# Script Author: Simon Matter <simon.matter@invoca.ch>
# Version: 2004060600

# Source function library.
if [ -f /lib/lsb/init-functions ] ; then           
   . /lib/lsb/init-functions
else
  exit 0
fi

# Source networking configuration.
# . /etc/sysconfig/network
. /etc/network/interfaces

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

# This is our service name
BASENAME=`basename $0`
if [ -L $0 ]; then
  BASENAME=`find $0 -name $BASENAME -printf %l`
  BASENAME=`basename $BASENAME`
fi

BIN=/usr/sbin/$BASENAME

CFG=/etc/$BASENAME/$BASENAME.cfg
[ -f $CFG ] || exit 1

PIDFILE=/var/run/$BASENAME.pid
LOCKFILE=/var/lock/subsys/$BASENAME

RETVAL=0

start() {
  quiet_check
  if [ $? -ne 0 ]; then
    echo "Errors found in configuration file, check it with '$BASENAME check'."
    return 1
  fi

  echo -n "Starting $BASENAME: "
  #daemon $BIN -D -f $CFG -p $PIDFILE
  start_daemon $BIN -D -f $CFG -p $PIDFILE
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch $LOCKFILE
  return $RETVAL
}

stop() {
  echo -n "Shutting down $BASENAME: "
  killproc $BASENAME -USR1
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
  [ $RETVAL -eq 0 ] && rm -f $PIDFILE
  return $RETVAL
}

restart() {
  quiet_check
  if [ $? -ne 0 ]; then
    echo "Errors found in configuration file, check it with '$BASENAME check'."
    return 1
  fi
  stop
  start
}

reload() {
  if ! [ -s $PIDFILE ]; then
    return 0
  fi

  quiet_check
  if [ $? -ne 0 ]; then
    echo "Errors found in configuration file, check it with '$BASENAME check'."
    return 1
  fi
  $BIN -D -f $CFG -p $PIDFILE -sf $(cat $PIDFILE)
}

check() {
  $BIN -c -q -V -f $CFG
}

quiet_check() {
  $BIN -c -q -f $CFG
}

rhstatus() {
  status $BASENAME
}

condrestart() {
  [ -e $LOCKFILE ] && restart || :
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  reload)
    reload
    ;;
  condrestart)
    condrestart
    ;;
  status)
    rhstatus
    ;;
  check)
    check
    ;;
  *)
    echo $"Usage: $BASENAME {start|stop|restart|reload|condrestart|status|check}"
    exit 1
esac
 
exit $?

Another added point is that my Debian 9 does not open SELinux, which is closed.

Please see:

You should use the systemd unit file, not the old sysvinit script. Follow the procedure mentioned in that thread.

Unfortunately, I followed his solution and the result was a new error.

rm /etc/init.d/haproxy
cd contrib/systemd
make
cp haproxy.service /lib/systemd/system/
systemctl daemon-reload
systemctl enable haproxy
systemctl start haproxy
systemctl status haproxy

Error message: Failed to start HAProxy Load Balancer.

root@korea:~/haproxy/contrib/systemd# systemctl status haproxy
● haproxy.service - HAProxy Load Balancer
   Loaded: loaded (/lib/systemd/system/haproxy.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2019-08-01 16:13:44 CDT; 8s ago
  Process: 27209 ExecStart=/usr/local/sbin/haproxy -Ws -f $CONFIG -p $PIDFILE $EXTRAOPTS (code=exited, status=1/FAILURE)
  Process: 27208 ExecStartPre=/usr/local/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS (code=exited, status=0/SUCCESS)
 Main PID: 27209 (code=exited, status=1/FAILURE)

Aug 01 16:13:44 korea.vps.com systemd[1]: haproxy.service: Main process exited, code=exited, status=1/FAILURE
Aug 01 16:13:44 korea.vps.com systemd[1]: Failed to start HAProxy Load Balancer.
Aug 01 16:13:44 korea.vps.com systemd[1]: haproxy.service: Unit entered failed state.
Aug 01 16:13:44 korea.vps.com systemd[1]: haproxy.service: Failed with result 'exit-code'.
Aug 01 16:13:44 korea.vps.com systemd[1]: haproxy.service: Service hold-off time over, scheduling restart.
Aug 01 16:13:44 korea.vps.com systemd[1]: Stopped HAProxy Load Balancer.
Aug 01 16:13:44 korea.vps.com systemd[1]: haproxy.service: Start request repeated too quickly.
Aug 01 16:13:44 korea.vps.com systemd[1]: Failed to start HAProxy Load Balancer.
Aug 01 16:13:44 korea.vps.com systemd[1]: haproxy.service: Unit entered failed state.
Aug 01 16:13:44 korea.vps.com systemd[1]: haproxy.service: Failed with result 'exit-code'.
root@korea:~/haproxy/contrib/systemd# 

Error message: Failed to start HAProxy Load Balancer.

The following is the content of the haproxy.service file

[Unit]
Description=HAProxy Load Balancer
After=network.target

[Service]
EnvironmentFile=-/etc/default/haproxy
EnvironmentFile=-/etc/sysconfig/haproxy
Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid" "EXTRAOPTS=-S /run/haproxy-master.sock"
ExecStartPre=/usr/local/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS
ExecStart=/usr/local/sbin/haproxy -Ws -f $CONFIG -p $PIDFILE $EXTRAOPTS
ExecReload=/usr/local/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
SuccessExitStatus=143
Type=notify

# The following lines leverage SystemD's sandboxing options to provide
# defense in depth protection at the expense of restricting some flexibility
# in your setup (e.g. placement of your configuration files) or possibly
# reduced performance. See systemd.service(5) and systemd.exec(5) for further
# information.

# NoNewPrivileges=true
# ProtectHome=true
# If you want to use 'ProtectSystem=strict' you should whitelist the PIDFILE,
# any state files and any other files written using 'ReadWritePaths' or
# 'RuntimeDirectory'.
# ProtectSystem=true
# ProtectKernelTunables=true
# ProtectKernelModules=true
# ProtectControlGroups=true
# If your SystemD version supports them, you can add: @reboot, @swap, @sync
# SystemCallFilter=~@cpu-emulation @keyring @module @obsolete @raw-io

[Install]
WantedBy=multi-user.target

Is haproxy in /usr/local/sbin/haproxy or /usr/sbin/haproxy? Adjust the unit file if the path is incorrect.

Also provide the output of haproxy -vv and confirm that you compiled haproxy with USE_SYSTEMD=1.

Both haproxy /usr/local/sbin/haproxy and /usr/sbin/haproxy have haproxy binaries because I linked them past “ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy” But at the moment I don’t know how to solve it

root@korea:~/haproxy/contrib/systemd# haproxy -vv
HA-Proxy version 2.1-dev1-458eaf-156 2019/08/01 - https://haproxy.org/
Build options :
  TARGET  = linux-glibc
  CPU     = generic
  CC      = gcc
  CFLAGS  = -O2 -g -fno-strict-aliasing -Wdeclaration-after-statement -fwrapv -Wno-unused-label -Wno-sign-compare -Wno-unused-parameter -Wno-old-style-declaration -Wno-ignored-qualifiers -Wno-clobbered -Wno-missing-field-initializers -Wtype-limits -Wshift-negative-value -Wshift-overflow=2 -Wduplicated-cond -Wnull-dereference
  OPTIONS = USE_PCRE2_JIT=1 USE_OPENSSL=1 USE_SLZ=1

Feature list : +EPOLL -KQUEUE -MY_EPOLL -MY_SPLICE +NETFILTER -PCRE -PCRE_JIT -PCRE2 +PCRE2_JIT +POLL -PRIVATE_CACHE +THREAD -PTHREAD_PSHARED -REGPARM -STATIC_PCRE -STATIC_PCRE2 +TPROXY +LINUX_TPROXY +LINUX_SPLICE +LIBCRYPT +CRYPT_H -VSYSCALL +GETADDRINFO +OPENSSL -LUA +FUTEX +ACCEPT4 -MY_ACCEPT4 -ZLIB +SLZ +CPU_AFFINITY +TFO +NS +DL +RT -DEVICEATLAS -51DEGREES -WURFL -SYSTEMD -OBSOLETE_LINKER +PRCTL +THREAD_DUMP -EVPORTS

Default settings :
  bufsize = 16384, maxrewrite = 1024, maxpollevents = 200

Built with multi-threading support (MAX_THREADS=64, default=1).
Built with OpenSSL version : OpenSSL 1.1.1c  28 May 2019
Running on OpenSSL version : OpenSSL 1.1.1c  28 May 2019
OpenSSL library supports TLS extensions : yes
OpenSSL library supports SNI : yes
OpenSSL library supports : TLSv1.0 TLSv1.1 TLSv1.2 TLSv1.3
Built with network namespace support.
Built with transparent proxy support using: IP_TRANSPARENT IPV6_TRANSPARENT IP_FREEBIND
Built with libslz for stateless compression.
Compression algorithms supported : identity("identity"), deflate("deflate"), raw-deflate("deflate"), gzip("gzip")
Built with PCRE2 version : 10.33 2019-04-16
PCRE2 library supports JIT : yes
Encrypted password support via crypt(3): yes

Available polling systems :
      epoll : pref=300,  test result OK
       poll : pref=200,  test result OK
     select : pref=150,  test result OK
Total: 3 (3 usable), will use epoll.

Available multiplexer protocols :
(protocols marked as <default> cannot be specified using 'proto' keyword)
              h2 : mode=HTTP       side=FE|BE     mux=H2
       <default> : mode=HTTP       side=FE|BE     mux=H1
       <default> : mode=TCP        side=FE|BE     mux=PASS

Available services : none

Available filters :
        [SPOE] spoe
        [COMP] compression
        [CACHE] cache
        [TRACE] trace


But I did not use USE_SYSTEMD=1 when compiling, I will try to compile this parameter first.

1 Like

A new problem has arisen and an error occurred during compilation.

root@korea:~/haproxy# make -j $(nproc) TARGET=linux-glibc USE_SYSTEMD=1 \
>     USE_OPENSSL=1 SSL_LIB=/opt/openssl-1.1.1/lib SSL_INC=/opt/openssl-1.1.1/include ADDLIB=-lpthread
  CC      src/ev_poll.o
  CC      src/ev_epoll.o
  CC      src/ssl_sock.o
  CC      src/namespace.o
  CC      src/http_ana.o
  CC      src/cfgparse-listen.o
  CC      src/stream.o
  CC      src/mux_h2.o
  CC      src/stats.o
  CC      src/flt_spoe.o
  CC      src/server.o
  CC      src/checks.o
  CC      src/haproxy.o
src/haproxy.c:72:31: fatal error: systemd/sd-daemon.h: No such file or directory
 #include <systemd/sd-daemon.h>
                               ^
compilation terminated.
Makefile:844: recipe for target 'src/haproxy.o' failed
make: *** [src/haproxy.o] Error 1

systemd header files are needed.

apt-get update && apt-get install libsystemd-dev

Thank you so much! The problem is solved now, you are my great benefactor! Love you forever :heart:

1 Like

Thank you so much! The problem is solved now, you are my great benefactor! Love you forever :heart: