gradle ssh 插件

周昊乾
2023-12-01

org.hidetake.ssh

 

Gradle SSH Plugin is a Gradle plugin which provides remote command execution and file transfer features.

https://gradle-ssh-plugin.github.io

远程部署插件, 可以远程传输文件,也可以执行远程shell命令

 


配置build.gradle文件

插件官方网址https://gradle-ssh-plugin.github.io/gradle插件https://plugins.gradle.org/plugin/org.hidetake.ssh

 1 //引入插件,此插件依赖war插件
 2 plugins {
 3     id 'war'
 4     id 'org.hidetake.ssh' version '2.9.0'
 5 }
 6 //远程服务器信息
 7 remotes {
 8   webServer {
 9     host = '172.18.112.102'
10     user = 'root'
11     password = 'lingyi2016'
12   }
13 }
14 //创建远程部署任务
15 task deployT(dependsOn: war) << {
16     ssh.run {
17         session(remotes.webServer) {
18             put from: war.archivePath.path, into: '/opt/test/apache-tomcat-8.5.15/webapps'
19             execute "service tomcat restart"
20         }
21     }
22 }

 

执行下面的命令即可

user@user-PC:~/user/my_workspace/111$ gradle deployT 

配置tomcat服务

linux服务器上配置tomcat以service方式启动

http://blog.csdn.net/chen_pt/article/details/53139488

  1. 在/etc/init.d目录下新建文件,命名为tomcat

  2. 对tomcat文件进行编辑,执行

    ​ 将下面代码粘上去

    注意:下面代码java_home和catalina_home是指jdk和tomcat安装的根路径

    #!/bin/bash  
    ​
    # description: Tomcat7 Start Stop Restart  
    ​
    # processname: tomcat7  
    ​
    # chkconfig: 234 20 80  
    ​
    JAVA_HOME=/opt/jdk1.8.0_121
    ​
    export JAVA_HOME  
    ​
    PATH=$JAVA_HOME/bin:$PATH  
    ​
    export PATH  
    ​
    CATALINA_HOME=/opt/test/apache-tomcat-8.5.15
    ​
    case $1 in  
    ​
    start)  
    ​
    sh $CATALINA_HOME/bin/startup.sh  
    ​
    ;;   
    ​
    stop)     
    ​
    sh $CATALINA_HOME/bin/shutdown.sh  
    ​
    ;;   
    ​
    restart)  
    ​
    sh $CATALINA_HOME/bin/shutdown.sh  
    ​
    sh $CATALINA_HOME/bin/startup.sh  
    ​
    ;;   
    ​
    esac      
    ​
    exit 0

     

  3. 按ESC退出,并#:wq

  4. 设置tomcat的文件属性,把tomcat 修改为可运行的文件,命令参考如下

    #chmod a+x tomcat

  5. 设置服务运行级别

    #chkconfig --add tomcat

  6. 服务就添加成功了

    ​ 然后用 chkconfig --list 查看,在服务列表里就会出现自定义的服务了

    #chkconfig --list

  7. 测试

    service tomcat start
    ​
    service tomcat stop
    ​
    service tomcat restart ​ service tomcat status


  8.  

 

转载于:https://www.cnblogs.com/woms/p/7040777.html

 类似资料: