First, the issue manifests itself only on Debian systems. The runit
runit_service provider will write an
LSB init.d script on
Debian, rather than symlinking to
/usr/bin/sv. The problem raised in
the new ticket is that the template will follow the link and write to
/usr/bin/sv. This is bad, as it will end up in a forkbomb as
runsvdir attempts to restart sv on
all the things.
Oops! Sorry about that. Let’s get it fixed, and practice some TDD.
The runit cookbook includes support for test-kitchen, though I did
for this effort. Part of this change was adding a box for Debian in
.kitchen.yml. I set about resolving this with TDD in mind.
First, the runit cookbook includes a couple
to facilitate setting up the system with the
so the outcome can be tested to ensure the behavior is correct. I
started by adding a “failing test” in the
recipe, meaning a link resource, and a
runit_service resource that
1 2 3 4 5 6 7
Then I ran
kitchen test on the Debian box. As expected, the link was
created, and then the runit service was configured. The service’s
provider will wait until the service is up. Since we’ve destroyed the
sv binary, that will never happen, so I destroyed it. I manually
confirmed the behavior too, to make sure I wasn’t seeing something
weird. Due to its very nature, this is really hard to test for
automatically, but it will happen consistently.
Next, I had to write the code to implement the fix for this bug.
Essentially, this means checking if the
is a symbolink link, and removing it.
Simple enough. Next I tested again by destroying the existing environment and rerunning it from scratch. This takes some time, but it verifies that everything is working properly. Here’s the output on Debian:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
I didn’t feel I needed a specific test for this in minitest-chef, because it wouldn’t have finished converging (earlier behavior I saw in the “failing” test).
If you’re contributing to cookbooks, and they have support for test-kitchen, it’s awesome if you can open a bug report with a failing test. In this case, it was fairly easy to reproduce the bug.