Gradle SSH Plugin is a Gradle plugin which provides remote command execution and file transfer features.
//引入插件,此插件依赖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
#!/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
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