lots of work to make it actually work.

Icluding the server keep alive interval.
Fix where expiry duration was added twice.
This commit is contained in:
Erik Brakkee 2024-07-21 22:36:17 +02:00
parent 12ecb72329
commit 7e6b4d9272
7 changed files with 87 additions and 27 deletions

View File

@ -58,10 +58,10 @@ func setWinsize(f *os.File, w, h int) {
uintptr(unsafe.Pointer(&struct{ h, w, x, y uint16 }{uint16(h), uint16(w), 0, 0}))) uintptr(unsafe.Pointer(&struct{ h, w, x, y uint16 }{uint16(h), uint16(w), 0, 0})))
} }
func sshServer(hostKeyFile string) *ssh.Server { func sshServer(hostKeyFile string, shellCommand string) *ssh.Server {
ssh.Handle(func(s ssh.Session) { ssh.Handle(func(s ssh.Session) {
// TODO shell should be made configurable
cmd := exec.Command("bash") cmd := exec.Command(shellCommand)
ptyReq, winCh, isPty := s.Pty() ptyReq, winCh, isPty := s.Pty()
if isPty { if isPty {
workingDirectory, _ := os.Getwd() workingDirectory, _ := os.Getwd()
@ -154,8 +154,8 @@ func (f ReaderFunc) Read(p []byte) (n int, err error) {
func main() { func main() {
wsURL := os.Args[1] wsURL := os.Args[1]
advanceWarningTime := 10 * time.Minute advanceWarningTime := 5 * time.Minute
agentExpriryTime := 30 * time.Minute agentExpriryTime := 10 * time.Minute
tickerInterval := 60 * time.Second tickerInterval := 60 * time.Second
agent.ConfigureAgent(advanceWarningTime, agentExpriryTime, tickerInterval) agent.ConfigureAgent(advanceWarningTime, agentExpriryTime, tickerInterval)
@ -176,8 +176,21 @@ func main() {
// Need to create listener implementation that aactually listens for websocket connections. // Need to create listener implementation that aactually listens for websocket connections.
var service AgentService var service AgentService
shells := []string{"bash", "sh", "ash", "ksh", "zsh", "fish", "tcsh", "csh"}
shell := ""
for _, candidate := range shells {
shell, err = exec.LookPath(candidate)
if err == nil {
break
}
}
if shell == "" {
log.Printf("Cannot find a shell in %v", shells)
os.Exit(1)
}
log.Printf("Using shell %s for remote sessions", shell)
service = ListenerServer(func() *ssh.Server { service = ListenerServer(func() *ssh.Server {
return sshServer("hostkey.pem") return sshServer("hostkey.pem", shell)
}) })
//service = ConnectionServer(netCatServer) //service = ConnectionServer(netCatServer)
//service = ConnectionServer(echoServer) //service = ConnectionServer(echoServer)

View File

@ -69,7 +69,6 @@ type FilteredFileSystem struct {
} }
func (ffs FilteredFileSystem) Open(name string) (http.File, error) { func (ffs FilteredFileSystem) Open(name string) (http.File, error) {
log.Println("Name : " + name)
f, err := ffs.fs.Open(name) f, err := ffs.fs.Open(name)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -0,0 +1,25 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: converge
name: converge
namespace: wamblee-org
spec:
replicas: 1
selector:
matchLabels:
app: converge
template:
metadata:
labels:
app: converge
spec:
containers:
- image: your.repo.com/converge:1.0
imagePullPolicy: Always
name: converge
ports:
- containerPort: 8000

13
kubernetes/service.yaml Normal file
View File

@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: converge
name: converge
spec:
ports:
- port: 8000
protocol: TCP
targetPort: 8000
selector:
app: converge

View File

@ -1,6 +1,6 @@
Session is set to expire at %v Session is set to expire at %v
The session expires automatically after %d time. The session expires automatically after %v.
If there are no more sessions after logging out, the agent If there are no more sessions after logging out, the agent
terminates. terminates.
@ -8,6 +8,10 @@ You can extend this time using
touch $agentdir/.hold touch $agentdir/.hold
The expiry time is equal to the modification time of the .hold
file with the expiry duration added.
To prevent the agent from exiting after the last session is gone, To prevent the agent from exiting after the last session is gone,
also use the above command in any shell. also use the above command in any shell.

View File

@ -161,7 +161,7 @@ func (state *AgentState) expiryTime(filename string) time.Time {
func check() { func check() {
now := time.Now() now := time.Now()
expiryTime := state.expiryTime(".hold").Add(state.agentExpriryTime) expiryTime := state.expiryTime(".hold")
if now.After(expiryTime) { if now.After(expiryTime) {
messageUsers("Expiry time was reached logging out") messageUsers("Expiry time was reached logging out")

View File

@ -19,7 +19,7 @@
<p> <p>
Converge is a utility for troubleshooting builds on continuous integration serves. Converge is a utility for troubleshooting builds on continuous integration serves.
It solves a common problem where the cause of job failure is difficult to determine. It solves a common problem where the cause of job failure is difficult to determine.
This is complicated furhter by the fact that build jobs are usually run on a build This is complicated further by the fact that build jobs are usually run on a build
farm where there is no access to the build agents or in more modern envrionments when farm where there is no access to the build agents or in more modern envrionments when
jobs are run in ephemeral containers. jobs are run in ephemeral containers.
</p> </p>
@ -43,8 +43,14 @@
</p> </p>
<p> <p>
There is a timeout mechanism in the agent such that jobs do not hang indefinetely waiting There is a timeout mechanism in the agent such that jobs do not hang indefinitely waiting
for a connection. for a connection. This mechanism is useful to make sure build agents do not wait
indefinitely for a user session. By default, the agent exits with status 0 when
the first client exits after logging in. This behavior as well as general expiry can be
controlled from within a shell session by touching a .hold file. After logging in, the
user can control expiry of the session as instructed by messages in the ssh session.
Then the timeout of a session is near the user is informed about this with messages
in the shell.
</p> </p>
<h1>Usage</h1> <h1>Usage</h1>
@ -118,7 +124,7 @@
<pre> <pre>
ssh -oServerAliveInterval=10 -p 10000 abc@localhost ssh -oServerAliveInterval=10 -p 10000 abc@localhost
sftp -oServerAliveInterval=10 -oPort 10000 abc@localhost sftp -oServerAliveInterval=10 -oPort=10000 abc@localhost
</pre> </pre>
<p> <p>