plist to install haproxy as macOS launchd service

In this tutorial I am showing how to configure haproxy to run as system service under macOS Sierra, using launchd. This allows routing all traffic to apache that is running in user-space on port 8080 (so I don't have to restart/reload using sudo). Install haproxy using Homebrew (brew install haproxy), then create as root a new file /Library/LaunchDaemons/homebrew.mxcl.haproxy.plist with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Enable and launch the service with the usual command during start, then forget about it:

sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.haproxy.plist
sudo launchctl unload -w /Library/LaunchDaemons/homebrew.mxcl.haproxy.plist

The haproxy 1.7 configuration to route all traffic to apache looks like this:

    maxconn 25

    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

    listen http-in
        bind *:80
        server server1 maxconn 25


Bonus: replacing <string>-db</string> with <string>-d</string> enables verbose logging in /usr/local/var/log/haproxy.log.