2021-09-21 22:36:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
2023-07-06 15:46:56 +00:00
|
|
|
"code.betamike.com/micropelago/pmux/pmuxlib"
|
2022-01-23 03:03:13 +00:00
|
|
|
|
2022-10-20 18:55:31 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
2021-09-21 22:36:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
cfgPath := flag.String("c", "./pmux.yml", "Path to config yaml file")
|
|
|
|
flag.Parse()
|
|
|
|
|
2024-10-29 11:03:52 +00:00
|
|
|
cfgB, err := os.ReadFile(*cfgPath)
|
2021-09-21 22:36:50 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("couldn't read cfg file at %q: %v", *cfgPath, err))
|
|
|
|
}
|
|
|
|
|
2022-06-19 01:52:04 +00:00
|
|
|
var cfg pmuxlib.Config
|
2021-09-21 22:36:50 +00:00
|
|
|
if err := yaml.Unmarshal(cfgB, &cfg); err != nil {
|
|
|
|
panic(fmt.Sprintf("couldn't parse cfg file: %v", err))
|
|
|
|
}
|
|
|
|
|
2024-07-19 13:35:38 +00:00
|
|
|
p := pmuxlib.NewPmux(cfg, os.Stdout, os.Stderr)
|
|
|
|
defer p.Stop()
|
2021-09-21 22:36:50 +00:00
|
|
|
|
2024-07-19 13:35:38 +00:00
|
|
|
sigCh := make(chan os.Signal, 2)
|
|
|
|
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
|
|
|
|
|
|
|
|
<-sigCh
|
2021-09-21 22:36:50 +00:00
|
|
|
|
2024-07-19 13:35:38 +00:00
|
|
|
go func() {
|
2021-09-21 22:36:50 +00:00
|
|
|
<-sigCh
|
2022-06-19 01:52:04 +00:00
|
|
|
fmt.Fprintln(os.Stderr, "forcefully exiting pmux process, there may be zombie child processes being left behind, good luck!")
|
|
|
|
os.Stderr.Sync()
|
2021-09-21 22:36:50 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}()
|
|
|
|
}
|