Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session reusage #275

Open
matthiasbalke opened this issue Aug 26, 2016 · 0 comments
Open

Session reusage #275

matthiasbalke opened this issue Aug 26, 2016 · 0 comments
Labels

Comments

@matthiasbalke
Copy link
Contributor

My gradle-ssh-plugin script is using a lot of small methods which performs some actions on a remote host. As far as I understand it each time I use the session() keyword a new SSH connections is established, right?

Is it possible to reuse an existing SSH session and passing it around? Maybe like this:
My current version

def tomcatShutdown(def stage) {
    ssh.run {
        session(remotes.allRoles('tomcat', stage)) {

            execute "${sudo_prefix} echo 'Shutting down Tomcat ...'"
            execute "if ${sudo_prefix} test -f '${tomcat_home}/catalina.pid'; then ${sudo_prefix} shutdown.sh; else echo 'Tomcat not running.'; fi"
        }
    }
}

def tomcatStartup(def stage) {
    ssh.run {
        session(remotes.allRoles('tomcat', stage)) {
            execute "echo 'Starting Tomcat ...'"
            execute "${sudo_prefix} startup.sh"
        }
    }
}

Version reusing sessions

def tomcatShutdown(def stage, def establishedSession) {
    ssh.run(establishedSession) {
            execute "${sudo_prefix} echo 'Shutting down Tomcat ...'"
            execute "if ${sudo_prefix} test -f '${tomcat_home}/catalina.pid'; then ${sudo_prefix} shutdown.sh; else echo 'Tomcat not running.'; fi"
    }
}

def tomcatStartup(def stage, def establishedSession) {
    ssh.run(establishedSession) {
            execute "echo 'Starting Tomcat ...'"
            execute "${sudo_prefix} startup.sh"
    }
}
@int128 int128 added the feature label Jan 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants