redis启动、关闭脚本

时间:2023-03-09 20:07:59
redis启动、关闭脚本
 #!/bin/bash
PORT=
NAME=redis-server
ID=`ps -ef | grep "$NAME" | grep -v "grep" | awk '{print $2}'`
#CHECK_PORT=`netstat -tnlp|grep "\b$PORT\b"`
REDIS_SERVER=/usr/local/redis/bin/redis-server
REDIS_CONFIG=/usr/local/redis/etc/redis.conf
RETAVL=
#检查shelk公共函数库是否存在,存在就加载
FUNCTIONS_PATH=/etc/init.d/functions
[ -f $FUNCTIONS_PATH ]&& source $FUNCTIONS_PATH
#检查redis文件是否存在并可执行
[ -x $REDIS_SERVER ]|| exit #定义函数
#检查是否执行成功
check(){
RETAVL=$?
if
[ $RETAVL -eq ];then
action "redis is $1" /bin/true
else
action "redis is $1" /bin/false
fi
}
#启动服务
start(){
$REDIS_SERVER $REDIS_CONFIG
RETVAL=$?
if [ $RETVAL -eq ]; then
echo "redis is started!";
else
echo "redis start failed!";
fi
return $RETAVL }
#停止服务
stop(){
for id in $ID
do
kill - $id
done
RETVAL=$?
if [ $RETVAL -eq ]; then
echo "redis is stopped!";
else
echo "redis stop failed!";
fi
return $RETVAL;
} #redis启动状态
status(){
STATUS=$(pgrep redis-server | wc -l)
if [[ $STATUS -eq ]];then
echo "redis is not running!";
else
echo "redis is running!";
fi
} #重启服务
restart(){
stop
sleep
start
} #判断
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo $"Usage:$0{start|stop|restart|help}"
esac
exit $RETAVL