working on server control and packaging

This commit is contained in:
sawka
2022-10-30 12:52:40 -07:00
parent 29dbf5dde9
commit 260fc2d313
3 changed files with 15 additions and 2 deletions
+13 -1
View File
@@ -11,6 +11,7 @@ import (
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"syscall"
"time" "time"
"github.com/alessio/shellescape" "github.com/alessio/shellescape"
@@ -41,7 +42,7 @@ var RemoteSetArgs = []string{"alias", "connectmode", "key", "password", "autoins
var WindowCmds = []string{"run", "comment", "cd", "cr", "clear", "sw", "alias", "unalias", "function", "reset"} var WindowCmds = []string{"run", "comment", "cd", "cr", "clear", "sw", "alias", "unalias", "function", "reset"}
var NoHistCmds = []string{"compgen", "line", "history"} var NoHistCmds = []string{"compgen", "line", "history"}
var GlobalCmds = []string{"session", "screen", "remote"} var GlobalCmds = []string{"session", "screen", "remote", "killserver"}
var hostNameRe = regexp.MustCompile("^[a-z][a-z0-9.-]*$") var hostNameRe = regexp.MustCompile("^[a-z][a-z0-9.-]*$")
var userHostRe = regexp.MustCompile("^(sudo@)?([a-z][a-z0-9-]*)@([a-z][a-z0-9.-]*)(?::([0-9]+))?$") var userHostRe = regexp.MustCompile("^(sudo@)?([a-z][a-z0-9-]*)@([a-z][a-z0-9.-]*)(?::([0-9]+))?$")
@@ -112,6 +113,8 @@ func init() {
registerCmdFn("line:show", LineShowCommand) registerCmdFn("line:show", LineShowCommand)
registerCmdFn("history", HistoryCommand) registerCmdFn("history", HistoryCommand)
registerCmdFn("killserver", KillServerCommand)
} }
func getValidCommands() []string { func getValidCommands() []string {
@@ -1661,6 +1664,15 @@ func LineShowCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sst
return update, nil return update, nil
} }
func KillServerCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
go func() {
fmt.Printf("received /killserver, shutting down\n")
time.Sleep(1 * time.Second)
syscall.Kill(syscall.Getpid(), syscall.SIGINT)
}()
return nil, nil
}
func formatTermOpts(termOpts sstore.TermOpts) string { func formatTermOpts(termOpts sstore.TermOpts) string {
if termOpts.Cols == 0 { if termOpts.Cols == 0 {
return "???" return "???"
+1
View File
@@ -37,6 +37,7 @@ type ModelUpdate struct {
Cmd *CmdType `json:"cmd,omitempty"` Cmd *CmdType `json:"cmd,omitempty"`
CmdLine *CmdLineType `json:"cmdline,omitempty"` CmdLine *CmdLineType `json:"cmdline,omitempty"`
Info *InfoMsgType `json:"info,omitempty"` Info *InfoMsgType `json:"info,omitempty"`
ClearInfo bool `json:"clearinfo,omitempty"`
Remotes []interface{} `json:"remotes,omitempty"` // []*remote.RemoteState Remotes []interface{} `json:"remotes,omitempty"` // []*remote.RemoteState
History *HistoryInfoType `json:"history,omitempty"` History *HistoryInfoType `json:"history,omitempty"`
Interactive bool `json:"interactive"` Interactive bool `json:"interactive"`
+1 -1
View File
@@ -12,5 +12,5 @@ sqlite3 /Users/mike/scripthaus/sh2.db
```bash ```bash
# @scripthaus command build # @scripthaus command build
go build -o server cmd/main-server.go go build -o ~/scripthaus/local-server cmd/main-server.go
``` ```