Is it possible to set up an alert (email) for when a particular services stops running?
I have alerts set up for when the MySQL or Apache goes down (set from System and Server Status), but there is a particular Service that keeps stopping every now and then and I’d like to be alerted when it does, so I can check log files at the time to see why. The service is rh-redis5-redis.service.
Hmm, if its not directly managed via webmin then I think you need to write a little script which checks the status every few minutes (via cron). There are quite some out there, which you can find easily with a quick google/whatever search.
Something like:
systemctl check if the wanted service gives back an “ok”. If not, automatically restart via systemctl command.
You could easily send a mail with that too.
You can either use a monitor type of Bootup Action or Check Process. For Check Process, you need to give it the exact process name of the program (I don’t know what that is, but it’s definitely not the systemd unit file…that’s a configuration file that tells systemd how to start the process, it is not the process). Bootup action may be simpler, but it’s not always reliable…depends on how well the systemctl status command or service _name_ status command woks.
Bootup Action is what you want, if you want to specify the systemd unit file (because it uses systemd to check the status).
Thanks for that, would I just put ‘rh-redis5-redis.service’ in the command to check for?
I would just try redis-server, based on the start command. Considering there are no other redis services running on the server, it should be pretty precise.
Choosing bootup action and selecting it from there has done the trick.
It went down over night and I got the alert.
Now to work out what caused it to go down. It reached its memory limit and crashed, rather than deleting keys as I thought I had configured.
I notice I can run a command when it detected the service goes down, what command is used to start redis. Is there a way I can find out? Then I could just get it to auto start.
That monit example uses initscripts, which is no longer used on any system currently supported by Virtualmin (though it’s possible your redis configuration is using an initscript, I dunno…Webmin still has an initscript, but it’s just that we haven’t had time to update it). You’d want to use systemctl commands, most likely.
That’s not a command. You probably mean sudo systemctl start redis.service, but that isn’t necessary. It’s going to run as root, unless you tell it otherwise, so just use systemctl start redis.service