码迷,mamicode.com
首页 > 其他好文 > 详细

redis 注册为服务

时间:2019-04-10 22:05:57      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:work   chmod   str   init   idf   begin   color   ppi   already   

进入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 注册为服务

标签:work   chmod   str   init   idf   begin   color   ppi   already   

原文地址:https://www.cnblogs.com/tele-share/p/10686114.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!