mdserver-web/plugins/openresty/install.sh

122 lines
2.8 KiB
Bash
Raw Normal View History

2018-11-25 04:48:48 -05:00
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
curPath=`pwd`
rootPath=$(dirname "$curPath")
rootPath=$(dirname "$rootPath")
serverPath=$(dirname "$rootPath")
2018-12-04 22:01:25 -05:00
action=$1
type=$2
2018-11-25 04:48:48 -05:00
2020-06-28 01:44:38 -04:00
VERSION=$2
install_tmp=${rootPath}/tmp/mw_install.pl
openrestyDir=${serverPath}/source/openresty
2019-02-02 09:13:51 -05:00
if id www &> /dev/null ;then
2022-11-01 08:27:20 -04:00
echo "www uid is `id -u www`"
echo "www shell is `grep "^www:" /etc/passwd |cut -d':' -f7 `"
2019-02-02 09:13:51 -05:00
else
groupadd www
2020-09-28 00:52:11 -04:00
useradd -g www -s /bin/bash www
2019-02-02 09:13:51 -05:00
fi
2020-06-28 01:44:38 -04:00
Install_openresty()
{
2022-11-18 11:46:08 -05:00
if [ -d $serverPath/openresty ];then
exit 0
fi
2022-08-01 01:34:40 -04:00
# ----- cpu start ------
if [ -z "${cpuCore}" ]; then
cpuCore="1"
fi
if [ -f /proc/cpuinfo ];then
cpuCore=`cat /proc/cpuinfo | grep "processor" | wc -l`
fi
MEM_INFO=$(free -m|grep Mem|awk '{printf("%.f",($2)/1024)}')
if [ "${cpuCore}" != "1" ] && [ "${MEM_INFO}" != "0" ];then
if [ "${cpuCore}" -gt "${MEM_INFO}" ];then
cpuCore="${MEM_INFO}"
fi
else
cpuCore="1"
2022-08-01 01:34:40 -04:00
fi
2022-11-04 10:17:57 -04:00
2022-11-05 22:10:34 -04:00
if [ "$cpuCore" -gt "2" ];then
cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'`
else
cpuCore="1"
2022-11-04 10:17:57 -04:00
fi
2022-08-01 01:34:40 -04:00
# ----- cpu end ------
2020-06-28 01:44:38 -04:00
mkdir -p ${openrestyDir}
echo '正在安装脚本文件...' > $install_tmp
if [ ! -f ${openrestyDir}/openresty-${VERSION}.tar.gz ];then
wget -O ${openrestyDir}/openresty-${VERSION}.tar.gz https://openresty.org/download/openresty-${VERSION}.tar.gz
fi
cd ${openrestyDir} && tar -zxvf openresty-${VERSION}.tar.gz
2020-07-13 20:38:10 -04:00
# --with-openssl=$serverPath/source/lib/openssl-1.0.2q
2022-06-22 12:48:52 -04:00
cd ${openrestyDir}/openresty-${VERSION} && ./configure \
--prefix=$serverPath/openresty \
2022-09-06 22:16:03 -04:00
--with-ipv6 \
2022-10-27 11:44:40 -04:00
--with-stream \
2020-06-28 01:44:38 -04:00
--with-http_v2_module \
2020-07-13 20:38:10 -04:00
--with-http_ssl_module \
2021-01-12 00:13:30 -05:00
--with-http_slice_module \
2022-09-02 11:16:41 -04:00
--with-http_stub_status_module \
2022-11-04 09:03:06 -04:00
--with-http_sub_module \
2022-09-02 11:16:41 -04:00
--with-http_realip_module
2022-10-12 13:10:03 -04:00
# --without-luajit-gc64
2022-10-12 16:18:47 -04:00
# --with-debug
2022-10-12 13:10:03 -04:00
# 用于调式
2022-06-22 08:46:10 -04:00
2022-08-01 01:34:40 -04:00
make -j${cpuCore} && make install && make clean
2022-06-22 08:46:10 -04:00
2022-06-22 12:48:52 -04:00
if [ -d $serverPath/openresty ];then
echo "${VERSION}" > $serverPath/openresty/version.pl
2022-06-29 22:51:54 -04:00
mkdir -p $serverPath/web_conf/php/conf
2022-07-04 21:04:14 -04:00
echo 'set $PHP_ENV 0;' > $serverPath/web_conf/php/conf/enable-php-00.conf
2022-06-28 13:07:25 -04:00
#初始化
2022-06-28 13:31:34 -04:00
cd ${rootPath} && python3 ${rootPath}/plugins/openresty/index.py start
cd ${rootPath} && python3 ${rootPath}/plugins/openresty/index.py initd_install
2022-11-04 10:17:57 -04:00
rm -rf $openrestyDir
2022-06-22 12:48:52 -04:00
fi
2020-06-28 01:44:38 -04:00
echo '安装完成' > $install_tmp
}
Uninstall_openresty()
{
2022-06-28 13:07:25 -04:00
2022-07-11 03:19:39 -04:00
if [ -f /usr/lib/systemd/system/openresty.service ] || [ -f /lib/systemd/system/openresty.service ];then
2022-06-28 13:07:25 -04:00
systemctl stop openresty
2022-07-03 10:08:21 -04:00
rm -rf /usr/systemd/system/openresty.service
2022-07-11 03:19:39 -04:00
rm -rf /lib/systemd/system/openresty.service
2022-06-28 13:31:34 -04:00
systemctl daemon-reload
fi
if [ -f $serverPath/openresty/init.d/openresty ];then
$serverPath/openresty/init.d/openresty stop
2022-06-18 03:44:17 -04:00
fi
2022-06-28 13:07:25 -04:00
rm -rf $serverPath/openresty
2020-06-28 01:44:38 -04:00
echo '卸载完成' > $install_tmp
}
action=$1
if [ "${1}" == 'install' ];then
Install_openresty
else
Uninstall_openresty
fi