Using Monit to monitor a custom daemon - daemon

I created a daemon using the System_Daemon pear package. How do I use Monit to restart the daemon when it fails.
I have the following code that was going to place in the monit config gile:
check process merge with pidfile /var/www/merge/merge.pid
group 1000
start program = "/etc/init.d/merge start"
stop program = "/etc/init.d/merge stop"
if failed host IPADDRESS port 80
then restart
if 5 restarts within 5 cycles then timeout
Is that the right way to monitor a custom daemon?

I'd say it looks quite correct.
If you ask, I guess it is because you are facing issues. Can you elaborate?

Related

How can I program an automatic restart of a process in a cgroup of systemctl?

I have an apache2 systemctl service running on my server. It has a bunch of subprocess in grouped in a Cgroup. If the server gets a bigger workload it can happen that one process fails. In particular it is /usr/sbin/fcgi-pm (I am running a Genome Browse (Gbrowse2)).
I want that the process restarts itself if it fails. It works fine, if I restart the Apache2 service again. However, I need to do it manually. Were is the setting of Apache2/ Systemctl that I can order a restart on failure of a subprocess?
Thanks in advance guys.

Supervisor kills Prefect agent with SIGTERM unexpectedly

I'm using a rapsberry pi 4, v10(buster).
I installed supervisor per the instructions here: http://supervisord.org/installing.html
Except I changed "pip" to "pip3" because I want to monitor running things that use the python3 kernel.
I'm using Prefect, and the supervisord.conf is running the program with command=/home/pi/.local/bin/prefect "agent local start" (I tried this with and without double quotes)
Looking at the supervisord.log file it seems like the Prefect Agent does start, I see the ASCII art that normally shows up when I start it from the command line. But then it shows it was terminated by SIGTERM;not expected, WARN recieved SIGTERM inidicating exit request.
I saw this post: Supervisor gets a SIGTERM for some reason, quits and stops all its processes but I don't even have that 10Periodic file it references.
Anyone know why/how Supervisor processes are getting killed by sigterm?
It could be that your process exits immediately because you don’t have an API key in your command and this is required to connect your agent to the Prefect Cloud API. Additionally, it’s a best practice to always assign a unique label to your agents, below is an example with “raspberry” as a label.
You can also check the logs/status:
supervisorctl status
Here is a command you can try, plus you can specify a directory in your supervisor config (not sure whether environment variables are needed but I saw it from other raspberry Pi supervisor user):
[program:prefect-agent]
command=prefect agent local start -l raspberry -k YOUR_API_KEY --no-hostname-label
directory=/home/pi/.local/bin/prefect
user=pi
environment=HOME="/home/pi/.local/bin/prefect",USER="pi"

Stop mosquitto autorestart on centos7

I'm trying to stop the Mosquitto broker service on a centos 7 server.
I've stopped the service with
sudo systemctl stop mosquitto.service
then I've disabled it with
sudo systemctl disable mosquitto.service
with ps I still get
/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
if I kill it, it autorestarts automatically and even after a reboot It's still running.
The process is owned by an other user (admin).
How can I stop it definitively?
This has nothing to do with mosquitto but how systemd manages its services.
systemctl disable only affects the autostart of the service but a disabled service will still get started if another service depends on it.
Lets say you have got a service mqtt-client depending on mosquitto with e.g. Wants=mosquitto. Every time mqtt-client is started the mosquitto service gets started as well, even if it is disabled.
So one way is either to prevent mqtt-client from starting as well (and all other services which depend on mosquitto) or remove the dependency.
Another approach is to totally prevent the service from being loaded by masking it:
systemctl mask mosquitto - this way you can neither start it manually nor by another service.
I would recommend reworking your dependencies in the long run since masking will just create a symlink to dev/null so nothing happens if service gets loaded and you are not able to start it by yourself without unmasking it first.

JBoss EAP6 - restart multiple hosts with one command in domain mode

I have an app that needs to be restarted through the JBoss CLI on multiple hosts during a deployment.
Is there a way to do this dynamically with a single restart(blocking=true) command? Or is there a different command that restarts all hosts while also using the blocking argument that waits for the servers restart.
Example code
/host=devserver1/server-config=Group-devserver1:restart(blocking=true)
/host=devserver2/server-config=Group-devserver2:restart(blocking=true)
/host=devserver3/server-config=Group-devserver3:restart(blocking=true)
You can use the server group to restart the servers with blocking or you can restart the servers on the host, but there is no blocking.
To restart via the server group you'd do something like:
/server-group=main-server-group:restart-servers(blocking=true)
To restart on the host you'd do something like:
/host=master:reload(restart-servers=true)

supervisord autorestart max tries?

http://supervisord.org/configuration.html#program-x-section-values says you can use autorestart=true to restart on exit, but doesn't say how to give a maximum amount of restarts (within startsecs) before giving up. Is there a way to do this? Note: I'm not talking about the first startup, but about the event that a program crashes after, say, running fine for 10 days.
According to the docs, autorestart doesn't care about startretries:
autorestart controls whether supervisord will autorestart a program if
it exits after it has successfully started up (the process is in the
RUNNING state).
supervisord has a different restart mechanism for when the process is
starting up (the process is in the STARTING state). Retries during
process startup are controlled by startsecs and startretries.
You should use startretries as well, ex of program configuration:
[program:consumer_example]
command=command example
process_name=%(program_name)s_%(process_num)02d
numprocs=1
autostart=true
autorestart=true
startretries=10
user=USERNAME
As you can see I used startretries with 10, when you not inform into program it uses the default value (3).
I think that you need is to use the startretries parameter..
http://supervisord.org/configuration.html?highlight=startretries#program-x-section-example
best regards