Shell Reids自动配置脚本 redis自带脚本参考参考

[root@localhost tmp]# cat test.sh 
#!/bin/sh
die () {
        echo "ERROR: $1. Aborting!"
        exit 1
}


#Initial defaults
_REDIS_PORT=6379
_MANUAL_EXECUTION=false

echo "Welcome to the redis service installer"
echo "This script will help you easily set up a running redis server"
echo

if [ $(id -u) -ne 0 ];then
	echo "You must run this script as root. Sorry!"
        exit 1
fi


if ! echo $REDIS_PORT | egrep -q '^[0-9]+$' ; then
        _MANUAL_EXECUTION=true
        #Read the redis port
        read  -p "Please select the redis port for this instance: [$_REDIS_PORT] " REDIS_PORT
        if ! echo $REDIS_PORT | egrep -q '^[0-9]+$' ; then
                echo "Selecting default: $_REDIS_PORT"
                REDIS_PORT=$_REDIS_PORT
        fi
fi


if [ -z "$REDIS_CONFIG_FILE" ] ; then
        _MANUAL_EXECUTION=true
        #read the redis config file
        _REDIS_CONFIG_FILE="/etc/redis/$REDIS_PORT.conf"
        read -p "Please select the redis config file name [$_REDIS_CONFIG_FILE] " REDIS_CONFIG_FILE
        if [ -z "$REDIS_CONFIG_FILE" ] ; then
                REDIS_CONFIG_FILE=$_REDIS_CONFIG_FILE
                echo "Selected default - $REDIS_CONFIG_FILE"
        fi
fi


if [ -z "$REDIS_LOG_FILE" ] ; then
        _MANUAL_EXECUTION=true
        #read the redis log file path
        _REDIS_LOG_FILE="/var/log/redis_$REDIS_PORT.log"
        read -p "Please select the redis log file name [$_REDIS_LOG_FILE] " REDIS_LOG_FILE
        if [ -z "$REDIS_LOG_FILE" ] ; then
                REDIS_LOG_FILE=$_REDIS_LOG_FILE
                echo "Selected default - $REDIS_LOG_FILE"
        fi
fi


if [ -z "$REDIS_DATA_DIR" ] ; then
        _MANUAL_EXECUTION=true
        #get the redis data directory
        _REDIS_DATA_DIR="/var/lib/redis/$REDIS_PORT"
        read -p "Please select the data directory for this instance [$_REDIS_DATA_DIR] " REDIS_DATA_DIR
        if [ -z "$REDIS_DATA_DIR" ] ; then
                REDIS_DATA_DIR=$_REDIS_DATA_DIR
                echo "Selected default - $REDIS_DATA_DIR"
        fi
fi

if [ ! -x "$REDIS_EXECUTABLE" ] ; then
        _MANUAL_EXECUTION=true
        #get the redis executable path
        _REDIS_EXECUTABLE=`command -v redis-server`
        read -p "Please select the redis executable path [$_REDIS_EXECUTABLE] " REDIS_EXECUTABLE
        if [ ! -x "$REDIS_EXECUTABLE" ] ; then
                REDIS_EXECUTABLE=$_REDIS_EXECUTABLE

                if [ ! -x "$REDIS_EXECUTABLE" ] ; then
                        echo "Mmmmm...  it seems like you don't have a redis executable. Did you run make install yet?"
                        exit 1
                fi
        fi
fi



echo "Selected config:"

echo "Port           : $REDIS_PORT"
echo "Config file    : $REDIS_CONFIG_FILE"
echo "Log file       : $REDIS_LOG_FILE"
echo "Data dir       : $REDIS_DATA_DIR"
echo "Executable     : $REDIS_EXECUTABLE"
echo "Cli Executable : $CLI_EXEC"

if $_MANUAL_EXECUTION == true ; then
        read -p "Is this ok? Then press ENTER to go on or Ctrl-C to abort." _UNUSED_
fi

mkdir -p `dirname "$REDIS_CONFIG_FILE"` || die "Could not create redis config directory"
mkdir -p `dirname "$REDIS_LOG_FILE"` || die "Could not create redis log dir"
mkdir -p "$REDIS_DATA_DIR" || die "Could not create redis data directory"

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值