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

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



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


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.


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..

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.