1
0

upgrade_redis.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Upgrade_Redis() {
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. [ ! -d "$redis_install_dir" ] && echo "${CWARNING}Redis is not installed on your system! ${CEND}" && exit 1
  13. OLD_redis_ver=`$redis_install_dir/bin/redis-cli --version | awk '{print $2}'`
  14. Latest_redis_ver=`curl --connect-timeout 2 -m 3 -s http://download.redis.io/redis-stable/00-RELEASENOTES | awk '/Released/{print $2}' | head -1`
  15. Latest_redis_ver=${Latest_redis_ver:-6.0.4}
  16. echo "Current Redis Version: ${CMSG}$OLD_redis_ver${CEND}"
  17. while :; do echo
  18. [ "${redis_flag}" != 'y' ] && read -e -p "Please input upgrade Redis Version(default: ${Latest_redis_ver}): " NEW_redis_ver
  19. NEW_redis_ver=${NEW_redis_ver:-${Latest_redis_ver}}
  20. if [ "$NEW_redis_ver" != "$OLD_redis_ver" ]; then
  21. [ ! -e "redis-$NEW_redis_ver.tar.gz" ] && wget --no-check-certificate -c http://download.redis.io/releases/redis-$NEW_redis_ver.tar.gz > /dev/null 2>&1
  22. if [ -e "redis-$NEW_redis_ver.tar.gz" ]; then
  23. echo "Download [${CMSG}redis-$NEW_redis_ver.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! Upgrade Redis version is the same as the old version${CEND}"
  30. exit
  31. fi
  32. done
  33. if [ -e "redis-$NEW_redis_ver.tar.gz" ]; then
  34. echo "[${CMSG}redis-$NEW_redis_ver.tar.gz${CEND}] found"
  35. if [ "${redis_flag}" != 'y' ]; then
  36. echo "Press Ctrl+c to cancel or Press any key to continue..."
  37. char=`get_char`
  38. fi
  39. tar xzf redis-$NEW_redis_ver.tar.gz
  40. pushd redis-$NEW_redis_ver
  41. make clean
  42. make -j ${THREAD}
  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. popd > /dev/null
  49. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_redis_ver${CEND} to ${CWARNING}$NEW_redis_ver${CEND}"
  50. rm -rf redis-$NEW_redis_ver
  51. else
  52. echo "${CFAILURE}Upgrade Redis failed! ${CEND}"
  53. fi
  54. fi
  55. popd > /dev/null
  56. }