- 论坛徽章:
- 0
|
我有个重启memcached的脚本,奇怪的很,有的机器上能得到pid,有的机器不行。
上次的提问:http://bbs.chinaunix.net/thread-4067693-1-1.html
大家看看我的脚本执行结果:- root@MJ-GS1:/opt/tools# sh -x ./mem_restart.sh /var/www/html/
- + path=/var/www/html/
- + exec_log_file=/opt/tools/mem_restart.log
- + cat /var/www/html//config.php
- + grep Memport
- + awk {print $3}
- + sed s/\;//
- + mem_port=11211
- + ps -eaf
- + grep memcache
- + grep -v grep
- + grep 11211
- + awk {print $2}
- + mem_pid=
- + ifconfig
- + grep inet addr:
- + grep -v 127.0.0.1
- + cut -d: -f2
- + awk { print $1}
- + ipaddr=192.168.105.153
- + echo 192.168.105.153
- + cut -d. -f1
- + ipaddr_fr=192
- + cat /dev/null
- + [ ! -f /var/www/html//config.php ]
- + [ != ]
- + [ 192 -ne 10 ]
- -u nobody -l 127.0.0.1 -d24 -p 11211
- + mem_cmd=
- + kill -9
- kill: 1: Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or
- kill -l [exitstatus]
- + sleep 1
- + echo old_mem_pid =
- + exec
- + ps -ef
- + grep memcache
- + grep -v grep
- + grep 11211
- + awk {print $2}
- + echo new_mem_pid =
- + [ 192 -ne 10 ]
- + echo restart
- restart
- + nohup /usr/sbin/service php5-fpm restart
- + ps_list fpm
- + ps -ef
- + grep fpm
- + grep -v grep
- + wc -l
- + [ 2 -lt 1 ]
- + exit
复制代码 下面是这个重启mem & fpm的脚本- #!/bin/bash
- path=$1
- exec_log_file=/opt/tools/mem_restart.log
- mem_port=`cat ${path}/config.php |grep Memport |awk '{print $3}'|sed "s/\;//"`
- mem_pid=`ps -eaf |grep memcache|grep -v grep |grep $mem_port|awk '{print $2}'`
- #mem_pid=`netstat -tpln|awk '$4~/'${mem_port}'$/&&$NF~/memcached$/{gsub(/\/sshd/,"");print $NF}'|cut -d\/ -f1`
- #mem_cmd=`ps -ef |grep mem|grep -v grep |awk 'NR==1 {S="";for(i=8;i<=NF;i++) S=S" "$i;print S}'`
- #process_deamon=`ps -ef |grep process_deamon |grep -v grep |wc -l`
- ipaddr=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' |cut -d: -f2 | awk '{ print $1}'`
- ipaddr_fr=`echo $ipaddr |cut -d. -f1 `
- ps_list() {
- ps -ef |grep $1|grep -v grep|wc -l
- }
- cat /dev/null > $exec_log_file
- if [ ! -f ${path}/config.php ] ; then
- echo "${path}/config.php does not exist !" > $exec_log_file
- exit
- fi
- if [ "$mem_pid" != "" ]; then
- mem_cmd=`ps -ef |grep mem|grep $mem_port|grep -v grep |awk 'NR==1 {S="";for(i=8;i<=NF;i++) S=S" "$i;print S}'`
- elif [ $ipaddr_fr -ne 10 ] ; then
- mem_cmd=`/usr/bin/memcached -m 1024 -p $mem_port -u nobody -l 127.0.0.1 -d`
- elif [ $ipaddr_fr -eq 10 ] ; then
- mem_cmd=`/usr/local/app/lnmp/memcached/bin/memcached -m 1024 -p $mem_port -u nobody -l 127.0.0.1 -d`
- fi
- kill -9 $mem_pid
- sleep 1
- exec $mem_cmd >/dev/null 2>&1 &
- echo "old_mem_pid = $mem_pid" >> $exec_log_file
- echo "new_mem_pid = `ps -ef |grep memcache|grep -v grep |grep $mem_port|awk '{print $2}'`" >> $exec_log_file
- if [ $ipaddr_fr -ne 10 ] ; then
- echo "restart"
- nohup /usr/sbin/service php5-fpm restart >>$exec_log_file 2>&1 &
- while [ `ps_list "fpm"` -lt 1 ] ; do
- nohup /usr/sbin/service php5-fpm restart >>$exec_log_file 2>&1 &
- sleep 1
- done
- else
- pkill php-fpm
- tsh /usr/local/app/lnmp/PHP/sbin/php-fpm
- fi
- exit
复制代码 |
|