1.编写sh脚本,便于服务器上管理工程:

  1. #!/bin/bash
  2.  
  3. source /etc/profile
  4. PROG_NAME=$
  5. ACTION=$
  6.  
  7. usage() {
  8. echo "Usage: $PROG_NAME {start|stop|restart|status|tailf}"
  9. exit ;
  10. }
  11.  
  12. # colors
  13. red='\e[0;31m'
  14. green='\e[0;32m'
  15. yellow='\e[0;33m'
  16. reset='\e[0m'
  17.  
  18. echoRed() { echo -e "${red}$1${reset}"; }
  19. echoGreen() { echo -e "${green}$1${reset}"; }
  20. echoYellow() { echo -e "${yellow}$1${reset}"; }
  21.  
  22. APP_HOME=$(cd $(dirname $)/..; pwd)
  23. app=${project.build.finalName}.${project.packaging}
  24. cd $APP_HOME
  25. mkdir -p logs
  26.  
  27. pidfile=logs/app.pid
  28. logfile=logs/start.`date +%F`.log
  29. JAVA_OPTS="${java_opts}"
  30.  
  31. bakdir=/data/ops/packages/app_bak/${project.build.finalName}
  32. bakfile=$bakdir/${project.build.finalName}`date +%F`.${project.packaging}
  33.  
  34. function check_pid() {
  35. if [ -f $pidfile ];then
  36. pid=`cat $pidfile`
  37. if [ -n $pid ]; then
  38. running=`ps -p $pid|grep -v "PID TTY" |wc -l`
  39. return $running
  40. fi
  41. fi
  42. return
  43. }
  44.  
  45. function start() {
  46. check_pid
  47. running=$?
  48. if [ $running -gt ];then
  49. echoGreen "$app now is running already, pid=`cat $pidfile`"
  50. return
  51. fi
  52.  
  53. nohup java -jar $JAVA_OPTS $app >> ${logfile} >& & pid=$!
  54.  
  55. echoGreen "$app starting "
  56. for e in $(seq ); do
  57. echo -n " $e"
  58. sleep
  59. done
  60. echo $pid > $pidfile
  61. check_pid
  62. running=$?
  63. if [ $running -gt ];then
  64. echoGreen " ,pid=`cat $pidfile`"
  65. return
  66. else
  67. echoRed ",started fail!!!"
  68. fi
  69. }
  70.  
  71. function stop() {
  72. pid=`cat $pidfile`
  73. kill - $pid
  74. echoRed "$app stoped..."
  75. }
  76.  
  77. function restart() {
  78. stop
  79. sleep
  80. start
  81. }
  82.  
  83. function backup(){
  84.  
  85. if [ ! -x $bakdir ];then
  86. mkdir -p $bakdir
  87.  
  88. fi
  89.  
  90. if [ ! -f $bakfile ];then
  91. cp $app $bakfile
  92. echo $bakfile backup finish
  93. else
  94. echo $bakfile is already backup
  95.  
  96. fi
  97. }
  98.  
  99. function rollback(){
  100.  
  101. if [ ! -f $bakfile ];then
  102. echo $bakfile backup not found
  103. else
  104. rm -f $app
  105. cp $bakfile $app
  106. echo $app rollback finish
  107.  
  108. fi
  109.  
  110. }
  111.  
  112. function tailf() {
  113. tail -f $APP_HOME/$logfile
  114. }
  115.  
  116. function status() {
  117. check_pid
  118. running=$?
  119. if [ $running -gt ];then
  120. echoGreen "$app now is running, pid=`cat $pidfile`"
  121. else
  122. echoYellow "$app is stoped"
  123. fi
  124. }
  125.  
  126. function main {
  127. RETVAL=
  128. case "$1" in
  129. start)
  130. start
  131. ;;
  132. stop)
  133. stop
  134. ;;
  135. restart)
  136. restart
  137. ;;
  138. tailf)
  139. tailf
  140. ;;
  141. status)
  142. status
  143. ;;
  144. backup)
  145. backup
  146. ;;
  147. rollback)
  148. rollback
  149. ;;
  150. *)
  151. usage
  152. ;;
  153. esac
  154. exit $RETVAL
  155. }
  156.  
  157. main $

