Elegant way to have systemd user service wait for mysqld to be available on startup

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











up vote
0
down vote

favorite












I have a server on which I am running a daemon as a normal user. I intend to give access to this user in the future to people I trust... but, as a precaution, I would like any configuration and management to be done without su or sudo access. For this reason I've written a simple systemd user unit and tested that it works. It does.



The problem is when restarting the server. The systemd attempts to start the daemon before mariadb (which this daemon needs) is ready. This causes the daemon to fail repeatedly until it exceeds systemd's StartLimit and systemd stops attempting to start the daemon all together.



There are a number of approaches I could take with this. I could re-write the systemd unit to run a script that queries the sql server over and over till it gets a connection and only then attempts to launch the daemon. Or I could add to the systemd unit a timeout between restarts of say... 30 seconds? But both feel... messy... pedestrian. I'd rather a more elegant solution.



I've been looking over the manpages of systemd but... there's a lot there. Any thoughts?



The unit file in question:



[Unit]
Description=Teamspeak 3

[Service]
Type=forking
#User=teamspeak
#Group=teamspeak
UMask=0027
Restart=always
WorkingDirectory=/home/teamspeak/ts
PIDFile=/home/teamspeak/ts/ts3server.pid
ExecStart=/home/teamspeak/ts/ts3server_startscript.sh start inifile=/home/teamspeak/ts/ts3server.ini
ExecStop=/home/teamspeak/ts/ts3server_startscript.sh stop
ExecReload=/home/teamspeak/ts/ts3server_startscript.sh restart

[Install]
WantedBy=default.target








share

























    up vote
    0
    down vote

    favorite












    I have a server on which I am running a daemon as a normal user. I intend to give access to this user in the future to people I trust... but, as a precaution, I would like any configuration and management to be done without su or sudo access. For this reason I've written a simple systemd user unit and tested that it works. It does.



    The problem is when restarting the server. The systemd attempts to start the daemon before mariadb (which this daemon needs) is ready. This causes the daemon to fail repeatedly until it exceeds systemd's StartLimit and systemd stops attempting to start the daemon all together.



    There are a number of approaches I could take with this. I could re-write the systemd unit to run a script that queries the sql server over and over till it gets a connection and only then attempts to launch the daemon. Or I could add to the systemd unit a timeout between restarts of say... 30 seconds? But both feel... messy... pedestrian. I'd rather a more elegant solution.



    I've been looking over the manpages of systemd but... there's a lot there. Any thoughts?



    The unit file in question:



    [Unit]
    Description=Teamspeak 3

    [Service]
    Type=forking
    #User=teamspeak
    #Group=teamspeak
    UMask=0027
    Restart=always
    WorkingDirectory=/home/teamspeak/ts
    PIDFile=/home/teamspeak/ts/ts3server.pid
    ExecStart=/home/teamspeak/ts/ts3server_startscript.sh start inifile=/home/teamspeak/ts/ts3server.ini
    ExecStop=/home/teamspeak/ts/ts3server_startscript.sh stop
    ExecReload=/home/teamspeak/ts/ts3server_startscript.sh restart

    [Install]
    WantedBy=default.target








    share























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a server on which I am running a daemon as a normal user. I intend to give access to this user in the future to people I trust... but, as a precaution, I would like any configuration and management to be done without su or sudo access. For this reason I've written a simple systemd user unit and tested that it works. It does.



      The problem is when restarting the server. The systemd attempts to start the daemon before mariadb (which this daemon needs) is ready. This causes the daemon to fail repeatedly until it exceeds systemd's StartLimit and systemd stops attempting to start the daemon all together.



      There are a number of approaches I could take with this. I could re-write the systemd unit to run a script that queries the sql server over and over till it gets a connection and only then attempts to launch the daemon. Or I could add to the systemd unit a timeout between restarts of say... 30 seconds? But both feel... messy... pedestrian. I'd rather a more elegant solution.



      I've been looking over the manpages of systemd but... there's a lot there. Any thoughts?



      The unit file in question:



      [Unit]
      Description=Teamspeak 3

      [Service]
      Type=forking
      #User=teamspeak
      #Group=teamspeak
      UMask=0027
      Restart=always
      WorkingDirectory=/home/teamspeak/ts
      PIDFile=/home/teamspeak/ts/ts3server.pid
      ExecStart=/home/teamspeak/ts/ts3server_startscript.sh start inifile=/home/teamspeak/ts/ts3server.ini
      ExecStop=/home/teamspeak/ts/ts3server_startscript.sh stop
      ExecReload=/home/teamspeak/ts/ts3server_startscript.sh restart

      [Install]
      WantedBy=default.target








      share













      I have a server on which I am running a daemon as a normal user. I intend to give access to this user in the future to people I trust... but, as a precaution, I would like any configuration and management to be done without su or sudo access. For this reason I've written a simple systemd user unit and tested that it works. It does.



      The problem is when restarting the server. The systemd attempts to start the daemon before mariadb (which this daemon needs) is ready. This causes the daemon to fail repeatedly until it exceeds systemd's StartLimit and systemd stops attempting to start the daemon all together.



      There are a number of approaches I could take with this. I could re-write the systemd unit to run a script that queries the sql server over and over till it gets a connection and only then attempts to launch the daemon. Or I could add to the systemd unit a timeout between restarts of say... 30 seconds? But both feel... messy... pedestrian. I'd rather a more elegant solution.



      I've been looking over the manpages of systemd but... there's a lot there. Any thoughts?



      The unit file in question:



      [Unit]
      Description=Teamspeak 3

      [Service]
      Type=forking
      #User=teamspeak
      #Group=teamspeak
      UMask=0027
      Restart=always
      WorkingDirectory=/home/teamspeak/ts
      PIDFile=/home/teamspeak/ts/ts3server.pid
      ExecStart=/home/teamspeak/ts/ts3server_startscript.sh start inifile=/home/teamspeak/ts/ts3server.ini
      ExecStop=/home/teamspeak/ts/ts3server_startscript.sh stop
      ExecReload=/home/teamspeak/ts/ts3server_startscript.sh restart

      [Install]
      WantedBy=default.target






      systemd systemd-boot





      share












      share










      share



      share










      asked 2 mins ago









      Cliff Armstrong

      2261210




      2261210

























          active

          oldest

          votes











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          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: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2funix.stackexchange.com%2fquestions%2f477867%2felegant-way-to-have-systemd-user-service-wait-for-mysqld-to-be-available-on-star%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f477867%2felegant-way-to-have-systemd-user-service-wait-for-mysqld-to-be-available-on-star%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?