> For the complete documentation index, see [llms.txt](https://java-woms.gitbook.io/java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://java-woms.gitbook.io/java/gradle/gradle-usage-summary/07.md).

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

```groovy
//引入插件，此插件依赖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"
        }
    }
}
```

执行下面的命令即可

```bash
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
```

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

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://java-woms.gitbook.io/java/gradle/gradle-usage-summary/07.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
