struCoder / pmgo

pmgo is a process manager for Golang applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Working directory for pmgo processes is not project folder

Anton-Cao opened this issue · comments

(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)
        }
...

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

This information needs to be added to readme or documentation

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

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