package templates import "converge/pkg/models" templ AgentUsage(access models.ConvergeAccess, usageInputs UsageInputs) {

Downloading and running the agent

This is what you run on a remote server, typically in your continuous integration job.

if usageInputs.RemoteShells[BASH] {
{addSshKeys(BASH, usageInputs.SshKeys)}
        curl --fail-with-body http{access.Secure}://{access.HostPort}/downloads/agent > agent{`
        chmod 755 agent
        `}./agent --id {usageInputs.Id} ws{access.Secure}://{access.HostPort}{`
        rm -f agent
        `}
} if usageInputs.RemoteShells[CMD] {
{addSshKeys(CMD, usageInputs.SshKeys)}
        curl --fail-with-body http{access.Secure}://{access.HostPort}/downloads/agent.exe > agent.exe{`
        `}agent --id {usageInputs.Id} ws{access.Secure}://{access.HostPort}{`
        del agent.exe
        `}
} if usageInputs.RemoteShells[POWERSHELL] {
{addSshKeys(POWERSHELL, usageInputs.SshKeys)}
        curl --fail-with-body http{access.Secure}://{access.HostPort}/downloads/agent.exe > agent.exe{`
        `}agent --id {usageInputs.Id} ws{access.Secure}://{access.HostPort}{`
        del agent.exe
        `}
}

The agent has more command-line options than shown here. Download the agent and run it without arguments to see all options.

Tip: Run the above command locally in a similar shell (for instance in a docker container) then try to connect to the shell using the commands below. If that works, then you are all set.

Connecting to the agent

The embedded ssh server in the agent supports both ssh and sftp. The user name is fixed at { access.Username }. This is the user used to connect to the embedded SSH server, after logging in however you will be running in a shell that is started by the same user that started the agent.

{`
          `}ssh -oServerAliveInterval=10 -oProxyCommand="wsproxy ws{access.Secure}://{access.HostPort}/client/{usageInputs.Id}"  { access.Username }{"@localhost"}   {`
          `}sftp -oServerAliveInterval=10 -oProxyCommand="wsproxy ws{access.Secure}://{access.HostPort}/client/{usageInputs.Id}" { access.Username }{"@localhost"}   {`
          `}

This requires the wsproxy utility which is available in the downloads section. This utility must be downloaded only once since it is quite generic. It will warn you when it a newer version must be downloaded.

For other ssh clients that do not support the openssh ProxyCommand option, there is another way to connect. In this method, a local port forwarder is started that forwards a local port to the webserver. Then you can start an ssh client that connects to the local tcp port.

{`
         `}ssh -oServerAliveInterval=10 -p 10000  { access.Username }{"@localhost"}   {`
         `}sftp -oServerAliveInterval=10 -p 10000 { access.Username }{"@localhost"}   {`
         `}

This requires the tcptows utility which is available in the downloads section. The utility must be started beforehand using:

{`
         `}tcptows ws{access.Secure}://{access.HostPort}/client/{usageInputs.Id}   {`
         `}tcptows ws{access.Secure}://{access.HostPort}/client/{usageInputs.Id}   {`
         `}

Working with the agent

if usageInputs.RemoteShells[BASH] {
{`
        # cd back to the agent directory
        cd $agentdir

        # prevent logout when last user exits
        touch $agentdir/.hold
       `}
} if usageInputs.RemoteShells[CMD] {
{`
        # cd back to the agent directory
        cd %agentdir%

        # prevent logout when last user exits
        echo > %agentdir%\.hold
        `}
} if usageInputs.RemoteShells[POWERSHELL] {
{`
        # cd back to the agent directory
        cd $env:agentdir

        # prevent logout when last user exits
        $null > $env:agentdir\.hold
        `}
} if usageInputs.RemoteShells[CMD] || usageInputs.RemoteShells[POWERSHELL] {

NOTE: When running the agent on windows, an exit of the remote session using exit in powershell or command prompt does not terminate the shell completely. To terminate the client ssh session must be killed by closing the terminal. Cleanup of remote processes on the agent appears to work properly despite this problem. It is just that exit of the windows shell (powershell or command prompt) is not detected properly.

}
} templ ShellUsage(access models.ConvergeAccess, usageInputs UsageInputs) {
@AgentUsage(access, usageInputs)
} templ Usage(access models.ConvergeAccess) {

Usage

} templ UsageTab(access models.ConvergeAccess) { @BasePage(2) { @Usage(access) } }