upgrade_web.sh 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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_Nginx() {
  11. cd $oneinstack_dir/src
  12. [ ! -e "$nginx_install_dir/sbin/nginx" ] && echo "${CWARNING}The Nginx is not installed on your system! ${CEND}" && exit 1
  13. OLD_Nginx_version_tmp=`$nginx_install_dir/sbin/nginx -v 2>&1`
  14. OLD_Nginx_version=${OLD_Nginx_version_tmp##*/}
  15. echo
  16. echo "Current Nginx Version: ${CMSG}$OLD_Nginx_version${CEND}"
  17. while :; do echo
  18. read -p "Please input upgrade Nginx Version(example: 1.9.15): " NEW_Nginx_version
  19. if [ "$NEW_Nginx_version" != "$OLD_Nginx_version" ];then
  20. [ ! -e "nginx-$NEW_Nginx_version.tar.gz" ] && wget --no-check-certificate -c http://nginx.org/download/nginx-$NEW_Nginx_version.tar.gz > /dev/null 2>&1
  21. if [ -e "nginx-$NEW_Nginx_version.tar.gz" ];then
  22. src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-$pcre_version.tar.gz && Download_src
  23. tar xzf pcre-$pcre_version.tar.gz
  24. echo "Download [${CMSG}nginx-$NEW_Nginx_version.tar.gz${CEND}] successfully! "
  25. break
  26. else
  27. echo "${CWARNING}Nginx version does not exist! ${CEND}"
  28. fi
  29. else
  30. echo "${CWARNING}input error! The upgrade Nginx version is the same as the old version${CEND}"
  31. fi
  32. done
  33. if [ -e "nginx-$NEW_Nginx_version.tar.gz" ];then
  34. echo "[${CMSG}nginx-$NEW_Nginx_version.tar.gz${CEND}] found"
  35. echo "Press Ctrl+c to cancel or Press any key to continue..."
  36. char=`get_char`
  37. tar xzf nginx-$NEW_Nginx_version.tar.gz
  38. cd nginx-$NEW_Nginx_version
  39. make clean
  40. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc # close debug
  41. $nginx_install_dir/sbin/nginx -V &> $$
  42. nginx_configure_arguments=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  43. rm -rf $$
  44. ./configure $nginx_configure_arguments
  45. make -j ${THREAD}
  46. if [ -f "objs/nginx" ];then
  47. /bin/mv $nginx_install_dir/sbin/nginx $nginx_install_dir/sbin/nginx$(date +%m%d)
  48. /bin/cp objs/nginx $nginx_install_dir/sbin/nginx
  49. kill -USR2 `cat /var/run/nginx.pid`
  50. sleep 1
  51. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  52. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_Nginx_version${CEND} to ${CWARNING}$NEW_Nginx_version${CEND}"
  53. else
  54. echo "${CFAILURE}Upgrade Nginx failed! ${CEND}"
  55. fi
  56. cd ..
  57. fi
  58. cd ..
  59. }
  60. Upgrade_Tengine() {
  61. cd $oneinstack_dir/src
  62. [ ! -e "$tengine_install_dir/sbin/nginx" ] && echo "${CWARNING}The Tengine is not installed on your system! ${CEND}" && exit 1
  63. OLD_Tengine_version_tmp=`$tengine_install_dir/sbin/nginx -v 2>&1`
  64. OLD_Tengine_version="`echo ${OLD_Tengine_version_tmp#*/} | awk '{print $1}'`"
  65. echo
  66. echo "Current Tengine Version: ${CMSG}$OLD_Tengine_version${CEND}"
  67. while :; do echo
  68. read -p "Please input upgrade Tengine Version(example: 2.1.15): " NEW_Tengine_version
  69. if [ "$NEW_Tengine_version" != "$OLD_Tengine_version" ];then
  70. [ ! -e "tengine-$NEW_Tengine_version.tar.gz" ] && wget --no-check-certificate -c http://tengine.taobao.org/download/tengine-$NEW_Tengine_version.tar.gz > /dev/null 2>&1
  71. if [ -e "tengine-$NEW_Tengine_version.tar.gz" ];then
  72. src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-$pcre_version.tar.gz && Download_src
  73. tar xzf pcre-$pcre_version.tar.gz
  74. echo "Download [${CMSG}tengine-$NEW_Tengine_version.tar.gz${CEND}] successfully! "
  75. break
  76. else
  77. echo "${CWARNING}Tengine version does not exist! ${CEND}"
  78. fi
  79. else
  80. echo "${CWARNING}input error! The upgrade Tengine version is the same as the old version${CEND}"
  81. fi
  82. done
  83. if [ -e "tengine-$NEW_Tengine_version.tar.gz" ];then
  84. echo "[${CMSG}tengine-$NEW_Tengine_version.tar.gz${CEND}] found"
  85. echo "Press Ctrl+c to cancel or Press any key to continue..."
  86. char=`get_char`
  87. tar xzf tengine-$NEW_Tengine_version.tar.gz
  88. cd tengine-$NEW_Tengine_version
  89. make clean
  90. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc # close debug
  91. $tengine_install_dir/sbin/nginx -V &> $$
  92. tengine_configure_arguments=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  93. rm -rf $$
  94. ./configure $tengine_configure_arguments
  95. make -j ${THREAD}
  96. if [ -f "objs/nginx" ];then
  97. /bin/mv $tengine_install_dir/sbin/nginx $tengine_install_dir/sbin/nginx$(date +%m%d)
  98. /bin/mv $tengine_install_dir/sbin/dso_tool $tengine_install_dir/sbin/dso_tool$(date +%m%d)
  99. /bin/mv $tengine_install_dir/modules $tengine_install_dir/modules$(date +%m%d)
  100. /bin/cp objs/nginx $tengine_install_dir/sbin/nginx
  101. /bin/cp objs/dso_tool $tengine_install_dir/sbin/dso_tool
  102. chmod +x $tengine_install_dir/sbin/*
  103. make install
  104. kill -USR2 `cat /var/run/nginx.pid`
  105. sleep 1
  106. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  107. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_Tengine_version${CEND} to ${CWARNING}$NEW_Tengine_version${CEND}"
  108. else
  109. echo "${CFAILURE}Upgrade Tengine failed! ${CEND}"
  110. fi
  111. cd ..
  112. fi
  113. cd ..
  114. }
  115. Upgrade_OpenResty() {
  116. cd $oneinstack_dir/src
  117. [ ! -e "$openresty_install_dir/nginx/sbin/nginx" ] && echo "${CWARNING}The OpenResty is not installed on your system! ${CEND}" && exit 1
  118. OLD_OpenResty_version_tmp=`$openresty_install_dir/nginx/sbin/nginx -v 2>&1`
  119. OLD_OpenResty_version="`echo ${OLD_OpenResty_version_tmp#*/} | awk '{print $1}'`"
  120. echo
  121. echo "Current OpenResty Version: ${CMSG}$OLD_OpenResty_version${CEND}"
  122. while :; do echo
  123. read -p "Please input upgrade OpenResty Version(example: 1.9.7.19): " NEW_OpenResty_version
  124. if [ "$NEW_OpenResty_version" != "$OLD_OpenResty_version" ];then
  125. [ ! -e "openresty-$NEW_OpenResty_version.tar.gz" ] && wget --no-check-certificate -c https://openresty.org/download/openresty-$NEW_OpenResty_version.tar.gz > /dev/null 2>&1
  126. if [ -e "openresty-$NEW_OpenResty_version.tar.gz" ];then
  127. src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-$pcre_version.tar.gz && Download_src
  128. tar xzf pcre-$pcre_version.tar.gz
  129. echo "Download [${CMSG}openresty-$NEW_OpenResty_version.tar.gz${CEND}] successfully! "
  130. break
  131. else
  132. echo "${CWARNING}OpenResty version does not exist! ${CEND}"
  133. fi
  134. else
  135. echo "${CWARNING}input error! The upgrade OpenResty version is the same as the old version${CEND}"
  136. fi
  137. done
  138. if [ -e "openresty-$NEW_OpenResty_version.tar.gz" ];then
  139. echo "[${CMSG}openresty-$NEW_OpenResty_version.tar.gz${CEND}] found"
  140. echo "Press Ctrl+c to cancel or Press any key to continue..."
  141. char=`get_char`
  142. tar xzf openresty-$NEW_OpenResty_version.tar.gz
  143. cd openresty-$NEW_OpenResty_version
  144. make clean
  145. openresty_version_tmp=${NEW_OpenResty_version%.*}
  146. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' bundle/nginx-$openresty_version_tmp/auto/cc/gcc # close debug
  147. $openresty_install_dir/nginx/sbin/nginx -V &> $$
  148. openresty_configure_arguments=`cat $$ | grep 'configure arguments:' | awk -F: '{print $2}'`
  149. rm -rf $$
  150. [ -n "`echo $openresty_configure_arguments | grep jemalloc`"] && malloc_module="--with-ld-opt='-ljemalloc'"
  151. [ -n "`echo $openresty_configure_arguments | grep perftools`" ] && malloc_module='--with-google_perftools_module'
  152. ./configure --prefix=$openresty_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-pcre=../pcre-$pcre_version --with-pcre-jit $malloc_module
  153. make -j ${THREAD}
  154. if [ -f "build/nginx-$openresty_version_tmp/objs/nginx" ];then
  155. /bin/mv $openresty_install_dir/nginx/sbin/nginx $openresty_install_dir/nginx/sbin/nginx$(date +%m%d)
  156. make install
  157. kill -USR2 `cat /var/run/nginx.pid`
  158. sleep 1
  159. kill -QUIT `cat /var/run/nginx.pid.oldbin`
  160. echo "You have ${CMSG}successfully${CEND} upgrade from ${CWARNING}$OLD_OpenResty_version${CEND} to ${CWARNING}$NEW_OpenResty_version${CEND}"
  161. else
  162. echo "${CFAILURE}Upgrade OpenResty failed! ${CEND}"
  163. fi
  164. cd ..
  165. fi
  166. cd ..
  167. }