Reputation: 18022
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.
Upvotes: 0
Views: 575
Reputation: 4989
Your setup suggests that you use sysv init and not yet systemd. If this is the case, read on. Otherwise ignore this answer.
In general, you will have a link like S20foo
in /etc/rc.d/rc3.d
. The 20 and 3 may be different for you. Normally, you would create a script /etc/init.d.pre_foo
that gets your extra config and link it to /etc/rc.d/rc3.d/S19pre_foo
. This will start pre_foo
before foo
.
Upvotes: 1