redis 註冊爲服務

進入redis的utils目錄下,拷貝redis_init_script到/etc/init.d/下並重命名爲redisredis

修改redis,指定配置文件,個人redis配置文件爲/etc/redis/redis.conf,以後chmod 777 redis,就能夠執行service redis start/stopide

如下是redis_init_scrip文件spa

 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
相關文章
相關標籤/搜索