I have a system service, foo
that is started and stopped via /usr/sbin/service restart foo
. It in turn appears to be controlled by a shell script /etc/init.d/foo
How can I create a "pre-start" hook, so that I can run an extra shell script prior to this service starting? In this case, the pre-start hook is extra config that has to be fetched from a cloud provider metadata catalog, and then jacked into a configuration file necessary for foo
to start properly.
I have considered modifying /etc/init.d/foo
directly, which would work. But which would complicate expected frequent patch-level upgrades which I will catch by apt-get upgrade
. I want to avoid a solution that requires re-establishing the hook.
A second option is that I could create a fooWrapper
service, remove foo
from all run levels, and then just start/stop fooWrapper
. The implementation of that script would just be my secret sauce + invoking /etc/init.d/foo
. The trouble with that is again package upgrades, whether foo
would re-insert itself into the various runlevels, and I would then end up running two conflicting copies.