将下面文本保存在位置:/etc/init.d/redis
chmod +x /etc/init.d/redis 设置权限
sudo chkconfig redis on 加入开机启动服务
service redis start 查看是否加入服务成功
#!/bin/sh
#chkconfig: 2345 80 90
#description:auto_run
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/etc/redis.conf"
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
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restartforce-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {startstoprestartforce-reload}" >&2
exit 1
esac
##############################
热门评论
加个软连接在init.d下