#!/bin/bash
set -x
cd ../../utils
. ./sys_info.sh
. ./sh-test-lib
cd -
#得到$1的绝对地址
INSTALLDIR=$(cd $1; pwd)
HOST=$distro
PKG_NAME="hhvm"
PKG_VER="3.17.3"
#发行版是centos的话,需要一次性安装这么多包
case $HOST in
centos)
echo "[$PKG_NAME] install package on $HOST system"
# install hhvm dependent packages
yum install tbb libdwarf freetype libjpeg-turbo ImageMagick libmemcached libxslt libyaml libtiff fontconfig libXext libXt libtool-ltdl \
libSM libICE libX11 libgomp cyrus-sasl jbigkit libxcb libXau -y
print_info $? install-dependent-packages
yum install -y curl nginx
print_info $? install-nginx
;;
esac
#将这个路径压栈
pushd $INSTALLDIR/packages/$PKG_NAME-$PKG_VER
#如果不存在这个文件的话,则通过wget下载
if [ ! -e ./${PKG_NAME}-${PKG_VER}-${HOST}.aarch64.tar.gz ];then
echo "[$PKG_NAME] the tarball is not exist"
wget http://htsat.vicp.cc:804/hhvm/${PKG_NAME}-${PKG_VER}-${HOST}.aarch64.tar.gz
fi
print_info $? download-hhvm-tarball
#不存在这个目录,则新建这个目录
if [ ! -d ${INSTALLDIR}/bin ];then
mkdir -p $INSTALLDIR/bin
fi
if [ ! -d ${INSTALLDIR}/etc/hhvm ];then
mkdir -p ${INSTALLDIR}/etc/hhvm
fi
#解压这个tar包
tar -xzvf ./${PKG_NAME}-${PKG_VER}-${HOST}.aarch64.tar.gz
print_info $? unzip-hhvm-file
#执行sigecp 命令,通过飘键得到cp执行的结果,
r1=`cp -fr ./bin/* $INSTALLDIR/bin`
r2=`cp -fr ./hhvm/config.hdf $INSTALLDIR/etc/hhvm`
r3=`cp -fr ./hhvm/php.ini $INSTALLDIR/etc/hhvm`
r4=`cp -fr ./hhvm/server.ini $INSTALLDIR/etc/hhvm`
r5=`rm -fr ./bin ./hhvm`
#cp 执行返回的值为零的话,表示执行成功
if [ ! $r1 ] && [ ! $r2 ] && [ ! $r3 ] && [ ! $r4 ] && [ ! $r5 ];then
print_info 0 prepare-config-files
else
print_info 1 prepare-config-files
fi
popd > /dev/null
echo "setup hhvm successfully"
#这里用test 测试是否存在目录,不存在的话,则通过mkdir 新建这个目录
#用if判断的话,需要写3行,用test的话一行就ok了。
#prepare test env
test ! -d /var/run/hhvm && mkdir -p /var/run/hhvm
test ! -d /var/log/hhvm && mkdir -p /var/log/hhvm
cp ./conf/nginx.conf* /etc/nginx/ -fr
test ! -d $INSTALLDIR/etc/hhvm && mkdir -p $INSTALLDIR/etc/hhvm
cp ./test_page/test_*.php /usr/share/nginx/html/ -fr
print_info $? copy-php-to-webserver
#这里可以用which得到nginx的路径后,执行,这样可以避免在这里写死路径
/usr/sbin/nginx -c /etc/nginx/nginx.conf
#-o 后表示保存的name
curl -o "./index" "http://localhost/index.html"
grep "nginx" "./index"
print_info $? start-nginx
#导出全局变量.
export LD_LIBRARY_PATH=$INSTALLDIR/packages/boost-1.58.0/lib:$LD_LIBRARY_PATH
#create run and log directory
#不存在目录的话,则新建。这里完全可以用test代替
if [ ! -d /var/run/hhvm ];then
mkdir -p /var/run/hhvm
fi
if [ ! -d /var/log/hhvm ];then
mkdir -p /var/log/hhvm
fi
#start hhvm service
if [ ! -e $INSTALLDIR/bin/hhvm ];then
echo "[$PKG_NAME] hhvm has not installed ,please install it firtly"
print_info 1 start-hhvm
else
#启动hhvm
$INSTALLDIR/bin/hhvm --mode daemon --config $INSTALLDIR/etc/hhvm/server.ini --config $INSTALLDIR/etc/hhvm/php.ini --config $INSTALLDIR/etc/hhvm/config.hdf
print_info $? start-hhvm
echo "[$PKG_NAME] start hhvm service successfully"
fi
ps -aux | grep nginx -wc
ps -aux | grep hhvm -wc
# HHVM is work or not
#下载保存文件,并在文件中查找关键字符串
curl -o "./test_hhvm" "http://localhost/test_hhvm.php"
grep "HHVM is working" "./test_hhvm"
print_info $? hhvm-work-status
#remove
#kill the nginx and hhvm process
unset LD_LIBRARY_PATH
print_info $? unset-lib-path
#如果找到ngix的进程,通过pidof 根据进程name拿到pid,在通过kill 杀掉这个进程
count=`ps -aux | grep nginx | wc -l`
if [ $count -gt 0 ];then
kill -9 $(pidof nginx)
print_info $? kill-nginx
fi
count=`ps -aux | grep hhvm | wc -l`
if [ $count -gt 0 ];then
kill -9 $(pidof hhvm)
print_info $? kill-hhvm
fi
#如果存在下面的目录则删除
#remove the binary and configuration files of hhvm
if [ -d /usr/estuary/bin/hhvm ];then
rm -fr /usr/estuary/bin/hhvm
fi
if [ -d /usr/estuary/etc/hhvm ];then
rm -fr /usr/estuary/etc/hhvm
fi
if [ -d /usr/estuary/etc/nginx ];then
rm -fr /usr/estuary/etc/nginx
fi
print_info $? remove-hhvm