What if Life is…?

What If Life is a collective avatar of almost an infinite number of individuals whose infinitely contradictive number of commands/decisions towards that avatar result in what we think is “free will”. These “video game” players sharing the avatar seem to like creating mathematical laws while playing this game, we’re talking about the ones responsible for the laws of physics to keep the universe going for ever.

Now imagine each one of those guys is a shared avatar too.
Putting the infinite into something small feels good in the brain.

Have the latest HAProxy as a Ubuntu Service

So you need to use HAProxy and you love the convenience of binary packages on repos, but when you install the version HAProxy available in the repos you realize that it is way too old for what you need.

Then you download the latest HAProxy, compile it, configure it, but it’s a bit of a pain in the ass to not have the convenience of having haproxy be automatically restarted as a service like those available on /etc/init.d

This post teaches you how to have haproxy as a Ubuntu/Debian service.

First copy or symlink this script to your /etc/init.d/ folder (you’ll need root permissions to do this)

#!/usr/bin/env bash
# haproxyd
# Script to start|stop|restart haproxy from /etc/init.d/
# By Gubatron.


test -x $HAPROXY_DAEMON || exit 0

set -e

function getHaproxyPID() {
PID=`ps aux | grep ‘haproxy -f’ | grep -v "grep" | awk ‘{ print $2 }’`

case $1 in
echo "Starting haproxy…"
echo "Hot restart of haproxy"
echo "Stopping haproxy"
COMMAND="kill -9 $PID"
echo "Usage: haproxyd {start|restart|stop}" >&2
exit 1

exit 0

This script, on it’s own can be used as
./haproxyd start
./haproxyd restart
./haproxyd stop

But you want this script registered on all the right runlevels of the operating system.

With Ubuntu/Debian there’s a utility called update-rc.d to register /etc/init.d/ scripts very easily.

Once the script above is available on /etc/init.d do the following

cd /etc/init.d
sudo update-rc.d haproxyd defaults

The script should now be registered on all the right runlevels and you should be able to invoke it as a service like

sudo service haproxyd <command>