I have a service which depends on mysql.service via Requires=
. This is necessary, because the service crashes, if mysql is not available.
Executing systemctl restart mysql
works fine. It stops my service first, restarts mysql and starts my service again.
How can I configure my unit, that it is also started again, if I run systemctl stop mysql && systemctl start mysql
?
This is especially a problem during debian’s unattended-upgrades of mysql, because the update-process uses stop
/start
and not restart
.
Best Answer
new and better answer
Clearly i have not been reading well yesterday. It seems your problem can easily be solved by adding
mysql.service
to your servicesWantedBy
under the[Install]
section.then after you reenable your service, it should be started whenever
mysql.service
is started, as long as your service is enabledthe result looks like this:
my old answer for reference:
I don't know if it is possible to configure your unit to behave the way you want it to.
I have, however, solved similar problems by installing systemd drop-in files to modify the foreign unit, in your case
mysql.service
.assuming your unit is
foo.service
you could create a.conf
file in/etc/systemd/system/mysql.service.d/
with the following content:this would cause systemd to try and start
foo.service
after every start ofmysql.service
for completeness sake, and to quote systemd documentation: