I am configuring Monit to monitor Redis and Redis Sentinel. But every time Monit is run, it logs that both Redis and Redis Sentinel are not running and tries to run them although both of them are already done. It fails in starting the Redis processes.
Whereas it is working perfectly for system checks and nginx and some other processes.
Versions:
Redis: Redis server v=2.8.4 sha=00000000:0 malloc=jemalloc-3.4.1 bits=64 build=a44a05d76f06a5d9
Monit: version 5.6
Here is my configuration of Monit for Redis (Redis Sentinel has almost same configuration):
# redis
check process redis with pidfile /var/run/redis-server.pid
group cache
group redis
start program = "/etc/init.d/redis-server start"
stop program = "/etc/init.d/redis-server stop"
if failed host 127.0.0.1 port 6379 then restart
if totalmem > 500 Mb then alert
if cpu > 60% for 2 cycles then alert
if cpu > 98% for 5 cycles then restart
if 2 restarts within 2 cycles then alert
depend redis_bin
depend redis_rc
check file redis_bin with path /usr/bin/redis-server
group redis
include /etc/monit/templates/rootbin
check file redis_rc with path /etc/init.d/redis-server
group redis
include /etc/monit/templates/rootbin
Here are the logs of Monit:
[PKT Aug 19 17:00:07] error : 'redis' process is not running
[PKT Aug 19 17:00:07] info : 'redis' trying to restart
[PKT Aug 19 17:00:07] info : 'redis' start: /etc/init.d/redis-server
[PKT Aug 19 17:00:37] error : 'redis' failed to start
I think this cause of this issue is other processes that are working fine are owned by root along with all the directories and bin files. But everything related to Redis is own by user "redis" from group "redis". And this is why Monit is not able to start or stop Redis.
But I have tried to use it by adding user in start and stop settings like this:
start program = "/etc/init.d/redis-server start"
as uid redis and gid redis
stop program = "/etc/init.d/redis-server stop"
as uid redis and gid redis
But this didn't work either.
What am I doing wrong here? What is the correct way to monitor Redis with Monit?