upgrade_web.sh 8.7 KB

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