I need to execute a script during shutdown/termination of an AWS instance(debian). I added my script to the /etc/init.d/myscript and a symlink to /etc/rc0.d/K01myscript however I noticed that when I terminate the instance I don't see that my script is executed. Any idea?
1 Answer
So I use systemd for the sensu client service
If this is indeed so, then you do not use init scripts at all. All you need to do is to add the two following lines to your systemd service:
RemainAfterExit=yes
ExecStop=/path/to/executable/script
The first option instructs systemd to treat the service as a daemon, i.e. to treat it as running even though all processes have died already; the second instruction points systemd to the cleanup script, which you will have to provide.
~
references, or programs that are expected to be in the path? May have to explicitly state the location of whatever needs to run.