check memcached process and restart if down

weixin_34402408發表於2018-03-08
#!/bin/sh
#check memcached process and restart if down
PATH=$PATH:/usr/bin/memcached
DATE=`date -d "today" +"%Y-%m-%d-%H:%M"`
#用ps命令檢視memcached程式
MM=`ps -aux |grep "memcached" |grep "13250" |grep -v "grep" |wc -l`
#if語句判斷程式是否存在,如果不存在,輸出日誌記錄並重啟memcached服務
if [ "$MM" == "0" ]; then
    echo "$DATE The memcached is problem and restart" >> /tmp/memcached_check.logs
    /usr/bin/memcached -m 1024 -p 13250 -d -u nobody
else
    echo "$DATE The memcached is ok" >>/tmp/memcached_check.logs
fi

相關文章