Why does systemd stop my service but not restart it?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
0
down vote

favorite












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?










share|improve this question



























    up vote
    0
    down vote

    favorite












    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?










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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?










      share|improve this question















      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?







      services systemd






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 27 at 23:10

























      asked Feb 26 at 23:08









      Medo42

      1011




      1011




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          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.






          share|improve this answer




















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










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1010107%2fwhy-does-systemd-stop-my-service-but-not-restart-it%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          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.






          share|improve this answer




















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














          up vote
          0
          down vote













          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.






          share|improve this answer




















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












          up vote
          0
          down vote










          up vote
          0
          down vote









          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 26 at 23:36









          augustin vm

          234




          234











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
















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















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




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

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1010107%2fwhy-does-systemd-stop-my-service-but-not-restart-it%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          pylint3 and pip3 broken

          Missing snmpget and snmpwalk

          How to enroll fingerprints to Ubuntu 17.10 with VFS491