Ubuntu: How can I execute command on shutdown (rc.local alternative) on Ubuntu?


I have some complicated database processes that I need to be able to shut down on power-loss, so as to avoid database corruption. In the good-old days of sysv, it was enough to put these scripts into /etc/init.d/rc.local but I can't find the equivalent for systemd. I hand-created the following rc-local-shutdown.service:

[Unit]  Description=/etc/rc.local.shutdown Compatibility  ConditionFileIsExecutable=/etc/rc.local.shutdown  DefaultDependencies=no  After=rc-local.service basic.target  Before=shutdown.target    [Service]  ExecStop=/etc/rc.local.shutdown  StandardInput=tty  RemainAfterExit=yes    [Install]  WantedBy=shutdown.target  

but I can't seem to actually get this to trigger and run. Fixed. I had preciously added a Type=oneshot clause, and this made the script not run. The above does seem to work when I test with systemctl stop rc-local-shutdown.service. I have not yet tested the far-more scary concept of actually powering off the system in question, though.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »