1

I'm trying to run a go command via "upstart" on my ubuntu.

My upstart script is

script
  go run /home/myhome/gocode/src/program/hello.go
end script

It's not working and I checked the log file and it says

/bin/sh: 1: /bin/sh: go: not found

I can run "go" on command line using any user name. How do I fix this?

ericbae
  • 9,604
  • 25
  • 75
  • 108

2 Answers2

6

You shouldn't be using go run to run your Go program. You should compile it with go build and then use Upstart to run that.

Use exec /path/to/your/binary instead.

Also see: - Can't Start Golang Prog Via Upstart - https://coderwall.com/p/iekaog - https://groups.google.com/forum/m/#!topic/golang-nuts/uBrN-G7anKg (lots of examples)

Community
  • 1
  • 1
elithrar
  • 23,364
  • 10
  • 85
  • 104
2

Type which go as another user to find out the full path to the go executable. Then, in your upstart script, replace go with the full path (e.g. /usr/local/go/bin).

I am not sure why you are having this problem, but maybe the upstart user has a different path than normal users (i.e. it might include /sbin instead of /usr/bin).

David Grayson
  • 84,103
  • 24
  • 152
  • 189
  • I added "/usr/local/go/bin" in the "etc/profile" - doesn't that make it system-wide? But that didn't work either. I also tried on "/etc/environment" - no success. – ericbae Jan 13 '14 at 01:44
  • Why was this downvoted? I suggested one thing that would have a good chance of working, the OP strangely did something else, and someone downvoted it. – David Grayson Jan 13 '14 at 05:09
  • 1
    wan't me, sorry for the late reply. I did try "which go" and tried the full path on the upstart script - to no avail. In the end, I knew I shouldn't run go program via "go run". So I built it and then used the upstart to call it - that did the trick (though it's still mystery to me why things weren't picking up initially) – ericbae Jan 13 '14 at 05:33