redis 注册为服务
Posted code never lies
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis 注册为服务相关的知识,希望对你有一定的参考价值。
进入redis的util目录下,拷贝redis_init_script到/etc/init.d/下并重命名为redis
修改CONF,指定配置文件,我的redis配置文件为/etc/redis/redis.conf,之后chmod 777 redis,就可以执行service redis start/stop
1 #!/bin/sh
2 #
3 # Simple Redis init.d script conceived to work on Linux systems
4 # as it does use of the /proc filesystem.
5
6 ### BEGIN INIT INFO
7 # Provides: redis_6379
8 # Default-Start: 2 3 4 5
9 # Default-Stop: 0 1 6
10 # Short-Description: Redis data structure server
11 # Description: Redis data structure server. See https://redis.io
12 ### END INIT INFO
13
14 REDISPORT=6379
15 EXEC=/usr/local/bin/redis-server
16 CLIEXEC=/usr/local/bin/redis-cli
17
18 PIDFILE=/var/run/redis_${REDISPORT}.pid
19 #CONF="/etc/redis/${REDISPORT}.conf"
20 CONF="/etc/redis/redis.conf"
21
22 case "$1" in
23 start)
24 if [ -f $PIDFILE ]
25 then
26 echo "$PIDFILE exists, process is already running or crashed"
27 else
28 echo "Starting Redis server..."
29 $EXEC $CONF
30 fi
31 ;;
32 stop)
33 if [ ! -f $PIDFILE ]
34 then
35 echo "$PIDFILE does not exist, process is not running"
36 else
37 PID=$(cat $PIDFILE)
38 echo "Stopping ..."
39 $CLIEXEC -p $REDISPORT shutdown
40 while [ -x /proc/${PID} ]
41 do
42 echo "Waiting for Redis to shutdown ..."
43 sleep 1
44 done
45 echo "Redis stopped"
46 fi
47 ;;
48 *)
49 echo "Please use start or stop as first argument"
50 ;;
51 esac
以上是关于redis 注册为服务的主要内容,如果未能解决你的问题,请参考以下文章