-
-
Notifications
You must be signed in to change notification settings - Fork 161
Expand file tree
/
Copy pathmain.go
More file actions
64 lines (56 loc) · 1.52 KB
/
main.go
File metadata and controls
64 lines (56 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//go:build full || e2e
package main
import (
"context"
"os"
"os/signal"
"syscall"
log "github.com/sirupsen/logrus"
"github.com/tg123/sshpiper/libplugin"
"github.com/urfave/cli/v2"
)
func main() {
plugin := newLuaPlugin()
libplugin.CreateAndRunPluginTemplate(&libplugin.PluginTemplate{
Name: "lua",
Usage: "sshpiperd lua plugin - route SSH connections using Lua scripts",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "script",
Usage: "path to lua script file",
Required: true,
EnvVars: []string{"SSHPIPERD_LUA_SCRIPT"},
Destination: &plugin.ScriptPath,
},
&cli.StringFlag{
Name: "lua-path",
Usage: "additional Lua package.path entries (semicolon-separated patterns)",
EnvVars: []string{"SSHPIPERD_LUA_PATH"},
Destination: &plugin.SearchPath,
},
},
CreateConfig: func(c *cli.Context) (*libplugin.SshPiperPluginConfig, error) {
// Create context for cleanup
ctx, cancel := context.WithCancel(c.Context)
plugin.cancelFunc = cancel
// Register SIGHUP handler for reloading the Lua script
go func() {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGHUP)
defer signal.Stop(sigChan)
for {
select {
case <-ctx.Done():
return
case <-sigChan:
log.Info("Received SIGHUP, reloading Lua script...")
if err := plugin.reloadScript(); err != nil {
log.Errorf("Failed to reload Lua script: %v", err)
}
}
}
}()
return plugin.CreateConfig()
},
})
}