1

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.

Run a shutdown script

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.

  • Have you enabled the systemd service after you created the .service file? – muru Dec 19 '17 at 6:06
  • I ran systemctl daemon-reload and systemctl enable shutdownDB commands after saving the service file. It created the symlinks in the want files. – Harley Frank Dec 19 '17 at 6:08
  • Try this instead: unix.stackexchange.com/a/41756/70524 – muru Dec 19 '17 at 6:10
  • Thank you for the link. I tried all the variations listed and it's still not executing. I am trying to see if I can find a log file to shed some light on this. – Harley Frank Dec 19 '17 at 6:47
  • journalctl -u shutdownDB.service might help in that – muru Dec 19 '17 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.