1
0

upgrade_memcached.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_Memcached() {
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. [ ! -e "${memcached_install_dir}/bin/memcached" ] && echo "${CWARNING}Memcached is not installed on your system! ${CEND}" && exit 1
  13. OLD_memcached_ver=`${memcached_install_dir}/bin/memcached -V | awk '{print $2}'`
  14. Latest_memcached_ver=`curl --connect-timeout 2 -m 3 -s https://github.com/memcached/memcached/wiki/ReleaseNotes | grep 'internal present.*ReleaseNotes' | grep -oE "[0-9]\.[0-9]\.[0-9]+" | head -1`
  15. Latest_memcached_ver=${Latest_memcached_ver:-1.5.12}
  16. echo "Current Memcached Version: ${CMSG}${OLD_memcached_ver}${CEND}"
  17. while :; do echo
  18. [ "${memcached_flag}" != 'y' ] && read -e -p "Please input upgrade Memcached Version(default: ${Latest_memcached_ver}): " NEW_memcached_ver
  19. NEW_memcached_ver=${NEW_memcached_ver:-${Latest_memcached_ver}}
  20. if [ "${NEW_memcached_ver}" != "${OLD_memcached_ver}" ]; then
  21. [ "${OUTIP_STATE}"x == "China"x ] && DOWN_ADDR=${mirror_link}/oneinstack/src || DOWN_ADDR=http://www.memcached.org/files
  22. [ ! -e "memcached-${NEW_memcached_ver}.tar.gz" ] && wget --no-check-certificate -c ${DOWN_ADDR}/memcached-${NEW_memcached_ver}.tar.gz > /dev/null 2>&1
  23. if [ -e "memcached-${NEW_memcached_ver}.tar.gz" ]; then
  24. echo "Download [${CMSG}memcached-${NEW_memcached_ver}.tar.gz${CEND}] successfully! "
  25. break
  26. else
  27. echo "${CWARNING}Memcached version does not exist! ${CEND}"
  28. fi
  29. else
  30. echo "${CWARNING}input error! Upgrade Memcached version is the same as the old version${CEND}"
  31. exit
  32. fi
  33. done
  34. if [ -e "memcached-${NEW_memcached_ver}.tar.gz" ]; then
  35. echo "[${CMSG}memcached-${NEW_memcached_ver}.tar.gz${CEND}] found"
  36. if [ "${memcached_flag}" != 'y' ]; then
  37. echo "Press Ctrl+c to cancel or Press any key to continue..."
  38. char=`get_char`
  39. fi
  40. tar xzf memcached-${NEW_memcached_ver}.tar.gz
  41. pushd memcached-${NEW_memcached_ver}
  42. make clean
  43. ./configure --prefix=${memcached_install_dir}
  44. make -j ${THREAD}
  45. if [ -e "memcached" ]; then
  46. echo "Restarting Memcached..."
  47. service memcached stop
  48. make install
  49. service memcached start
  50. popd > /dev/null
  51. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}${OLD_memcached_ver}${CEND} to ${CWARNING}${NEW_memcached_ver}${CEND}"
  52. rm -rf memcached-${NEW_memcached_ver}
  53. else
  54. echo "${CFAILURE}Upgrade Memcached failed! ${CEND}"
  55. fi
  56. fi
  57. popd > /dev/null
  58. }