package templates
import "git.wamblee.org/converge/pkg/models"
templ AgentUsage(access models.ConvergeAccess, usageInputs UsageInputs) {
for _, message := range usageInputs.ErrorMessages {
{message}
}
downloading and running the agent
This is what you run on a remote server, typically in your continuous integration job.
if usageInputs.RemoteShells[BASH] {
@templ.Raw(addSshKeys(BASH, usageInputs.SshKeys))
{DOWNLOAD_COMMAND[usageInputs.DownloadCommand]} agent {GetDownloadSecureOption(usageInputs)} http{access.Secure}://{access.BaseUrl}/downloads/agent
chmod 755 agent
./agent {GetAgentSecureOption(usageInputs)} --id {usageInputs.Id} ws{access.Secure}://{access.BaseUrl}
rm -f agent
}
if usageInputs.RemoteShells[CMD] {
@templ.Raw(addSshKeys(CMD, usageInputs.SshKeys))
{DOWNLOAD_COMMAND[usageInputs.DownloadCommand]} agent.exe {GetDownloadSecureOption(usageInputs)} http{access.Secure}://{access.BaseUrl}/downloads/agent.exe
.\agent {GetAgentSecureOption(usageInputs)} --id {usageInputs.Id} ws{access.Secure}://{access.BaseUrl}
del agent.exe
}
if usageInputs.RemoteShells[POWERSHELL] {
@templ.Raw(addSshKeys(POWERSHELL, usageInputs.SshKeys))
{DOWNLOAD_COMMAND[usageInputs.DownloadCommand]} agent.exe {GetDownloadSecureOption(usageInputs)} http{access.Secure}://{access.BaseUrl}/downloads/agent.exe
.\agent {GetAgentSecureOption(usageInputs)} --id {usageInputs.Id} ws{access.Secure}://{access.BaseUrl}
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
You need to install wsproxy
, which is available in the downloads section and
make it availebla in your path. This utility needs to be downloaded only once, if a newer version of
wsproxy
is needed it will tell you about that.
The embedded ssh server in the agent supports both ssh and sftp.
ssh -oServerAliveInterval=10 -oProxyCommand="wsproxy ws{access.Secure}://{access.BaseUrl}/client/{usageInputs.Id}" {"localhost"}
sftp -oServerAliveInterval=10 -oProxyCommand="wsproxy ws{access.Secure}://{access.BaseUrl}/client/{usageInputs.Id}" {"localhost"}
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 {"localhost"}
sftp -oServerAliveInterval=10 -p 10000 {"localhost"}
This requires the tcptows
utility which is available in the
downloads section. The utility must be started beforehand
using:
tcptows 10000 ws{access.Secure}://{access.BaseUrl}/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) {