Last active
May 28, 2018 09:52
-
-
Save emacsist/9e9a01b9407941348f1f55cd70e3f22b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
OPENSSL_VERSION="openssl-1.1.0h" | |
# wget http://nginx.org/download/nginx-1.13.12.tar.gz . | |
NGINX_VERSION="nginx-1.13.12" | |
# 旧版的 nginx 路径 | |
OLD_NGINX_PATH="${HOME}/nginx/nginx-1.2.2" | |
BASE_DIR="${HOME}/nginx" | |
NGINX_PATH=${BASE_DIR}/${NGINX_VERSION} | |
function prepare(){ | |
sudo apt-get update -y | |
sudo apt-get install libpcre3-dev libssl-dev perl make build-essential curl wget -y | |
mkdir -p ${NGINX_PATH} ${OPENSSL_PATH} | |
} | |
function actionSSL(){ | |
cd ${BASE_DIR} | |
if [ ! -f "${BASE_DIR}/${OPENSSL_VERSION}.tar.gz" ]; then | |
wget https://www.openssl.org/source/${OPENSSL_VERSION}.tar.gz | |
fi | |
if [ ! -d "${BASE_DIR}/${OPENSSL_VERSION}-src" ];then | |
tar -xvf ${OPENSSL_VERSION}.tar.gz | |
mv ${OPENSSL_VERSION} ${OPENSSL_VERSION}-src | |
fi | |
cd ${OPENSSL_VERSION}-src | |
./config --prefix=${HOME}/nginx/${OPENSSL_VERSION} && make -j8 && echo "compile openSSL ok..." | |
} | |
function actionNginx(){ | |
cd ${BASE_DIR} | |
if [ ! -f "${OPENSSL_VERSION}.tar.gz" ];then | |
echo "openssl not found !!" | |
exit 1 | |
fi | |
if [ ! -f "${BASE_DIR}/${NGINX_VERSION}.tar.gz" ]; then | |
wget http://nginx.org/download/${NGINX_VERSION}.tar.gz | |
fi | |
if [ ! -d "${BASE_DIR}/${NGINX_VERSION}-src" ]; then | |
tar -xvf ${NGINX_VERSION}.tar.gz | |
mv ${NGINX_VERSION} ${NGINX_VERSION}-src | |
fi | |
cd ${NGINX_VERSION}-src | |
./configure --prefix="${OLD_NGINX_PATH}" --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_v2_module --with-openssl="${BASE_DIR}/${OPENSSL_VERSION}-src" | |
make -j8 | |
} | |
function autoUpgrade(){ | |
cd ${BASE_DIR} | |
cp "${OLD_NGINX_PATH}/sbin/nginx" "${OLD_NGINX_PATH}/sbin/nginx.orinal.bak" | |
rm "${OLD_NGINX_PATH}/sbin/nginx" | |
echo "backup nginx bin ok..." | |
cp "${NGINX_VERSION}-src/objs/nginx" "${OLD_NGINX_PATH}/sbin/nginx" | |
sudo kill -USR2 `cat ${OLD_NGINX_PATH}/logs/nginx.pid` && echo "kill -USR2 command status: $?" | |
sudo kill -WINCH `cat ${OLD_NGINX_PATH}/logs/nginx.pid.oldbin` && echo "kill -WINCH command status: $?" | |
sleep 10 | |
sudo kill -QUIT `cat ${OLD_NGINX_PATH}/logs/nginx.pid.oldbin` && echo "kill -QUIT command status: $?" | |
} | |
function main(){ | |
prepare | |
actionSSL | |
actionNginx | |
echo "---------------------^_^ OK...---------------------" | |
autoUpgrade | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment