创建 vi /etc/init.d/redis 文件 并添加
#!/bin/bash
#chkconfig: 2345 10 90
#description: Start and Stop redis
EXEC=/home/weblogic/redis-3.2.3/src/redis-server
CLIEXEC=/home/weblogic/redis-3.2.3/src/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/home/weblogic/redis-3.2.3/redis.conf"
REDISPORT="6379"
case "$1" in
start)
if [ -f $PIDFILE ];then
echo "$PIDFILE exists,process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ];then
echo "$PIDFILE does not exist,process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart)
"$0" stop
sleep 3
"$0" start
;;
*)
echo "Please use start or stop or restart as first argument"
;;
esac
PIDFILE 可以在redis.conf 配置文件中 查询得到
pidfile /var/run/redis_6379.pid
其中 要注意 redis.conf 文件中的
dir /home/weblogic/redis-3.2.3/src 数据目录路径