ssh plugin

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

//引入插件,此插件依赖war插件
plugins {
    id 'war'
    id 'org.hidetake.ssh' version '2.9.0'
}
//远程服务器信息
remotes {
  webServer {
    host = '172.18.112.102'
    user = 'root'
    password = 'lingyi2016'
  }
}
//创建远程部署任务
task deployT(dependsOn: war) << {
    ssh.run {
        session(remotes.webServer) {
            put from: war.archivePath.path, into: '/opt/test/apache-tomcat-8.5.15/webapps'
            execute "service tomcat restart"
        }
    }
}

执行下面的命令即可

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
  1. 按ESC退出,并#:wq

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

#chmod a+x tomcat
  1. 设置服务运行级别

#chkconfig --add tomcat
  1. 服务就添加成功了

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

   #chkconfig --list
  1. 测试

service tomcat start

service tomcat stop

service tomcat restart

service tomcat status

​​​​​​​​​​​​

#!/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

Last updated