The sed invocation was changing all lines matching "local daemon.*". This changed the line it was supposed to, but two other lines that also matched that pattern were being modified, which meant that the "daemon_pid_var" and "daemon_pid" variables were not defined when they should have been.