Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS Catalina: Does not work #45

Open
vonhraban opened this issue Oct 24, 2019 · 14 comments
Open

MacOS Catalina: Does not work #45

vonhraban opened this issue Oct 24, 2019 · 14 comments

Comments

@vonhraban
Copy link

vonhraban commented Oct 24, 2019

It does not work with the following message:

$ watcher
2019/10/24 21:02:15 build started
Building ....
2019/10/24 21:02:17 build completed
Running ...
2019/10/24 21:02:17 process interrupted: signal: killed

Other people from my team who upgraded to Catalina report the same

$ go version
go version go1.12.9 darwin/amd64
@vonhraban vonhraban changed the title MacOS Catalina: Does not work, MacOS Catalina: Does not work Oct 24, 2019
@puneet-sutar
Copy link

Guys getting the same error on macOS Catalina.
@vonhraban Were you able to solve the issue?

@dsincl12
Copy link

yup same here, i will see if i get some time this evening to find out what's causing this and make a pull request.

@dsincl12
Copy link

ok i've found the issue and got a fix for it. it's not done yet but the problem is the change to zsh from bash on MacOS Catalina. I will try to get it done tomorrow after work.

If you're on Catalina and just want to get it working, change runCommand() in common.go:

func runCommand(name string, args ...string) (*exec.Cmd, error) {
	var cmd *exec.Cmd

	if len(args) == 0 {
		cmd = exec.CommandContext(context.Background(), "/bin/zsh", "-c", name)
	} else {
		cmd = exec.Command(name, args...)
	}

	stderr, err := cmd.StderrPipe()
	if err != nil {
		return cmd, err
	}

	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return cmd, err
	}

	if err := cmd.Start(); err != nil {
		return cmd, err
	}

	go io.Copy(os.Stdout, stdout)
	go io.Copy(os.Stderr, stderr)

	return cmd, nil
}

and then change Run() in run.go:

func (r *Runner) Run(p *Params) {
	for fileName := range r.start {

		color.Green("Running %s...\n", p.Get("run"))

		cmd, err := runCommand(fileName, p.Package...)
		if err != nil {
			log.Printf("Could not run the go binary: %s \n", err)
			r.kill(cmd)

			continue
		}

		r.cmd = cmd

		go func(cmd *exec.Cmd, fileName string) {
			if err := cmd.Wait(); err != nil {
				log.Printf("process interrupted: %s \n", err)
				r.kill(cmd)
			}

			removeFile(fileName)
		}(r.cmd, fileName)
	}
}

@dsincl12
Copy link

Uhm... seems to be even simpler. You only need to make the change to Run() (i.e. moving removeFile()).

@dedo1911
Copy link

I had to add this line before runCommand in Run func:
fileName = "./" + fileName

It was trying to search for fileName in PATH.. maybe I'm missing something.

I've also added removeFile to the err handler of runCommand, right before continue. To don't leave any invalid executable around...

@zzeynal
Copy link

zzeynal commented Jun 9, 2020

Hello,
after cloning and installin golang watcher, try to type watcher on my terminal, on cd /path/to/myapp directory following error returns:

zsh: command not found: watcher

Could you please advice what is wrong?

Btw, I am using MacOS Catalina

Thanks for your support

@tzusman
Copy link

tzusman commented Jun 9, 2020

@zzeynal Not sure why you added your question to this issue, but here's your problem: Just because you are in the folder, it doesn't mean that folder is in your $PATH. You can do one of two things: add that folder to your $PATH environment variable, or just run ./watcher. You may need to chmod +x ./watcher first if it's not already executable.

@zzeynal
Copy link

zzeynal commented Jun 12, 2020

@zzeynal Not sure why you added your question to this issue, but here's your problem: Just because you are in the folder, it doesn't mean that folder is in your $PATH. You can do one of two things: add that folder to your $PATH environment variable, or just run ./watcher. You may need to chmod +x ./watcher first if it's not already executable.

# @tzusman Thanks for your reply.

Somehow I have fixed and watcher command already works. But now I have same issue with building and running the myapp.

Building ....
2020/06/12 19:28:11 build completed
Running ...
2020/06/12 19:28:11 process interrupted: signal: killed

It does not build any executable file nor runs any, as there does not appear any exeucatble file.

While nomral outcome instead of above outcome, should look like as the below:

Building ....
2020/06/12 19:28:11 build completed
Running ...
2020/06/12 19:28:11 process interrupted: signal: killed
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.

  • using env: export GIN_MODE=release
  • using code: gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET /posts --> main.Posts (3 handlers)
[GIN-debug] GET /posts/:id --> main.Show (3 handlers)
[GIN-debug] POST /posts --> main.Store (3 handlers)
[GIN-debug] PATCH /posts/:id --> main.Update (3 handlers)
[GIN-debug] DELETE /posts/:id --> main.Delete (3 handlers)
[GIN-debug] Listening and serving HTTP on :9090

it should build and then run that build executable, but unfortunately it does not happen.

I have make all mentioned changes to Run() funtion and all other stuff, but still the same outcome.

Please help!

Thanks in advance!

@tzusman
Copy link

tzusman commented Jun 12, 2020

@zzeynal Your question isn't watcher related, so I would post this question in a more appropriate place. I would however ensure that go build and go run works for your app, otherwise watcher won't be able to run it either. good luck

@zzeynal
Copy link

zzeynal commented Jun 12, 2020

@zzeynal Your question isn't watcher related, so I would post this question in a more appropriate place. I would however ensure that go build and go run works for your app, otherwise watcher won't be able to run it either. good luck

@tzusman yes, sure while running go build and go run commands my app works.

Much appreciate your support.

@zzeynal
Copy link

zzeynal commented Jun 13, 2020

ok i've found the issue and got a fix for it. it's not done yet but the problem is the change to zsh from bash on MacOS Catalina. I will try to get it done tomorrow after work.

If you're on Catalina and just want to get it working, change runCommand() in common.go:

func runCommand(name string, args ...string) (*exec.Cmd, error) {
	var cmd *exec.Cmd

	if len(args) == 0 {
		cmd = exec.CommandContext(context.Background(), "/bin/zsh", "-c", name)
	} else {
		cmd = exec.Command(name, args...)
	}

	stderr, err := cmd.StderrPipe()
	if err != nil {
		return cmd, err
	}

	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return cmd, err
	}

	if err := cmd.Start(); err != nil {
		return cmd, err
	}

	go io.Copy(os.Stdout, stdout)
	go io.Copy(os.Stderr, stderr)

	return cmd, nil
}

and then change Run() in run.go:

func (r *Runner) Run(p *Params) {
	for fileName := range r.start {

		color.Green("Running %s...\n", p.Get("run"))

		cmd, err := runCommand(fileName, p.Package...)
		if err != nil {
			log.Printf("Could not run the go binary: %s \n", err)
			r.kill(cmd)

			continue
		}

		r.cmd = cmd

		go func(cmd *exec.Cmd, fileName string) {
			if err := cmd.Wait(); err != nil {
				log.Printf("process interrupted: %s \n", err)
				r.kill(cmd)
			}

			removeFile(fileName)
		}(r.cmd, fileName)
	}
}

after changing Run() func in run.go file I got such a problem:

exported method Runner.Run should have comment or be unexported go-lint

Please advice.

@zzeynal
Copy link

zzeynal commented Jun 14, 2020

Guys solved my issue!
Everything is done great, based upon your advice.

Thanks!

@yalexx
Copy link

yalexx commented Oct 16, 2020

I have the same issue with Mac OS Catalina. How do I build the watcher after I change the code?

❯ watcher -c config.dev.yaml
2020/10/16 10:35:48 build started
Building ....
2020/10/16 10:35:55 build completed
Running ...
2020/10/16 10:35:55 process interrupted: signal: killed

@fajardm
Copy link

fajardm commented Aug 23, 2021

any progress on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants