0

I am having some problems understanding the ideas behind systemd. What I am trying to do is configure a service which should normally run, and that depends on mariadb to work properly. Here is the (anonymized) .service file that I came up with:

[Unit]
Description=My Service
Requires=mariadb.service
After=mariadb.service

[Service]
ExecStart=/usr/bin/python2.7 -u /home/serviceuser/service.py
WorkingDirectory=/home/serviceuser
User=serviceuser

[Install]
WantedBy=multi-user.target

It worked well enough, but I noticed that sometimes the service would spontaneously stop. After some debugging I figured out that this coincided with mariadb security updates being installed automatically by ubuntu. Testing this, I found out that stopping mariadb will stop my service first (which makes sense to me) but starting mariadb back up again will not start my service.

I would expect that the WantedBy means that multi-user.target would really like My Service to run. So systemd should try to ensure that it runs whenever there is nothing that would prevent that. Things that would prevent it would be that the service or one of its dependencies was explicitly stopped. As soon as that preventing condition goes away, systemd should start the service again.

What is the mistake in this reasoning that leads to the service NOT being started again? How can I achieve the behavior I want with systemd?

0

mariadb is set as dependency of My Service so starting it will also launch mariadb if not running. Consequently stopping mariadb also stop My Service.

But if you only restart mariadb My Service will not be started automatically. You may like to enable My Service: systemctl enable My\ Service.service That will configure it to be started after booting up. But if I'm right stopping it shall keep it stopped until reboot or manual restart.

  • Thank you, but that only reiterates what I already found out. It does not actually answer either of the two questions. – Medo42 Feb 27 '18 at 22:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.