upgrade_redis.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. cd $oneinstack_dir/src
  12. [ ! -d "$redis_install_dir" ] && echo "${CWARNING}The Redis is not installed on your system! ${CEND}" && exit 1
  13. OLD_Redis_version=`$redis_install_dir/bin/redis-cli --version | awk '{print $2}'`
  14. echo "Current Redis Version: ${CMSG}$OLD_Redis_version${CEND}"
  15. while :
  16. do
  17. echo
  18. read -p "Please input upgrade Redis Version(example: 3.0.5): " NEW_Redis_version
  19. if [ "$NEW_Redis_version" != "$OLD_Redis_version" ];then
  20. [ ! -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
  21. if [ -e "redis-$NEW_Redis_version.tar.gz" ];then
  22. echo "Download [${CMSG}redis-$NEW_Redis_version.tar.gz${CEND}] successfully! "
  23. break
  24. else
  25. echo "${CWARNING}Redis version does not exist! ${CEND}"
  26. fi
  27. else
  28. echo "${CWARNING}input error! The upgrade Redis version is the same as the old version${CEND}"
  29. fi
  30. done
  31. if [ -e "redis-$NEW_Redis_version.tar.gz" ];then
  32. echo "[${CMSG}redis-$NEW_Redis_version.tar.gz${CEND}] found"
  33. echo "Press Ctrl+c to cancel or Press any key to continue..."
  34. char=`get_char`
  35. tar xzf redis-$NEW_Redis_version.tar.gz
  36. cd redis-$NEW_Redis_version
  37. make clean
  38. if [ "$OS_BIT" == '32' ];then
  39. sed -i '1i\CFLAGS= -march=i686' src/Makefile
  40. sed -i 's@^OPT=.*@OPT=-O2 -march=i686@' src/.make-settings
  41. fi
  42. make
  43. if [ -f "src/redis-server" ];then
  44. echo "Restarting Redis..."
  45. service redis-server stop
  46. /bin/cp src/{redis-benchmark,redis-check-aof,redis-check-rdb,redis-cli,redis-sentinel,redis-server} $redis_install_dir/bin/
  47. service redis-server start
  48. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_Redis_version${CEND} to ${CWARNING}$NEW_Redis_version${CEND}"
  49. else
  50. echo "${CFAILURE}Upgrade Redis failed! ${CEND}"
  51. fi
  52. cd ..
  53. fi
  54. cd ..
  55. }