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

centos8 设置 redis 开机自启动

时间:2020-07-14 00:34:31      阅读:331      评论:0      收藏:0      [点我收藏+]

标签:pre   lease   ice   out   root   argument   already   run   systemd   

编写脚本文件

#!/bin/bash
#chkconfig: 22345 10 90
#description: Start and Stop redis

REDISPORT=6379
EXEC=/usr/local/soft/redis5/bin/redis-server
CLIEXEC=/usr/local/soft/redis5/bin/redis-cli

PIDFILE=/var/run/redis_6379.pid
CONF="/usr/local/soft/redis5/conf/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
        ;;
    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

 

技术图片

 

 

 

操作步骤记录

[root@localhost redis5]# vim /etc/init.d/redis5
[root@localhost redis5]# chmod +x /etc/init.d/redis5 
[root@localhost redis5]# 
[root@localhost redis5]# 
[root@localhost redis5]# chkconfig --add redis5 

[root@localhost redis5]# 
[root@localhost redis5]# 
[root@localhost redis5]# 
[root@localhost redis5]# 
[root@localhost redis5]# chkconfig redis on
error reading information on service redis: No such file or directory
[root@localhost redis5]# 
[root@localhost redis5]# chkconfig redis5 on
[root@localhost redis5]# 
[root@localhost redis5]# 
[root@localhost redis5]# 
[root@localhost redis5]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use systemctl list-unit-files.
      To see services enabled on particular target use
      systemctl list-dependencies [target].

redis5             0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@localhost redis5]# 
[root@localhost redis5]# 

 

centos8 设置 redis 开机自启动

标签:pre   lease   ice   out   root   argument   already   run   systemd   

原文地址:https://www.cnblogs.com/yadongliang/p/12538894.html

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