How can I use Monit to monitor a service that does not have a /var/run/ pid file or how can I create a pid...












0















I am using Debian 9.8



I have a service that runs my dotnet program. I would like to monitor it with monit but in all of the examples, you need to reference a .pid file in /var/run but my dotnet program doesn't have a .pid file in /var/run.



So I added PIDFile=/var/run/testservice.pid to the .service file for my service but it does not create the file when I start it.



This is where I am at



this is my .service file



[Unit]
Description=Test Service
Wants=network-online.target influxdb.service
After=network-online.target influxdb.service

[Service]
User=testservice
Group=mainapp
SyslogIdentifier=testservice
PIDFile=/var/run/testservice.pid

Restart=on-failure
TimeoutStopSec=5
RestartSec=10

ExecStart=/usr/bin/dotnet /mainapp/app/TestSystemdService.dll

[Install]
WantedBy=multi-user.target









share|improve this question





























    0















    I am using Debian 9.8



    I have a service that runs my dotnet program. I would like to monitor it with monit but in all of the examples, you need to reference a .pid file in /var/run but my dotnet program doesn't have a .pid file in /var/run.



    So I added PIDFile=/var/run/testservice.pid to the .service file for my service but it does not create the file when I start it.



    This is where I am at



    this is my .service file



    [Unit]
    Description=Test Service
    Wants=network-online.target influxdb.service
    After=network-online.target influxdb.service

    [Service]
    User=testservice
    Group=mainapp
    SyslogIdentifier=testservice
    PIDFile=/var/run/testservice.pid

    Restart=on-failure
    TimeoutStopSec=5
    RestartSec=10

    ExecStart=/usr/bin/dotnet /mainapp/app/TestSystemdService.dll

    [Install]
    WantedBy=multi-user.target









    share|improve this question



























      0












      0








      0








      I am using Debian 9.8



      I have a service that runs my dotnet program. I would like to monitor it with monit but in all of the examples, you need to reference a .pid file in /var/run but my dotnet program doesn't have a .pid file in /var/run.



      So I added PIDFile=/var/run/testservice.pid to the .service file for my service but it does not create the file when I start it.



      This is where I am at



      this is my .service file



      [Unit]
      Description=Test Service
      Wants=network-online.target influxdb.service
      After=network-online.target influxdb.service

      [Service]
      User=testservice
      Group=mainapp
      SyslogIdentifier=testservice
      PIDFile=/var/run/testservice.pid

      Restart=on-failure
      TimeoutStopSec=5
      RestartSec=10

      ExecStart=/usr/bin/dotnet /mainapp/app/TestSystemdService.dll

      [Install]
      WantedBy=multi-user.target









      share|improve this question
















      I am using Debian 9.8



      I have a service that runs my dotnet program. I would like to monitor it with monit but in all of the examples, you need to reference a .pid file in /var/run but my dotnet program doesn't have a .pid file in /var/run.



      So I added PIDFile=/var/run/testservice.pid to the .service file for my service but it does not create the file when I start it.



      This is where I am at



      this is my .service file



      [Unit]
      Description=Test Service
      Wants=network-online.target influxdb.service
      After=network-online.target influxdb.service

      [Service]
      User=testservice
      Group=mainapp
      SyslogIdentifier=testservice
      PIDFile=/var/run/testservice.pid

      Restart=on-failure
      TimeoutStopSec=5
      RestartSec=10

      ExecStart=/usr/bin/dotnet /mainapp/app/TestSystemdService.dll

      [Install]
      WantedBy=multi-user.target






      systemd pid monit






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 27 at 15:31







      TheColonel26

















      asked Feb 27 at 15:17









      TheColonel26TheColonel26

      1149




      1149






















          2 Answers
          2






          active

          oldest

          votes


















          2














          If all you want is to know whether the service is running, you can query systemd:



          systemctl is-active TestApp.service


          You can also check whether it is inactive specifically due to a known failure:



          systemctl is-failed TestApp.service


          According to docs, this can be incorporated into monit as check program … with path:



          check program TestApp with path "systemctl --quiet is-active TestApp"
          if status != 0 then ...




          Note that systemd's PIDFile= is for telling init where to read the PID from. If the daemon itself doesn't create a pidfile, systemd certainly won't bother. If you really need one, you could have an ExecStartPost=/bin/sh -c "echo $MAINPID > /run/testapp.pid" or something similar.






          share|improve this answer































            1














            Monit have an option for matching processes using regex as well.



            So , first you would do from shell: (for testing)



            monit procmatch 'program'



            It will match process with highest uptime.
            Then you can add in monit configuration :



            check process myprogram matching 'progr.*'
            start program = /bin/app
            stop program = something..





            share|improve this answer
























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              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',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1409899%2fhow-can-i-use-monit-to-monitor-a-service-that-does-not-have-a-var-run-pid-file%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              If all you want is to know whether the service is running, you can query systemd:



              systemctl is-active TestApp.service


              You can also check whether it is inactive specifically due to a known failure:



              systemctl is-failed TestApp.service


              According to docs, this can be incorporated into monit as check program … with path:



              check program TestApp with path "systemctl --quiet is-active TestApp"
              if status != 0 then ...




              Note that systemd's PIDFile= is for telling init where to read the PID from. If the daemon itself doesn't create a pidfile, systemd certainly won't bother. If you really need one, you could have an ExecStartPost=/bin/sh -c "echo $MAINPID > /run/testapp.pid" or something similar.






              share|improve this answer




























                2














                If all you want is to know whether the service is running, you can query systemd:



                systemctl is-active TestApp.service


                You can also check whether it is inactive specifically due to a known failure:



                systemctl is-failed TestApp.service


                According to docs, this can be incorporated into monit as check program … with path:



                check program TestApp with path "systemctl --quiet is-active TestApp"
                if status != 0 then ...




                Note that systemd's PIDFile= is for telling init where to read the PID from. If the daemon itself doesn't create a pidfile, systemd certainly won't bother. If you really need one, you could have an ExecStartPost=/bin/sh -c "echo $MAINPID > /run/testapp.pid" or something similar.






                share|improve this answer


























                  2












                  2








                  2







                  If all you want is to know whether the service is running, you can query systemd:



                  systemctl is-active TestApp.service


                  You can also check whether it is inactive specifically due to a known failure:



                  systemctl is-failed TestApp.service


                  According to docs, this can be incorporated into monit as check program … with path:



                  check program TestApp with path "systemctl --quiet is-active TestApp"
                  if status != 0 then ...




                  Note that systemd's PIDFile= is for telling init where to read the PID from. If the daemon itself doesn't create a pidfile, systemd certainly won't bother. If you really need one, you could have an ExecStartPost=/bin/sh -c "echo $MAINPID > /run/testapp.pid" or something similar.






                  share|improve this answer













                  If all you want is to know whether the service is running, you can query systemd:



                  systemctl is-active TestApp.service


                  You can also check whether it is inactive specifically due to a known failure:



                  systemctl is-failed TestApp.service


                  According to docs, this can be incorporated into monit as check program … with path:



                  check program TestApp with path "systemctl --quiet is-active TestApp"
                  if status != 0 then ...




                  Note that systemd's PIDFile= is for telling init where to read the PID from. If the daemon itself doesn't create a pidfile, systemd certainly won't bother. If you really need one, you could have an ExecStartPost=/bin/sh -c "echo $MAINPID > /run/testapp.pid" or something similar.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 27 at 16:17









                  grawitygrawity

                  242k37512568




                  242k37512568

























                      1














                      Monit have an option for matching processes using regex as well.



                      So , first you would do from shell: (for testing)



                      monit procmatch 'program'



                      It will match process with highest uptime.
                      Then you can add in monit configuration :



                      check process myprogram matching 'progr.*'
                      start program = /bin/app
                      stop program = something..





                      share|improve this answer




























                        1














                        Monit have an option for matching processes using regex as well.



                        So , first you would do from shell: (for testing)



                        monit procmatch 'program'



                        It will match process with highest uptime.
                        Then you can add in monit configuration :



                        check process myprogram matching 'progr.*'
                        start program = /bin/app
                        stop program = something..





                        share|improve this answer


























                          1












                          1








                          1







                          Monit have an option for matching processes using regex as well.



                          So , first you would do from shell: (for testing)



                          monit procmatch 'program'



                          It will match process with highest uptime.
                          Then you can add in monit configuration :



                          check process myprogram matching 'progr.*'
                          start program = /bin/app
                          stop program = something..





                          share|improve this answer













                          Monit have an option for matching processes using regex as well.



                          So , first you would do from shell: (for testing)



                          monit procmatch 'program'



                          It will match process with highest uptime.
                          Then you can add in monit configuration :



                          check process myprogram matching 'progr.*'
                          start program = /bin/app
                          stop program = something..






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Feb 27 at 19:49









                          fugitivefugitive

                          12019




                          12019






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1409899%2fhow-can-i-use-monit-to-monitor-a-service-that-does-not-have-a-var-run-pid-file%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Index of /

                              Tribalistas

                              Listed building