Using monit with CommandBox

Good afternoon,

I appreciate all of the help in getting my server transitioned over using CommandBox. I have it up and running and things seem to be running OK, for now. For uptime purposes, I’m wondering if there’s any way to integrate monit functionality with CommandBox.

I’m currently running CommandBox as a service located at /usr/lib/systemd/system/mydomain.service. This is the contents of the service file:

[Unit]
Description=MyDomain.com Web Service

[Service]
User=ubuntu
Group=ubuntu
ExecStart=/usr/local/bin/box server start /web/default/server.json
Type=forking

[Install]
WantedBy=multi-user.target

(Feedback about the service set up is always welcome.)

In the past I’ve used monit with configuration similar to this:

check process lucee with pidfile /opt/lucee/tomcat/work/tomcat.pid
      start program = "/opt/lucee/lucee_ctl start"
      stop program = "/opt/lucee/lucee_ctl stop"
      restart program = "/opt/lucee/lucee_ctl restart"
      if failed host www.mydomain.com port 443 with protocol https and request "/server_up.cfm" with timeout 5 seconds for 2 times within 3 cycles then restart

If Lucee gets bogged down in something stupid, I’ve used this to step in restart it. I’ve also set up similar ones for nginx and mysql. This allows for unattended monitoring of the server in case something happens when I’m away and can’t restart it.

I’m curious how I might best configure a similar monit file for my CommandBox server. I should note that the thing that worries me is the weird issue that’s already come up once before where I go to start the server, even after a restart, and CommandBox “thinks” there’s a server still running, because of an improper shutdown.

By nature, a monit usage is likely going to trigger when problems are happening, so the risk of the ‘server still running’ issue seems high. That’s why I’m reaching out for any thoughts people might have about how to manage such a situation and if anybody else has any ideas. Thank you as always for the feedback.

I’m wondering if anybody has any thoughts on this, still. When my server crashes I still have to manually go in and restart it, meaning there are often hours and hours of downtime. My existing monit configuration, /etc/monit/commandbox, looks like this:

check host myDomain with address 127.0.0.1
    start program = "/bin/systemctl start mySite.service" with timeout 60 seconds
    stop program  = "/bin/systemctl stop mySite.service"
    if failed port 8080 protocol http for 2 cycles then restart
    if 5 restarts within 5 cycles then timeout

This … does not work. This is the result in my /var/log/monit.log:

[UTC Jan 10 23:54:16] error    : 'myDomain' failed protocol test [HTTP] at [127.0.0.1]:8080 [TCP/IP] -- HTTP: Error receiving data -- Resource temporarily unavailable
[UTC Jan 10 23:54:17] info     : 'myDomain' trying to restart
[UTC Jan 10 23:54:18] info     : 'myDomain' stop: '/bin/systemctl stop mySite.service'
[UTC Jan 10 23:55:47] error    : 'myDomain' failed to stop (exit status -1) -- Program '/bin/systemctl stop mySite.service' timed out after 30 s

I’m wondering if there’s a better way to structure this? Or perhaps to alter the /usr/lib/systemd/system/mydomain.service shown earlier in this thread? I appreciate the help. And, yes, I am working on “why is this crashing, anyway?” in a thread on the Lucee Dev forum. Since that might take months to do, I’m hoping for a temporary patch to get my server through.