0

I am trying to execute the script with systemd and below is the service definition I am using but, the script is not running before the reboot occurs:

[Unit]
Description=Before Shutting Down
Before=reboot.target
RequiresMountsFor=/home

[Service]
Type=oneshot
User=oracle
ExecStart=/home/oracle/scripts/stop_db.sh
RemainAfterExit=yes

[Install]
WantedBy=reboot.target

Any luck please? Went through multiple solutions suggested without any luck.

Service status:

● dbstop.service - Before Shutting Down
   Loaded: loaded (/etc/systemd/system/dbstop.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
2
  • Does the script in the service work if run on its own? Commented May 4, 2022 at 1:56
  • Yes the script works fine. Even if I start the service using systemctl command then also it works fine and database gets shut down. Commented May 4, 2022 at 5:22

1 Answer 1

1

Why don't you start and stop the DB as a service and let systemd do the rest?

[Unit]
Description=myDB
After=network-online.target nss-lookup.target
Wants=network-online.target nss-lookup.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/home/oracle/scripts/start_db.sh
ExecStop=/home/oracle/scripts/stop_db.sh

[Install]
WantedBy=multi-user.targetYM
3
  • Thank you. Tried this as well but, did not work. Commented May 4, 2022 at 8:05
  • Why didn’t it work? This is the correct way of doing things.
    – jsbillings
    Commented May 5, 2022 at 0:46
  • ok it did not work Commented May 6, 2022 at 6:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .