Score:1

How do I make systemd wait for a service to finish shutdown before shutting down another one?

us flag

I have two services: mysql and liferay. Liferay start depends on mysql but liferay's shutdwon also depends on mysql. The problem is that systemd will shutdown mysql before liferay's shutdown is over. When I run "systemctl stop mysql" it will start shutting down both services at the same time and liferay will have no mysql service to finish it's own shutdown.

I have Liferay's service declared like this:

[Unit]
Description=Liferay Portal
After=network.target,mysql.service
Requires=mysql.service

[Service]
Type=forking
WorkingDirectory=/opt/liferay
ExecStart=/opt/liferay/liferay-ce-portal/tomcat/bin/startup.sh
User=liferay
Group=liferay
Restart=always

[Install]
WantedBy=multi-user.target

Any ideas?

TIA

Fernando

in flag
According to [this quote from the docs](https://serverfault.com/questions/785127/how-to-stop-systemd-services-in-specific-order) `After=` should do the trick. I'd try removing the `Requires=` directive, it may override the `After=` behavior.
Score:0
us flag

As per Gerald's comment, it seems the answer is simply to remove the "Requires=".

This version does the trick:

[Unit]
Description=Liferay Portal
After=mysql.service

[Service]
Type=forking
WorkingDirectory=/opt/liferay
ExecStart=/opt/liferay/liferay-ce-portal/tomcat/bin/startup.sh
User=liferay
Group=liferay
Restart=always

[Install]
WantedBy=multi-user.target

Thanks Gerald!

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.