赞
踩
nodejs构建配置
注意:下图的dist是vue项目打包目录名称,根据实际名称配置
- # input your command here
- cnpm cache clean --force
- cnpm install
- cnpm run build
主机部署配置
- rm -rf /home/vipcardmall/frontend/
- mkdir -p /home/vipcardmall/frontend
- #解压构建的dist压缩包到指定目录
- tar zxvf /home/flowapp/vip_card_mall_user_frontend_v2.tgz -C /home/vipcardmall/frontend
- #删除dist压缩包
- rm -rf /home/flowapp/vip_card_mall_user_frontend_v2.tgz
下图红框的是webhook触发地址,通过post/json触发,触发后会自动触发流水线,请求参数{},触发成功返回
- {
- "object": true,
- "successful": true
- }
deploy.sh
- #!/bin/bash
-
- #---------------------------配置开始----------------------------------
- # 修改APP_NAME为云效上的应用名
- APP_NAME=openapi-service-0.0.1-SNAPSHOT
- PROG_NAME=$0
- ACTION=$1
- APP_START_TIMEOUT_SECONDS=70 # 等待应用启动的时间(秒)
- APP_PORT=6677 # 应用端口
- BASE_URL=http://127.0.0.1:${APP_PORT}/openapi-service # 应用的基础URL
- HEALTH_CHECK_URL=${BASE_URL}/common/heartCheck # 应用健康检查URL
- APP_HOME=/home/backend/openapi # 从package.tgz中解压出来的jar包放到这个目录下
- JAR_NAME=${APP_HOME}/${APP_NAME}.jar # jar包的名字
- JAVA_OUT=${APP_HOME}/prod.log #应用的启动日志
- PACKAGE_PATH=/home/flowapp/mall-openapi.tgz #制品路径
- SHUTDOWN_URL=${BASE_URL}/common/actuator/shutdown #优雅关闭地址
- SHUTDOWN_TIMEOUT_SECONDS=70 #优雅停机超时时间(秒)
- SPRING_PROFILE="prod" # The Spring profile to activate
- #---------------------------配置结束----------------------------------
-
-
- # 创建出相关目录
- mkdir -p ${APP_HOME}
- usage() {
- echo "Usage: $PROG_NAME {start|stop|restart}"
- exit 2
- }
-
- health_check() {
- exptime=0
- echo "checking ${HEALTH_CHECK_URL}"
- while true
- do
- status_code=`/usr/bin/curl -L -o /dev/null --connect-timeout 5 -s -w %{http_code} ${HEALTH_CHECK_URL}`
- if [ "$?" != "0" ]; then
- echo -n -e "\rapplication not started"
- else
- echo "code is $status_code"
- if [ "$status_code" == "200" ];then
- break
- fi
- fi
- sleep 1
- ((exptime++))
-
- echo -e "\rWait app to pass health check: $exptime..."
-
- if [ $exptime -gt ${APP_START_TIMEOUT_SECONDS} ]; then
- echo 'app start failed'
- exit 1
- fi
- done
- echo "check ${HEALTH_CHECK_URL} success"
- }
- start_application() {
- echo "starting java process"
- nohup java -jar -Xmx512m -Xms256m -Dspring.profiles.active=${SPRING_PROFILE} -Dserver.port=${APP_PORT} ${JAR_NAME} >${JAVA_OUT} 2>&1 &
- echo "started java process"
- }
-
- stop_application() {
- # 查找Java进程ID
- checkjavapid=$(ps -ef | grep java | grep ${APP_NAME} | grep ${APP_PORT} | grep -v grep | awk '{print $2}')
-
- # 如果没有发现Java进程,则直接返回
- if [[ ! $checkjavapid ]]; then
- echo "No java process to stop (process not found)"
- return
- fi
-
- # 向Java进程发送SIGTERM请求
- echo "Sending SIGTERM to Java process with PID ${checkjavapid}."
- kill -15 ${checkjavapid}
-
- # 等待Java进程停止
- for ((i=0; i<$SHUTDOWN_TIMEOUT_SECONDS; i++)); do
- # 使用curl检查心跳接口
- http_status=$(curl -o /dev/null -s -w "%{http_code}\n" ${HEALTH_CHECK_URL})
-
- # 如果状态码不是200,认为进程已经停止
- if [ "$http_status" != "200" ]; then
- echo "Java process stopped successfully."
- return
- fi
-
- sleep 1
- echo "Waiting for Java process to stop..."
- done
-
- # 如果Java进程在等待时间后仍然存在,则发送SIGKILL
- echo "Java process did not stop after $SHUTDOWN_TIMEOUT_SECONDS seconds, sending SIGKILL"
- kill -9 $checkjavapid
- echo "Java process killed forcefully"
- }
-
- start() {
- start_application
- health_check
- }
- stop() {
- stop_application
- }
- deploy() {
- # 停止应用程序
- stop
-
- # 解压PACKAGE_PATH文件到APP_HOME目录
- echo "Unpacking $PACKAGE_PATH to $APP_HOME"
- if tar zxvf $PACKAGE_PATH -C $APP_HOME; then
- echo "Unpack finished successfully."
-
- # 删除原始压缩包
- echo "Removing the package $PACKAGE_PATH"
- rm -f $PACKAGE_PATH
- if [ $? -eq 0 ]; then
- echo "Package removed successfully."
- else
- echo "Failed to remove the package."
- fi
- else
- echo "Error occurred during unpacking. Exiting."
- exit 1
- fi
-
- # 启动应用程序
- start
- }
-
- case "$ACTION" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart)
- stop
- start
- ;;
- deploy)
- deploy
- ;;
- *)
- usage
- ;;
- esac
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。