diff --git a/package.sh b/package.sh index eef7bfb94ad9f74d2d8a0f679967e915d81ef1b1..2849d1d683bf6730a1df68e1b3a0d245b9502637 100644 --- a/package.sh +++ b/package.sh @@ -1,15 +1,4 @@ #!/bin/bash -OSS_URL=https://sysom.oss-cn-beijing.aliyuncs.com/redis -REDIS_DL_URL=https://download.redis.io/releases -RELEASE=sysomRelease-$(date +"%Y%m%d%H%M%S") -RELEASE_TARGET=${RELEASE}/server/target -RELEASE_REDIS=${RELEASE}/server/redis -SERVERDIR=sysom_server -WEBDIR=sysom_web -SCRIPTDIR=script -TOOLSDIR=tools -REDIS_DIR=redis-5.0.14 -REDIS_PKG=redis-5.0.14.tar.gz check_cmd() { local cmd="$1" @@ -23,48 +12,27 @@ green() { printf '\33[1;32m%b\n\33[0m' "$1" } -###you can ignore the action if the version of redis >= 5.0.0 in the deployment environment### -compile_redis() { - wget ${OSS_URL}/${REDIS_PKG} || wget ${REDIS_DL_URL}/${REDIS_PKG} - if [ ! -e ${REDIS_PKG} ] - then - echo "download ${REDIS_PKG} fail" - exit 1 - fi - tar -zxvf ${REDIS_PKG} - pushd ${REDIS_DIR} - make || exit 1 - popd - mkdir -p ${RELEASE_REDIS} - cp ${REDIS_DIR}/redis.conf ${RELEASE_REDIS}/ - cp ${REDIS_DIR}/src/redis-server ${RELEASE_REDIS}/ - rm -rf ${REDIS_DIR} ${REDIS_PKG} -} - -compile_sysom() { +check_cmd yarn +check_cmd tar - check_cmd yarn - check_cmd tar - - # build web - pushd sysom_web || exit - yarn - yarn build - popd || exit - - ###you can ignore the action if the version of redis >= 5.0.0 in the deployment environment### - compile_redis - - mkdir -p ${RELEASE_TARGET} - cp -r ${SERVERDIR}/ "${RELEASE_TARGET}"/ - cp -r ${TOOLSDIR}/ "${RELEASE}"/ - cp -r ${WEBDIR}/dist/ "${RELEASE_TARGET}"/${WEBDIR}/ - mkdir -p "${RELEASE_TARGET}"/${WEBDIR}/download/ - cp ${TOOLSDIR}/deploy/deploy.sh "${RELEASE}"/ - cp ${TOOLSDIR}/deploy/clear.sh "${RELEASE}"/ - cp -r ${SCRIPTDIR} "${RELEASE}"/ - tar czf "${RELEASE}".tar.gz "${RELEASE}"/ - rm -rf "${RELEASE}" - green "The release pacakge is ${RELEASE}.tar.gz" -} -compile_sysom +RELEASE=sysomRelease-$(date +"%Y%m%d%H%M%S") +SERVERDIR=sysom_server +WEBDIR=sysom_web +SCRIPTDIR=script +TOOLSDIR=tools +# build web +pushd sysom_web || exit +yarn +yarn build +popd || exit + +mkdir -p "${RELEASE}" +cp -r ${SERVERDIR}/ ${TOOLSDIR}/ "${RELEASE}"/ +cp -r ${WEBDIR}/dist/ "${RELEASE}"/${WEBDIR}/ +mkdir -p "${RELEASE}"/${WEBDIR}/download/ +cp ${TOOLSDIR}/deploy/deploy.sh "${RELEASE}"/ +cp ${TOOLSDIR}/deploy/clear.sh "${RELEASE}"/ +cp -r ${SCRIPTDIR} "${RELEASE}"/ +tar czf "${RELEASE}".tar.gz "${RELEASE}"/ +rm -rf "${RELEASE}" +green "The release pacakge is ${RELEASE}.tar.gz" diff --git a/script/server/0_local_services/clear.sh b/script/server/0_local_services/clear.sh index badb537ace1da987be54521eec5cd5bcc7399759..f3904f8a2fca0cb0ad54a8fa9273d309bb8d437b 100755 --- a/script/server/0_local_services/clear.sh +++ b/script/server/0_local_services/clear.sh @@ -1,11 +1,18 @@ #!/bin/bash +SERVICE_NAME=sysom-redis +clear_local_redis() { + rm -rf /etc/supervisord.d/${SERVICE_NAME}.ini + ###use supervisorctl update to stop and clear services### + supervisorctl update +} + stop_redis() { ###we need redis version >= 5.0.0, check redis version### redis_version=`yum list all | grep "^redis.x86_64" | awk '{print $2}' | awk -F"." '{print $1}'` echo ${redis_version} if [ $redis_version -lt 5 ] then - kill -9 `ps -e | grep redis-server | awk '{print $1}'` + clear_local_redis else systemctl stop redis.service fi diff --git a/script/server/0_local_services/init.sh b/script/server/0_local_services/init.sh index 6fd6369542e403ade4ae5ceb4f7c4def328356e3..7f6da660087cf50496c7b5a635b53fde0d3fc8cc 100755 --- a/script/server/0_local_services/init.sh +++ b/script/server/0_local_services/init.sh @@ -3,7 +3,11 @@ # ScriptName: start local service # Author: huangtuquan #***************************************************************# -SERVICE_NAME=sysom-redis +OSS_URL=https://sysom.oss-cn-beijing.aliyuncs.com/redis +REDIS_DL_URL=https://download.redis.io/releases +REDIS_DIR=redis-5.0.14 +REDIS_PKG=redis-5.0.14.tar.gz + usr_local_redis=0 setup_database() { @@ -41,12 +45,35 @@ setup_redis() { echo ${redis_version} if [ $redis_version -lt 5 ] then - init_conf + echo "redis version in yum repo is less than 5.0.0, we will compile redis(5.0.14) and install it." + if [ ! -e ${REDIS_PKG} ] + then + wget ${OSS_URL}/${REDIS_PKG} || wget ${REDIS_DL_URL}/${REDIS_PKG} + if [ ! -e ${REDIS_PKG} ] + then + echo "download ${REDIS_PKG} fail" + exit 1 + fi + fi + echo "now uncompress ${REDIS_PKG}, then compile and install it." + tar -zxvf ${REDIS_PKG} + pushd ${REDIS_DIR} + make + mkdir -p ${SERVER_HOME}/redis + cp redis.conf ${SERVER_HOME}/redis/ + cp src/redis-server ${SERVER_HOME}/redis/ + if [ $? -ne 0 ] + then + echo "redis compile or install error, exit 1" + exit 1 + fi usr_local_redis=1 + popd fi } start_local_redis() { + init_conf ###if supervisor service started, we need use "supervisorctl update" to start new conf#### supervisorctl update supervisorctl status ${SERVICE_NAME} @@ -62,6 +89,7 @@ start_local_redis() { start_app() { systemctl enable nginx.service systemctl restart nginx.service + systemctl start supervisord if [ $usr_local_redis == 1 ] then ###if redis systemd service has been start, we need stop it first### @@ -75,7 +103,6 @@ start_app() { systemctl enable redis.service systemctl restart redis.service fi - systemctl start supervisord } deploy() { diff --git a/script/server/0_local_services/start.sh b/script/server/0_local_services/start.sh index 5f74ad870e580ef1734ba6d0027040b6c170b40b..0f32583c94a17a9dcc2db8b3ddf5303237743e58 100755 --- a/script/server/0_local_services/start.sh +++ b/script/server/0_local_services/start.sh @@ -1,11 +1,16 @@ #!/bin/bash +SERVICE_NAME=sysom-redis +start_local_redis() { + supervisorctl start $SERVICE_NAME +} + start_redis() { ###we need redis version >= 5.0.0, check redis version### redis_version=`yum list all | grep "^redis.x86_64" | awk '{print $2}' | awk -F"." '{print $1}'` echo ${redis_version} if [ $redis_version -lt 5 ] then - /usr/local/bin/redis-server /usr/local/bin/redis.conf & + start_local_redis else systemctl start redis.service fi diff --git a/script/server/0_local_services/stop.sh b/script/server/0_local_services/stop.sh index 3860753db8a83b8573eb3ee39e308e4ce3982a24..9dda6548164cd3e37d81f80fe8157f3b3488562c 100755 --- a/script/server/0_local_services/stop.sh +++ b/script/server/0_local_services/stop.sh @@ -1,11 +1,15 @@ #!/bin/bash +SERVICE_NAME=sysom-redis +stop_local_redis() { + supervisorctl stop $SERVICE_NAME +} stop_redis() { ###we need redis version >= 5.0.0, check redis version### redis_version=`yum list all | grep "^redis.x86_64" | awk '{print $2}' | awk -F"." '{print $1}'` echo ${redis_version} if [ $redis_version -lt 5 ] then - kill -9 `ps -e | grep redis-server | awk '{print $1}'` + stop_local_redis else systemctl stop redis.service fi diff --git a/script/server/init.sh b/script/server/init.sh index 58aaead49184d16b9a29dbfd179ab46c5fc88b34..fdfd0829893322f5b9b5495ebec3bfbed9500210 100644 --- a/script/server/init.sh +++ b/script/server/init.sh @@ -9,7 +9,7 @@ fi if [ "$APP_HOME" == "" ] then - export APP_HOME=/usr/local/sysom/ + export APP_HOME=/usr/local/sysom export SERVER_HOME=/usr/local/sysom/server export NODE_HOME=/usr/local/sysom/node fi diff --git a/tools/deploy/deploy.sh b/tools/deploy/deploy.sh index 708297404f5c868588e8fad3a4938f2e2e572aae..027b9a6ec474c6efb1f84d10d90e8be749515b4e 100755 --- a/tools/deploy/deploy.sh +++ b/tools/deploy/deploy.sh @@ -7,7 +7,7 @@ # Function: deploy sysom #***************************************************************# APP_NAME="sysom" -SERVER_DIR="server" +SERVER_DIR="sysom_server" WEB_DIR="sysom_web" SCRIPT_DIR="script" APP_HOME=/usr/local/sysom @@ -55,9 +55,11 @@ update_target() { if [ -d "${TARGET_PATH}" ]; then rm -rf ${TARGET_PATH} fi + mkdir -p ${TARGET_PATH} echo "INFO: copy project file..." - cp -r ${SERVER_DIR}/* ${SERVER_HOME}/ + cp -r ${SERVER_DIR} ${WEB_DIR} ${TARGET_PATH} cp -r ${SCRIPT_DIR} ${APP_HOME}/init_scripts + cp tools/deploy/sysom-server.service /usr/lib/systemd/system/ } start_script_server() {