struCoder / pmgo

pmgo is a process manager for Golang applications.
MIT License
625 stars 65 forks source link

Working directory for pmgo processes is not project folder #32

Open Anton-Cao opened 6 years ago

Anton-Cao commented 6 years ago

(More of a detail than an issue with pmgo, but I spent some time debugging a bug that was caused by this so I'm hoping that noting it down here can help other people later.)

Child processes that the pmgo daemon manages have the same working directory as the pmgo process. This means the working directory is not the project folder, so relative file paths can break.

To get around this, you can change the working directory:

import (
        "os"
...

func main() {
        gopath := os.Getenv("GOPATH")
        err := os.Chdir(gopath + "/src/{path to project}")
        if err != nil {
                fmt.Println("error changing directories: ", err)
        }
...
struCoder commented 6 years ago

@Anton-Cao Right. when exe pmgo start command, pmgo will build your project from GOPATH/src.

rafaelmaeuer commented 5 years ago

This information needs to be added to readme or documentation

helloworldpark commented 5 years ago

I think this issue should also be fixed, since from go 1.11, projects no longer need to be placed under $GOPATH/src.

youjianglong commented 2 years ago

I submitted the pull request to the start command by adding the cwd parameter to specify the working directory.