shell 打包发布脚本

  1. #!/bin/bash
  2. #author cl*
  3. CODE_DIR="codedir"
  4. PACKAGED_NAME="packagename"
  5. GIT_PROJECT_NAME="projectname"
  6. GIT_BRANCH_NAME="branchname"
  7. APP_DEPLOY_PATH="deploypath"
  8. PROFILE="prd"
  9. PORT=9096
  10. #如果任何语句的执行结果不是 true 则应该退出
  11. set -e
  12. #git 初始化配置,配置后,无需手动输入用户名及密码即可从指定 git 管理代码
  13. function gitinit(){
  14. echo "start gitinit..."
  15. cd ~/
  16. touch .git-credentials
  17. echo "http://username:password@xxx.xxx.xxx.xxx" > .git-credentials
  18. git config --global credential.helper store
  19. #执行此句后 ~/.gitconfig 文件多了一项 [credential] helper = store
  20. echo "finish gitinit..."
  21. }
  22. #pull and package gitcodeResource
  23. function package(){
  24. echo "start pull git resource code..."
  25. rm -rf ./$CODE_DIR
  26. git clone http://xxx.xxx.xxx.xxx/Card/$GIT_PROJECT_NAME.git
  27. cd ./$CODE_DIR
  28. git checkout $GIT_BRANCH_NAME
  29. echo "git checkout succeed ..."
  30. echo "starting packaging app ..."
  31. mvn clean package -Dmaven.test.skip=true
  32. echo "packaging app success ..."
  33. }
  34. #code deploy
  35. function deploy(){
  36. cd $APP_DEPLOY_PATH
  37. shutdown
  38. echo "rename last version..."
  39. if [ -f $PACKAGED_NAME.jar ]
  40. then
  41. mv $PACKAGED_NAME.jar $PACKAGED_NAME'_'`date +%Y%m%d%H%M%S`.jar
  42. fi
  43. echo "copy jar..."
  44. cp $APP_DEPLOY_PATH/$CODE_DIR/target/$PACKAGED_NAME.jar $APP_DEPLOY_PATH
  45. echo "start member@"$PORT
  46. startup
  47. }
  48. #app shutdown
  49. function shutdown(){
  50. PID=$(ps -ef | grep $PACKAGED_NAME.jar | grep -v grep | awk '{print $2}')
  51. if [ -z "$PID" ]
  52. then
  53. echo Application is already stopped
  54. else
  55. echo kill $PID
  56. kill -9 $PID
  57. fi
  58. }
  59. #app startup
  60. function startup(){
  61. echo "startuping"$GIT_BRANCH_NAME"..."
  62. export JAVA_HOME=$JAVA_HOME
  63. nohup java -server -Xms512M -Xmx512M -Xss256k \
  64. -XX:+UseStringDeduplication \
  65. -XX:+HeapDumpOnOutOfMemoryError \
  66. -jar $PACKAGED_NAME.jar \
  67. --server.port=$PORT \
  68. --spring.profiles.active=$PROFILE \
  69. > /dev/null 2>&1 &
  70. echo "startuping success ..."
  71. echo "打开端口:"$PORT"..."
  72. firewall-cmd --zone=public --add-port=$PORT/tcp --permanent
  73. }
  74. #pring helpinfo
  75. function help(){
  76. echo "Usage: ./onekey.sh [gitinit|package|deploy|startup|shutdown|help]"
  77. echo "gitinit: 初始化 git 设置"
  78. echo "package: 程序打包"
  79. echo "deploy: 程序发布"
  80. echo "startup: 程序启动"
  81. echo "shutdown: 程序关闭"
  82. echo "help: 打印帮助信息"
  83. }
  84. case "$1" in
  85. 'gitinit')
  86. gitinit
  87. ;;
  88. 'package')
  89. package
  90. ;;
  91. 'deploy')
  92. deploy
  93. ;;
  94. 'startup')
  95. startup
  96. ;;
  97. 'shutdown')
  98. shutdown
  99. ;;
  100. 'help')
  101. help
  102. ;;
  103. *)
  104. esac
  105. exit 0
  106. 作者:flhuoshan
  107. 链接:https://hacpai.com/article/1513239674815
  108. 来源:黑客派
  109. 协议:CC BY-SA 4.0 https://creativecommons.org/licenses/by-sa/4.0

静态资源版本打包

使用gulp解决Web项目中静态资源版本更新与缓存 - 无忌的个人空间 - 开源中国