I have several services that need to be manually saved and shutdown before the server does a reboot or shutdown. I enter them manually by using a script. I was trying to figure out if I can do it automatically before the system goes down.
Execute a script upon logout/reboot/shutdown in Ubuntu
https://www.tecmint.com/auto-execute-linux-scripts-during-reboot-or-startup/
The links above I tried and it hasn't succeeded. I was able to run the startup script via rc.local but the shutdown script doesn't run for some reason.
Here is my shutdown script if it was written as a systemd
/etc/systemd/system/shutdownDB.service
[Unit]
Description=Runs the Database Shutdown Proceedures.
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target
[Service]
Type=oneshot
ExecStart=/scripts/shutdownDB
[Install]
WantedBy=halt.target reboot.target shutdown.target
I have placed the same file in both the rc0.d and the rc6.d using S99shutdownDB or K99shutdownDB. Inside the file is bash /scripts/shutdownDB.sh and then exit 0.
I think I am missing something else or I am not properly doing this correctly. Any help would be appreciative.
Update 12-19-2017
I created shutdown and restart scripts in my /scripts folder. Inside will run the commands needed and then either perform a restart or a shutdown depending on what is used. It's better to run one script rather than three. This is a band-aid solution though. I really would like to know how to get this to work properly.
journalctl -u shutdownDB.service
might help in that – muru Dec 19 '17 at 06:47