What is the point of the system daemon?
Closed this issue · 2 comments
joe-at-startupmedia commented
systemctl start pmon2
What is the point of starting this daemon? I am able to add processes without starting it using the following:
pmon2 run /home/api_user/go/bin/helloworld --user api_user
joe-at-startupmedia commented
My guess is that the deamon process spawned by systemctl start pmon2
monitors all processes in the database and restarts them when they are unhealthy? pm2 automatically starts the god deamon when you run pm2 start [service]
. Besides this, Is there anything else I'm missing?
joe-at-startupmedia commented
According to the code. This file explains how pmond works:
https://github.com/ntt360/pmon2/blob/483fb1f80656fa6b489d8f7ebd47f16f7b86bb97/app/god/monitor.go
In summary it does the following in an infinite loop that executes every 500 ms.
- finds all processes in the database that have a status of running or failed
- loadOrStores the pid/process name into a syncMap and returns early if loaded
- If stored, it proceeds to execute a closure that checks if the process is still:
a. in the database
b. has a status of running or failed
c. hasn't been updated since 5 seconds ago - Deletes the pid/process from the syncMap when the closure exits.
- Checks if the process is running on the OS
- Mark the process as failed if the process doesn't have autostart enabled OR
- Attempts to start the process.