新建文件
sudo vim redis.sh
#!/bin/bash
start(){
REDIS_HOME=/usr/local
APP_NAME=redis
WAIT_TIME=5
echo "REDIS_HOME:"${REDIS_HOME}
for i in {7000..7005}
do
REDIS_ID=$(ps -ef | grep ${APP_NAME} |grep ${i}| grep -v 'grep' | head -1 | awk '{print $2}')
if [ -z "$REDIS_ID" ]; then
echo "[${APP_NAME}] will be start"
cd $REDIS_HOME/$i
redis-server redis.conf & >/dev/null 2>&1
else
echo "[${APP_NAME}] has bean start"
fi
done
}
stop(){
REDIS_HOME=/usr/local
APP_NAME=redis
WAIT_TIME=5
echo "REDIS_HOME:"${REDIS_HOME}
for i in {7000..7005}
do
REDIS_ID=$(ps -ef | grep ${APP_NAME} |grep ${i}| grep -v 'grep' | head -1 | awk '{print $2}')
if [ -z "$REDIS_ID" ]; then
echo "[$i] has bean stop"
else
echo "[$i] will be stop"
kill -9 $REDIS_ID
sleep ${WAIT_TIME}
fi
done
}
status(){
REDIS_HOME=/usr/local
APP_NAME=redis
WAIT_TIME=5
echo "REDIS_HOME:"${REDIS_HOME}
for i in {7000..7005}
do
REDIS_ID=$(ps -ef | grep ${APP_NAME} |grep ${i}| grep -v 'grep' | head -1 | awk '{print $2}')
if [ -z "$REDIS_ID" ]; then
echo "[$i] has bean stop"
else
echo "[$i] has bean start"
fi
done
}
case "$1" in
start)
echo "start redis"
start
;;
stop)
echo "stop redis"
stop
;;
status)
status
;;
restart)
echo "restart redis"
#$0 stop
sleep 2
#$0 start
;;
*)
printf 'Usage: %s {start|stop|status|restart}\n' "$prog"
exit 1
;;
esac