Files
linux-odyssey/services/terminal-service/terminal.go
T
Justin Lin 5e81db2759 feat: connect terminal service to backend
feat: put terminal service into container

refactor: separate main into terminal and websocket

feat: create zsh using commander in home

feat: pass backendUrl to container

feat: pass token to ws server to cmd-hook

feat: gen terminal access token for frontend

feat: success to connect through traefik

fix: handle invalid jwt

feat: connect to session container via traefik
2025-05-05 19:53:33 +08:00

41 lines
624 B
Go

package main
import (
"os"
"os/exec"
"github.com/creack/pty"
)
type terminal struct {
cmd *exec.Cmd
pty *os.File
}
func newTerminal(token string) (*terminal, error) {
// Start a new shell in the home directory
cmd := exec.Command("/usr/bin/zsh")
cmd.Dir = os.Getenv("HOME")
cmd.Env = append(os.Environ(), "ZDOTDIR=/etc/zsh", "TOKEN="+token)
ptmx, err := pty.Start(cmd)
if err != nil {
return nil, err
}
return &terminal{
cmd: cmd,
pty: ptmx,
}, nil
}
func (t *terminal) Close() error {
if t.pty != nil {
t.pty.Close()
}
if t.cmd != nil {
t.cmd.Process.Kill()
t.cmd.Wait()
}
return nil
}