一例用于监控memcached进程是否启动的shell脚本,用于memcache的启动、停止与重启等操作。
1,memcached_inc.sh 设置路径,端口等讯息。
复制代码代码示例:
#!/bin/sh
#config include HOST=$(hostname) SITE="mysite" PORT=11211 MEMCACHED_PID_FILE="/tmp/memcached.pid" MEMCACHED_DAEMON_PID_FILE="/tmp/memcached_daemon.pid" MEMCACHED="memcached -d -m 64 -p $PORT -u memcache -l 127.0.0.1 -P $MEMCACHED_PID_FILE" MEMCACHED_DAEMON_FILE="memcached_daemon.sh" ERROR_LOG_FILE="${ROOT}/memcached_${SITE}_${HOST}_${PORT}.log"
2,gm_memcached.sh 控制memcached 启动,停止,重启。
复制代码代码示例:
#!/bin/sh
case "$1" in
3,memcached_daemon.sh 监控memcached 进程,如进程失效则自动启动。
复制代码代码示例:
#!/bin/sh
#site; www.jbxue.com #memcached daemon ROOT=$(cd "$(dirname "$0")"; pwd) . ${ROOT}/memcached_inc.sh while : do if [ -f "$MEMCACHED_PID_FILE" ] && [ -s "$MEMCACHED_PID_FILE" ]; then PID=$(cat $MEMCACHED_PID_FILE) else PID="" fi if [ -z "$PID" ] || [ -z $(ps aux|awk '{print $2}' | grep "^$PID$") ]; then $MEMCACHED sleep 1 printf "[$(date +%Y-%m-%d' '%H:%M:%S)] ${SITE} ${HOST} memcached ${PORT} is restarted\n" >> $ERROR_LOG_FILE echo "Subject: ${SITE} ${HOST} memcached ${PORT} is restarted $(date +%Y-%m-%d' '%H:%M:%S)" | sendmail me@gmail.com fi sleep 5 done exit 0
调用方法:
复制代码代码示例:
./gm_memcached.sh start #启动memcached
./gm_memcached.sh stop #停止memcached ./gm_memcached.sh restart #重启memcached (责任编辑:IT) |