warrend / warren run cmd work and sock clean and pipe and sigint handle
This commit is contained in:
parent
e9598f4ddd
commit
c3385f8495
|
@ -0,0 +1,36 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/dballard/warren/lib/warren"
|
||||
"log"
|
||||
"net"
|
||||
// "os"
|
||||
// "os/exec"
|
||||
// "time"
|
||||
)
|
||||
|
||||
var runUsage = `
|
||||
warren run - Interfaces with warrend to manage running instances
|
||||
`
|
||||
|
||||
var runCmd = &Command{
|
||||
Name: "run",
|
||||
Usage: "",
|
||||
Summary: "Interface to warrend to manage running instances",
|
||||
Help: runUsage,
|
||||
Run: runRun,
|
||||
}
|
||||
|
||||
func runRun(cmd *Command, args ...string) {
|
||||
if len(args) == 0 || args[0] == "help" {
|
||||
fmt.Print(cmd.Help)
|
||||
return
|
||||
}
|
||||
|
||||
_, err := net.Dial(warren.CmdSockType(), warren.CmdSockAddr())
|
||||
if err != nil {
|
||||
log.Fatal("Error connecting to warrend:", err)
|
||||
}
|
||||
|
||||
}
|
|
@ -27,6 +27,7 @@ Commands:{{range .}}
|
|||
var commands = []*Command{
|
||||
buildCmd,
|
||||
deployCmd,
|
||||
runCmd,
|
||||
}
|
||||
|
||||
func usage() {
|
||||
|
|
Binary file not shown.
|
@ -2,8 +2,12 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/dballard/warren/lib/warren"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func cmdHandle(c net.Conn) {
|
||||
|
@ -23,11 +27,26 @@ func cmdHandle(c net.Conn) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
cmdSock, err := net.Listen("unix", "/tmp/warrend.sock")
|
||||
|
||||
cmdSock, err := net.Listen(warren.CmdSockType(), warren.CmdSockAddr())
|
||||
defer cmdSock.Close()
|
||||
if err != nil {
|
||||
log.Fatal("Listen on sock error:", err)
|
||||
}
|
||||
|
||||
// Handle signals
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c,
|
||||
syscall.SIGINT,
|
||||
syscall.SIGTERM,
|
||||
syscall.SIGQUIT,
|
||||
syscall.SIGHUP,
|
||||
)
|
||||
go func() {
|
||||
_ = <-c
|
||||
cmdSock.Close()
|
||||
}()
|
||||
|
||||
for {
|
||||
fd, err := cmdSock.Accept()
|
||||
fmt.Println("accept")
|
||||
|
|
Binary file not shown.
|
@ -8,6 +8,17 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var cmdSockType string = "unix"
|
||||
var cmdSockAddr string = "/tmp/warrend.sock"
|
||||
|
||||
func CmdSockType() string {
|
||||
return cmdSockType
|
||||
}
|
||||
|
||||
func CmdSockAddr() string {
|
||||
return cmdSockAddr
|
||||
}
|
||||
|
||||
func GitHash() string {
|
||||
hash, err := exec.Command("git", "rev-parse", "HEAD").Output()
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue