Search code examples
memcachedcentos7monit

Monit memcached config without pidfile


I have classic situation. Need to configure monit for memcached on CentOS7. The problem is, that all configs i can find in google contains this row:

check process memcached with pidfile /var/run/memcached/memcached.pid

However, There is no memcached.pid file in /var/run and no /var/run/memcached folder. I've checked /usr/lib/systemd/system/memcached.service

[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/memcached
ExecStart=/usr/bin/memcached -u $USER -p $PORT -m $CACHESIZE -c $MAXCONN $OPTIONS

So, there is no path to .pid file. The question is can I check memcached without .pid file? The second question - can be this .pid file in another location?


Solution

  • Replace in your monit config

    check process memcached with pidfile /var/run/memcached/memcached.pid
    

    with

    check process memcached with match memcached
    

    My config for memcached:

    check process memcached with match memcached
        start program = "/usr/bin/systemctl start memcached"
        stop program = "/usr/bin/systemctl stop memcached"
        if failed host 127.0.0.1 port 11211 protocol MEMCACHE then restart
        if cpu > 70% for 2 cycles then alert
        if cpu > 98% for 5 cycles then restart
        if 2 restarts within 3 cycles then timeout
    

    Centos 7, monit 5.14