2

I am using haproxy for load balancing mysql.Haproxy is running on Ubuntu 14.04 .I have set ENABLED=1 in /etc/defaults/haproxy file. But when restarted, haproxy doesn't start as daemon. The configuration file looks like this:

global
    daemon

defaults
    log global
    retries 2
    timeout connect 3000
    timeout server 5000
    timeout client 5000



frontend mysql_read
    mode tcp
    bind *.*.*.*:3308
    default_backend cluster_db_read

backend cluster_db_read
    mode tcp
    option tcpka
    option mysql-check user haproxy_check
    balance roundrobin
     server s1 *.*.*.*:3306 check
    server s2 *.*.*.*:3306 check backup 


listen stats
    bind 0.0.0.0:8080
    mode http
    stats enable
    stats uri /
    stats realm Strictly\ Private
    stats auth user:password
#stats auth Another_User:passwd
#stats auth Another_User:passwd

The output of sudo netstat -tulpn is as follows

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1078/mysqld
tcp 0 0 192.168.1.102:3308 0.0.0.0:* LISTEN 1834/haproxy
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1834/haproxy
tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN 1557/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 913/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2145/cupsd
tcp6 0 0 :::22 :::* LISTEN 913/sshd
tcp6 0 0 ::1:631 :::* LISTEN 2145/cupsd
udp 0 0 0.0.0.0:56175 0.0.0.0:* 803/avahi-daemon: r udp 0 0 0.0.0.0:39839 0.0.0.0:* 1292/dhclient
udp 0 0 127.0.1.1:53 0.0.0.0:* 1557/dnsmasq
udp 0 0 0.0.0.0:68 0.0.0.0:* 1292/dhclient
udp 0 0 0.0.0.0:631 0.0.0.0:* 958/cups-browsed udp 0 0 0.0.0.0:5353 0.0.0.0:* 803/avahi-daemon: r udp6 0 0 :::53961 :::* 803/avahi-daemon: r udp6 0 0 :::5353 :::* 803/avahi-daemon: r udp6 0 0 :::22178 :::* 1292/dhclient

What changes should be made to make haproxy as a daemon service?

user3615045
  • 146
  • 1
  • 6

1 Answers1

0

Not sure which version of ubuntu since this is a old post, but for anyone else who wants to accomplish this on ubuntu 18.04 or Ubuntu 18.10

To make the HAProxy service persist through reboots, enter the following command:

systemctl enable haproxy.service

Reboot your machine

Login & Check if HAProxy is running on boot.

To check the status of HAProxy Type:

service haproxy status

Check your output for active / running status: (Active: active (running)) If its active & running, then your HAProxy is Working on System Boot. Output will also point out any errors you can fix in your config even if its active.

You can also check if HAProxy is running via netstat:

netstat -tulpn