文件中包含多个站位符,可以借助spring filter打包时进行填充,如将sh起名为app.sh放置于maven格式项目的src/main/bin目录下则在pom文件中可添加如下配置,如:

  1. <profiles>
  2. <!--开发默认环境-->
  3. <profile>
  4. <id>dev</id>
  5. <activation>
  6. <activeByDefault>true</activeByDefault>
  7. </activation>
  8. <properties>
  9. <profileActive>dev</profileActive>
  10. <java_opts>-server -Xms512m -Xmx512m -XX:NewSize=128m -XX:MaxNewSize=128m -Xss256k</java_opts>
  11. <bakcupdir>/data/ops/packages/app_bak</bakcupdir>
  12. </properties>
  13. </profile>
  14. <!--生产环境-->
  15. <profile>
  16. <id>product</id>
  17. <properties>
  18. <profileActive>product</profileActive>
  19. <java_opts>-server -Xms2048m -Xmx2048m -XX:NewSize=256m -XX:MaxNewSize=256m -Xss256k</java_opts>
  20. <bakcupdir>/data/ops/packages/app_bak</bakcupdir>
  21. </properties>
  22. </profile>
  23.  
  24. </profiles>
  25.  
  26. <build>
  27. <finalName>liam-service</finalName>
  28. <resources>
  29. <resource>
  30. <directory>src/main/resources</directory>
  31. <filtering>true</filtering>
  32. </resource>
  33. <resource>
  34. <directory>src/main/resources/keys/*</directory>
  35. <includes>
  36. <include>webank_keystore.jks</include>
  37. <include>webank_truststore.jks</include>
  38. </includes>
  39. <filtering>false</filtering>
  40. </resource>
  41. <!--也就是此处配置上maven打包需要进行配置的文件-->
  42. <resource>
  43. <directory>src/main/bin</directory>
  44. <targetPath>${project.build.directory}/bin</targetPath>
  45. <filtering>true</filtering>
  46. </resource>
  47. </resources>
  48. <plugins>
  49. <plugin>
  50. <groupId>org.springframework.boot</groupId>
  51. <artifactId>spring-boot-maven-plugin</artifactId>
  52. <version>1.5.6.RELEASE</version>
  53. <configuration>
  54. <!--fork: 如果没有该项配置,肯呢个devtools不会起作用,即应用不会restart-->
  55. <fork>true</fork>
  56. </configuration>
  57. <executions>
  58. <execution>
  59. <goals>
  60. <!-- 用于打包jar -->
  61. <goal>repackage</goal>
  62. </goals>
  63. </execution>
  64. </executions>
  65. </plugin>
  66. <plugin>
  67. <groupId>org.apache.maven.plugins</groupId>
  68. <artifactId>maven-compiler-plugin</artifactId>
  69. <version>3.5.1</version>
  70. <configuration>
  71. <source>${jdk.version}</source>
  72. <target>${jdk.version}</target>
  73. <encoding>UTF-8</encoding>
  74. </configuration>
  75. </plugin>
  76. </plugins>
  77. <pluginManagement>
  78. <plugins>
  79. <plugin>
  80. <artifactId>maven-resources-plugin</artifactId>
  81. <configuration>
  82. <encoding>utf-8</encoding>
  83. <useDefaultDelimiters>true</useDefaultDelimiters>
  84. <nonFilteredFileExtensions>
  85. <!--防止maven该表证书内的内容-->
  86. <nonFilteredFileExtension>p12</nonFilteredFileExtension>
  87. <nonFilteredFileExtension>jks</nonFilteredFileExtension>
  88. </nonFilteredFileExtensions>
  89. </configuration>
  90. </plugin>
  91. </plugins>
  92. </pluginManagement>
  93. </build>

如此将包打好后扔于服务器上,就很方便了:

  1. ssh "chmod +x /data/ops/app/liam-service/bin/app.sh"
  2. ssh "/data/ops/app/liam-service/bin/app.sh backup"
  3. ssh "/data/ops/app/liam-service/bin/app.sh stop"
  4. ssh "/data/ops/app/liam-service/bin/app.sh start"

当然借助jenkens的话会很方便~

java spring boot项目部署-上的更多相关文章

  1. 多个Spring Boot项目部署在一个Tomcat容器无法启动

    转自https://www.cnblogs.com/tomxin7/p/9434085.html 业务介绍 最近用Spring Boot开发了一个翻译的小项目,但是服务器上还跑着其他项目,包括一个同样 ...

  2. 从零开始通过idea插件将一个spring boot项目部署到docker容器里运行

    实操:将一个spring boot项目部署到docker容器里运行 实验需要的环境: 腾讯云+Ubuntu 16.04 x64+idea+插件docker integration+daocloud 第 ...

  3. KubeSphere CI/CD+GitLab+Harbor将Spring Boot项目部署至Kubernetes

    上一篇文章分享了如何在 KubeSphere 对公共的代码仓库 GitHub 和镜像仓库 DockerHub 创建流水线,本文将继续使用 KubeSphere,基于 Harbor 和 GitLab 创 ...

  4. 简化 Spring Boot 项目部署,Flyway 搞起来

    虽然我之前录了一个微人事(https://github.com/lenve/vhr)部署视频(新版微人事部署教程来啦),但是由于这次升级涉及到了 Redis 和 RabbitMQ,所以在本地跑微人事还 ...

  5. Spring Boot项目部署到外部Tomcat服务器

    2017年04月27日 23:33:52 阅读数:7542 前言 Spring Boot项目一般都是内嵌tomcat或者jetty服务器运行,很少用war包部署到外部的服务容器,即使放到linux中, ...

  6. 将spring boot项目部署到tomcat容器中

    一. 我这里用的环境 tomcat: tomcat 8 jdk: jdk 7 spring boot 版本: 1.5 二. 将创建好的spring boot项目做如下修改 2.1. 修改打包形式 在p ...

  7. Spring boot 项目部署服务器

    Spring Boot 有两种部署到服务器的方式,这里介绍官方推荐的(jar包) 一.首先进行application.properties配置 # EMBEDDED SERVER CONFIGURAT ...

  8. spring boot 项目部署在阿里云上

    装jdk, 然后 nohup java -jar xxxx.jar> system.log 2>&1 & lsof -i:9999 kill -9 1234

  9. Spring Boot 项目部署到本地Tomcat,出现访问路径问题

    首先确定war 包没问题,把war包放在webapps目录下,访问http://localhost:8080/ + 项目名称 发现首页可以访问但css,js请求都是404,跳转页面也是404 解决方法 ...

随机推荐

  1. Spring Boot fastJSON的使用

    springBoot,默认使用的json解析框架是Jackson. 虽然jackson能够满足json的解析,如果想使用熟悉的alibaba的fastjon,我们只需要在pom文件中配置maven依赖 ...

  2. H5学习入门

    [块级标签与行级标签的区别] 1.块级标签: 默认宽度100%(独占一行) 自动换行(右边不能有任何东西) 可以使用css设置宽度高度   2.行级标签: 内容宽度,由内容撑开(内容多宽,宽度就占多宽 ...

  3. ArcGIS10.3+Oracle12C+ArcGIS Server10.3安装布署(之二)

    1.创建PDB 输入 dbca 命令 2.安装完成后,连接PDBSDE的容器数据库 3.环境变量 从Oracle的官方网站下载   instantclient-basic-nt-12.1.0.2.0. ...

  4. Flutter自定义标题栏之处理状态栏高度

    App在很多情况下由于各种需求需要自定义标题栏,而在能够构建Android和IOS应用的Flutter中,如果不在Scaffold中使用AppBar会发现默认是沉浸式. 猜想:我们使用自定义标题栏好像 ...

  5. oracle 网络配置 及 pl/sql 连接配置

    oracle网络配置有三个文件,它们都在D:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN 这个文件夹下面,有sqlnet.ora.l ...

  6. 【java8】为java8的foreach正名

    首先为自己没有经过严格测试得出的错误结论感到抱歉,原博文,测试完感觉自己发现了一个新bug,后来思前想后觉得不应该是这样的,如果效率差的这么多,jdk的开发人员会不去优化它吗,但是怎么重复测试任然得到 ...

  7. Python DDT(data driven tests)模块心得

    关于ddt模块的一些心得,主要是看官网的例子,加上一点自己的理解,官网地址:http://ddt.readthedocs.io/en/latest/example.html ddt(data driv ...

  8. C#实现ADH815通讯

    最近在做自提柜项目,考虑到ADH815电路板在自助售卖行业的通用性.把通讯代码贴出来了. 下载地址

  9. PHP防SQL注入和XSS攻击

    摘要: 就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.在用户名输入框中输入:' or 1=1#,密码随便输入,这时候的合成后的SQL ...

  10. 《C++ Primer Plus》读书笔记之九—使用类

    第十一章 使用类 1.操作符函数的格式:operator op(argument-list).op是将要重载的操作符. 2.操作符重载函数的两种调用方式:①函数表示法:C=A.operator+(B) ...