upgrade_redis.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # http://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. Upgrade_Redis()
  11. {
  12. cd $oneinstack_dir/src
  13. [ ! -d "$redis_install_dir" ] && echo "${CWARNING}The Redis is not installed on your system! ${CEND}" && exit 1
  14. OLD_Redis_version=`$redis_install_dir/bin/redis-cli --version | awk '{print $2}'`
  15. echo "Current Redis Version: ${CMSG}$OLD_Redis_version${CEND}"
  16. while :
  17. do
  18. echo
  19. read -p "Please input upgrade Redis Version(example: 3.0.5): " NEW_Redis_version
  20. if [ "$NEW_Redis_version" != "$OLD_Redis_version" ];then
  21. [ ! -e "redis-$NEW_Redis_version.tar.gz" ] && wget --no-check-certificate -c http://download.redis.io/releases/redis-$NEW_Redis_version.tar.gz > /dev/null 2>&1
  22. if [ -e "redis-$NEW_Redis_version.tar.gz" ];then
  23. echo "Download [${CMSG}redis-$NEW_Redis_version.tar.gz${CEND}] successfully! "
  24. break
  25. else
  26. echo "${CWARNING}Redis version does not exist! ${CEND}"
  27. fi
  28. else
  29. echo "${CWARNING}input error! The upgrade Redis version is the same as the old version${CEND}"
  30. fi
  31. done
  32. if [ -e "redis-$NEW_Redis_version.tar.gz" ];then
  33. echo "[${CMSG}redis-$NEW_Redis_version.tar.gz${CEND}] found"
  34. echo "Press Ctrl+c to cancel or Press any key to continue..."
  35. char=`get_char`
  36. tar xzf redis-$NEW_Redis_version.tar.gz
  37. cd redis-$NEW_Redis_version
  38. make clean
  39. if [ "$OS_BIT" == '32' ];then
  40. sed -i '1i\CFLAGS= -march=i686' src/Makefile
  41. sed -i 's@^OPT=.*@OPT=-O2 -march=i686@' src/.make-settings
  42. fi
  43. make
  44. if [ -f "src/redis-server" ];then
  45. echo "Restarting Redis..."
  46. service redis-server stop
  47. /bin/cp src/{redis-benchmark,redis-check-aof,redis-check-dump,redis-cli,redis-sentinel,redis-server} $redis_install_dir/bin/
  48. service redis-server start
  49. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_Redis_version${CEND} to ${CWARNING}$NEW_Redis_version${CEND}"
  50. else
  51. echo "${CFAILURE}Upgrade Redis failed! ${CEND}"
  52. fi
  53. cd ..
  54. fi
  55. cd ..
  56. }