From 7f4e3c39da2963705c100776e5c546148dacab49 Mon Sep 17 00:00:00 2001 From: Zeni Kim Date: Sun, 15 Sep 2024 10:06:16 -0500 Subject: [PATCH] rewrite --- cmd/helper_.go | 6 +++--- cmd/new.go | 6 +++--- cmd/new_test.go | 6 +++--- cmd/run.go | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/cmd/helper_.go b/cmd/helper_.go index 8b65493..489d81f 100644 --- a/cmd/helper_.go +++ b/cmd/helper_.go @@ -55,7 +55,7 @@ func prepareJobContent(jobName string) string { t := `package eventjobs import ( - "github.com/goffee/core" + "git.smarteching.com/goffee/core" ) var {JobName} core.EventJob = func(event *core.Event, c *core.Context) { @@ -107,7 +107,7 @@ func createHandlerFile(handlersFilePath string) (*os.File, error) { _, err = file.WriteString(`package handlers import ( - "github.com/goffee/core" + "git.smarteching.com/goffee/core" ) `) @@ -121,7 +121,7 @@ func prepareMiddlewareContent(middlewareName string) string { t := `package middlewares import ( - "github.com/goffee/core" + "git.smarteching.com/goffee/core" ) var {middlewareName} core.Middleware = func (c *core.Context) { diff --git a/cmd/new.go b/cmd/new.go index c9e418c..8f50cf1 100644 --- a/cmd/new.go +++ b/cmd/new.go @@ -38,7 +38,7 @@ type RepoMeta struct { } // Config file -const CONFIG_URL string = "https://raw.githubusercontent.com/gocondor/gaffer/main/config.json" +const CONFIG_URL string = "https://git.smarteching.com/goffee/goffee/raw/branch/main/config.json" const REPO_URL string = "https://git.smarteching.com/goffee/goffee/cup/releases/latest" @@ -165,7 +165,7 @@ func (cn *CmdNew) DownloadGoCondor(http *http.Client, url string, tempName strin tempFilePath := os.TempDir() + "/" + tempName response, err := http.Get(url) if err != nil { - fmt.Println("error downloading the GoCondor release") + fmt.Println("error downloading the Cup release") os.Exit(1) } defer response.Body.Close() @@ -179,7 +179,7 @@ func (cn *CmdNew) DownloadGoCondor(http *http.Client, url string, tempName strin _, err = io.Copy(file, response.Body) if err != nil { - fmt.Println("error writing the GoCondor release to file") + fmt.Println("error writing the Cup release to file") os.Exit(1) } diff --git a/cmd/new_test.go b/cmd/new_test.go index b61ed47..5ad6721 100644 --- a/cmd/new_test.go +++ b/cmd/new_test.go @@ -36,7 +36,7 @@ func TestDownloadConfig(t *testing.T) { func TestDownloadGoCondor(t *testing.T) { // Prepare newCmd := CmdNew{} - fileName := "gocondor_temp_" + randstr.Hex(8) + ".tar.gz" + fileName := "cup_temp_" + randstr.Hex(8) + ".tar.gz" server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { res, err := os.ReadFile("testdata/gocondor.tar.gz") if err != nil { @@ -78,8 +78,8 @@ func TestIsUpdatedRequired(t *testing.T) { func TestUnpack(t *testing.T) { // Prepare cn := CmdNew{} - filepath := "./testdata/gocondor.tar.gz" - folderName := "gocondor-0.3-alpha.6" + filepath := "./testdata/cup.tar.gz" + folderName := "cup-0.3-alpha.6" destPath := os.TempDir() os.RemoveAll(destPath + "/" + folderName) diff --git a/cmd/run.go b/cmd/run.go index 81af1c2..0ffd9a0 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -118,6 +118,15 @@ func startRestartControllerJob(fileChangeChan chan bool, pidChan chan int, start if err != nil { fmt.Println("error stopping process: ", err.Error()) } + } else if runtime.GOOS == "linux" { + pgid, err := syscall.Getpgid(pid) + if err != nil { + fmt.Println("error getting pgid: ", err.Error()) + } + err = syscall.Kill(-pgid, syscall.SIGKILL) + if err != nil { + fmt.Println("error stopping process: ", err.Error()) + } } else { fmt.Println("not implemented for os: ", runtime.GOOS) } @@ -176,6 +185,32 @@ func startServerJob(pidChan chan int, startAppChan chan bool) { pidChan <- pid }() } + } else if runtime.GOOS == "linux" { + execFile := pwd + "/tmp/" + path.Base(pwd) + binary, lookErr := exec.LookPath("/bin/sh") + if lookErr != nil { + panic(lookErr) + } + args := []string{"/bin/sh", "-c", execFile} + execSpec := &syscall.ProcAttr{ + Dir: pwd, + Env: os.Environ(), + Files: []uintptr{os.Stdin.Fd(), os.Stdout.Fd(), os.Stderr.Fd()}, + Sys: &syscall.SysProcAttr{ + Setpgid: true, + }, + } + pid, _, err = syscall.StartProcess(binary, args, execSpec) + if err != nil { + fmt.Println("error starting process: ", err.Error()) + go func() { + pidChan <- 0 + }() + } else { + go func() { + pidChan <- pid + }() + } } else { fmt.Println("not implemented for os: ", runtime.GOOS) }