Bunch of fixes observed during hot standby testing, fixing memory leaks, and tidying API

WIP - FOR REVIEW ONLY.

just discovered one bug i can't seem to track down, where service_up does not recompute itself as true
I think it's simpler to use `<%- defaultValue %>` (which instructs the templater to escape values) rather than including `_.escape`.