Concourse worker service readiness

systemd supports something called service readiness, it’s a way to know that the program you started has initialized and is ready to actually accept connections/run jobs/whatever. systemd then uses this state to support ordering and dependencies between services.

One way to implement that is when the program supports the sd-notify mechanism, ie. explicitly sending an “I’m ready” message to pid1, or by just forking after the initialization is done, and the process is ready (Type=notify vs Type=forking).

Does concourse support any of those? The reason I ask is, that we want to run other services after the concourse worker is actually ready to work.

currently we are running it as Type=simple, which makes the service “active/ready” as soon the process is started:

[Service]
Type=simple
User=root
Group=root
ExecStart=/opt/concourse/bin/concourse worker …

ps. some more info can be found at:
https://www.freedesktop.org/software/systemd/man/daemon.html
https://www.freedesktop.org/software/systemd/man/sd_notify.html
https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type=

I’ve come up with half a hack by having an ExecStartPost= script that checks the worker healthcheck url to succeed. This delays the readiness of the systemd service until the worker is healthy.

the script:

#! /bin/bash
# default values, if the environment variables don't exist
: ${CONCOURSE_HEALTHCHECK_BIND_PORT:=8888}
: ${CONCOURSE_HEALTHCHECK_BIND_IP:=127.0.0.1}
: ${CONCOURSE_HEALTHCHECK_URL:=http://$CONCOURSE_HEALTHCHECK_BIND_IP:$CONCOURSE_HEALTHCHECK_BIND_PORT/}

until curl --fail --silent $CONCOURSE_HEALTHCHECK_URL; do
    sleep 0.5;
done

the change in concourse-worker.service

[Service]
Type=simple
…
ExecStartPost=/usr/local/bin/concourse-is-ready.sh