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...
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
add a comment |
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
add a comment |
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
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
systemd pid monit
edited Feb 27 at 15:31
TheColonel26
asked Feb 27 at 15:17
TheColonel26TheColonel26
1149
1149
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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..
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Feb 27 at 16:17
grawitygrawity
242k37512568
242k37512568
add a comment |
add a comment |
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..
add a comment |
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..
add a comment |
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..
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..
answered Feb 27 at 19:49
fugitivefugitive
12019
12019
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
