RHEL 7を再起動する前に、データベース終了スクリプトを実行する必要があります。

RHEL 7を再起動する前に、データベース終了スクリプトを実行する必要があります。

systemdを使用してスクリプトを実行しようとしています。以下は私が使用しているサービス定義ですが、再起動するまでスクリプトは実行されません。

[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

頑張ってますか?複数の提案ソリューションを試しましたが、運がありませんでした。

サービスステータス:

● dbstop.service - Before Shutting Down
   Loaded: loaded (/etc/systemd/system/dbstop.service; enabled; vendor preset: disabled)
   Active: inactive (dead)

ベストアンサー1

データベースをサービスとして開始および停止し、systemdに残りのタスクを実行させることはどうですか?

[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

おすすめ記事