Last active
February 4, 2016 11:39
-
-
Save ddelponte/5879191 to your computer and use it in GitHub Desktop.
Restart remote tomcat instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This script restarts a remote tomcat instance | |
* Usage: groovy restartRemoteTomcat.groovy or groovy restartRemoteTomcat.groovy remoteServer remoteUser pathToTomcatBinDirectory | |
* Example: groovy restartRemoteTomcat myServer username "/home/username/apache-tomcat-7.0.39/bin/" | |
*/ | |
@Grapes([ | |
@Grab('org.apache.ant:ant:1.8.3'), | |
@Grab(group = 'ant', module = 'ant-jsch', version = '1.6.5'), | |
@Grab(group = 'com.jcraft', module = 'jsch', version = '0.1.48'), | |
@GrabConfig(systemClassLoader = true) | |
]) | |
// Configure the parameters | |
def ant = new AntBuilder() | |
def remoteServer = "remoteServername" | |
def remoteUser = "remoteUsername" | |
def privateKey = "/home/username/.ssh/id_rsa" // path to local user's private key file | |
def passphrase = "" | |
def binDirPath = "" // path to tomcat's bin directory on remote server | |
def stopCommand = "shutdown.sh" | |
def startCommand = "startup.sh" | |
if (args) { | |
remoteServer = args[0] | |
remoteUser = args[1] | |
binDirPath = args[2] | |
} | |
println "Stopping tomcat: ${remoteServer}:${binDirPath}${stopCommand}" | |
ant.sshexec( | |
host: remoteServer, | |
username: remoteUser, | |
keyfile: privateKey, | |
passphrase: passphrase, | |
command: "${binDirPath}${stopCommand}" | |
) | |
println "Starting tomcat: ${remoteServer}:${binDirPath}${stopCommand}" | |
ant.sshexec( | |
host: remoteServer, | |
username: remoteUser, | |
keyfile: privateKey, | |
passphrase: passphrase, | |
command: "${binDirPath}${startCommand}" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment