diff --git a/cmd/serve.go b/cmd/serve.go index bdc76b95e..f9c71b2e6 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -26,7 +26,8 @@ import ( "net/http" "net/url" "os" - "path" + "os/exec" + "path/filepath" "strconv" "strings" ) @@ -73,6 +74,15 @@ func autoPort() string { return "8991" } +func exePath() (string, error) { + file, err := exec.LookPath(os.Args[0]) + if err != nil { + return "", err + } + + return filepath.Abs(file) +} + // search packages func runServe(cmd *Command, args []string) { // Check flags. @@ -318,7 +328,11 @@ func AutoRun() error { Files: []*os.File{nil, nil, nil}, } - p := path.Join(curPath, "gopm") + p, err := exePath() + if err != nil { + return err + } + _, err = os.StartProcess(p, []string{"gopm", "serve", "-l"}, attr) if err != nil { return err @@ -376,8 +390,9 @@ func getPidPath() (string, error) { return "", err } - pFile := strings.Replace("~/.gopm/var/pid", "~", homeDir, -1) - return pFile, nil + pFile := strings.Replace("~/.gopm/var/", "~", homeDir, -1) + os.MkdirAll(pFile, os.ModePerm) + return pFile + "pid", nil } func startService(listen, port string) error { diff --git a/build.sh b/install.sh similarity index 87% rename from build.sh rename to install.sh index 0c59d1202..9f89ab84f 100755 --- a/build.sh +++ b/install.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -if [ ! -f build.sh ]; then +if [ ! -f install.sh ]; then echo 'build.sh must be run within its container folder' 1>&2 exit 1 fi @@ -14,7 +14,7 @@ fi gofmt -w $CURDIR cd $NEWPATH -go build +go install cd $CURDIR echo 'Build successfully!'