I have monit configured to mount an NFS filesystem if it is ever not mounted, however for some reason monit won't mount the share automatically and I have to run monit start myshare
in order to get the filesystem mounted.
The system often can't mount NFS shares at boot time (as the remote system is typically booting at the same time and isn't up yet) which is why I want monit to keep retrying the mount, which will eventually succeed when the remote system finishes booting.
However it seems that monit just gives up too soon and stops trying, meaning I have to manually run monit start myshare
in order to get it to try again. This always succeeds, suggesting the start
command in monitrc
is correct.
I can see in the monit manual how to limit a service so that it will stop trying after a certain number of failures, but I can't see how to disable this so it just keeps trying forever.
Here is my monitrc
:
set daemon 30
set log syslog
set mailserver ...
check filesystem myshare with path /mnt/myshare
start program = "/bin/mount /mnt/myshare"
group nfs
And this is what it says after booting the machine:
$ monit status myshare
Filesystem 'myshare'
status Execution failed
monitoring status Monitored
monitoring mode active
on reboot start
filesystem type nfs
$ monit start myshare
$ monit status myshare
Monit 5.25.1 uptime: 5d 10h 32m
Filesystem 'myshare'
status OK
monitoring status Monitored
monitoring mode active
on reboot start
filesystem type nfs
What am I missing?
You should check for a flag file available only when the mount is ok like and retry on a regular basis
check file myshare-flag with path /mnt/myshare/my-flag-file if does not exist then exec "/bin/mount /mnt/myshare" repeat every 2 cycles
Checking a flag file is better as the file will only be present when mount is working.