3

So as the title states, I have a problem where monit won't start on boot. I have a CentOS 7 box that it does start on, and another CentOS 7 box that it doesn't start on, so I know it's not a OS issue and must be a configuration issue somewhere. Both boxes are built with vagrant and are nearly identical. I have no idea where to start.

I'll be watching this question for a while, so please feel free to ask me to clarify anything, I know this isn't much to go on. Any help is appreciated.

EDIT: It's worth noting that I've already tried systemctl enable monit but its already enabled.

EDIT 2: (Irrelevant)

EDIT 3:

[root@stage-web-1 vagrant]# systemctl status monit
monit.service - Pro-active monitoring utility for unix systems
Loaded: loaded (/usr/lib/systemd/system/monit.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2017-06-01 16:37:00 UTC; 6min ago
Process: 1131 ExecStop=/usr/bin/monit quit (code=exited, status=1/FAILURE)
Process: 1079 ExecStart=/usr/bin/monit -I (code=exited, status=1/FAILURE)
Main PID: 1079 (code=exited, status=1/FAILURE)

Jun 01 16:37:00 stage-web-1 systemd[1]: Started Pro-active monitoring utility for unix systems.
Jun 01 16:37:00 stage-web-1 systemd[1]: Starting Pro-active monitoring utility for unix systems...
Jun 01 16:37:00 stage-web-1 monit[1079]: Error opening the log file '/var/www/html/nfs/monit/stage-web-1.log' for writing -- No such file or directory
Jun 01 16:37:00 stage-web-1 systemd[1]: monit.service: main process exited, code=exited, status=1/FAILURE
Jun 01 16:37:00 stage-web-1 monit[1131]: Error opening the log file '/var/www/html/nfs/monit/stage-web-1.log' for writing -- No such file or directory
Jun 01 16:37:00 stage-web-1 systemd[1]: monit.service: control process exited, code=exited status=1
Jun 01 16:37:00 stage-web-1 systemd[1]: Unit monit.service entered failed state.
Jun 01 16:37:00 stage-web-1 systemd[1]: monit.service failed.
19
  • systemctl enable monit?
    – jordanm
    May 30 '17 at 18:56
  • Ah yes, that was my original idea, however, its's already enabled. I will edit the original post. May 30 '17 at 18:57
  • What happens if you use systemctl to stop and then restart it? Do you get any errors? Have you used the monit options that set a startup delay? Do you have another script that is unmonitoring things at startup?
    – Zoredache
    May 30 '17 at 18:59
  • I don't know of any scripts that are unmonitoring things, but the monit service itself wont start. systemctl start monit starts it just fine, with no errors. I haven't thought of starting with a delay. May 30 '17 at 19:05
  • Would you have any idea how I might do about this? May 30 '17 at 19:14
2

As it turns out, /var/www/html/nfs is a mounted folder to a network drive through NFS. Monit was being started before NFS, so the folder didn't exist yet, causing monit to error with Error opening the log file '/var/www/html/nfs/monit/stage-web-1.log' for writing -- No such file or directory.

The solution was to edit /lib/systemd/system/monit.service:

[Unit]
Description=Pro-active monitoring utility for unix systems
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/monit -I
ExecStop=/usr/bin/monit quit
ExecReload=/usr/bin/monit reload

[Install]
WantedBy=multi-user.target

and add nfs.service to the After section. The end result looking like:

[Unit]
Description=Pro-active monitoring utility for unix systems
After=network.target nfs.service

[Service]
Type=simple
ExecStart=/usr/bin/monit -I
ExecStop=/usr/bin/monit quit
ExecReload=/usr/bin/monit reload

[Install]
WantedBy=multi-user.target

Monit now starts correctly on boot :)

Thanks to everyone who helped steer me in the right direction.

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.