forked from goffee/goffee
rewrite
This commit is contained in:
parent
c97afa7564
commit
7f4e3c39da
4 changed files with 44 additions and 9 deletions
|
|
@ -55,7 +55,7 @@ func prepareJobContent(jobName string) string {
|
||||||
t := `package eventjobs
|
t := `package eventjobs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goffee/core"
|
"git.smarteching.com/goffee/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
var {JobName} core.EventJob = func(event *core.Event, c *core.Context) {
|
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
|
_, err = file.WriteString(`package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goffee/core"
|
"git.smarteching.com/goffee/core"
|
||||||
)
|
)
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
|
@ -121,7 +121,7 @@ func prepareMiddlewareContent(middlewareName string) string {
|
||||||
t := `package middlewares
|
t := `package middlewares
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goffee/core"
|
"git.smarteching.com/goffee/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
var {middlewareName} core.Middleware = func (c *core.Context) {
|
var {middlewareName} core.Middleware = func (c *core.Context) {
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ type RepoMeta struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config file
|
// 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"
|
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
|
tempFilePath := os.TempDir() + "/" + tempName
|
||||||
response, err := http.Get(url)
|
response, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error downloading the GoCondor release")
|
fmt.Println("error downloading the Cup release")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
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)
|
_, err = io.Copy(file, response.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error writing the GoCondor release to file")
|
fmt.Println("error writing the Cup release to file")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ func TestDownloadConfig(t *testing.T) {
|
||||||
func TestDownloadGoCondor(t *testing.T) {
|
func TestDownloadGoCondor(t *testing.T) {
|
||||||
// Prepare
|
// Prepare
|
||||||
newCmd := CmdNew{}
|
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) {
|
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||||
res, err := os.ReadFile("testdata/gocondor.tar.gz")
|
res, err := os.ReadFile("testdata/gocondor.tar.gz")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -78,8 +78,8 @@ func TestIsUpdatedRequired(t *testing.T) {
|
||||||
func TestUnpack(t *testing.T) {
|
func TestUnpack(t *testing.T) {
|
||||||
// Prepare
|
// Prepare
|
||||||
cn := CmdNew{}
|
cn := CmdNew{}
|
||||||
filepath := "./testdata/gocondor.tar.gz"
|
filepath := "./testdata/cup.tar.gz"
|
||||||
folderName := "gocondor-0.3-alpha.6"
|
folderName := "cup-0.3-alpha.6"
|
||||||
destPath := os.TempDir()
|
destPath := os.TempDir()
|
||||||
os.RemoveAll(destPath + "/" + folderName)
|
os.RemoveAll(destPath + "/" + folderName)
|
||||||
|
|
||||||
|
|
|
||||||
35
cmd/run.go
35
cmd/run.go
|
|
@ -118,6 +118,15 @@ func startRestartControllerJob(fileChangeChan chan bool, pidChan chan int, start
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error stopping process: ", err.Error())
|
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 {
|
} else {
|
||||||
fmt.Println("not implemented for os: ", runtime.GOOS)
|
fmt.Println("not implemented for os: ", runtime.GOOS)
|
||||||
}
|
}
|
||||||
|
|
@ -176,6 +185,32 @@ func startServerJob(pidChan chan int, startAppChan chan bool) {
|
||||||
pidChan <- pid
|
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 {
|
} else {
|
||||||
fmt.Println("not implemented for os: ", runtime.GOOS)
|
fmt.Println("not implemented for os: ", runtime.GOOS)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue