Golang – command "go" not found when running via Upstart

huangapple go评论97阅读模式
英文:

Golang - command "go" not found when running via Upstart

问题

我正在尝试在我的Ubuntu上通过"upstart"运行一个go命令。

我的upstart脚本是:

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

它没有起作用,我检查了日志文件,显示如下:

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

我可以在命令行上使用任何用户名运行"go"命令。我该如何解决这个问题?

英文:

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?

答案1

得分: 6

你不应该使用go run来运行你的Go程序。你应该使用go build编译它,然后使用Upstart来运行它。

改用exec /path/to/your/binary

另外参考:

英文:

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:

答案2

得分: 2

在另一个用户下输入which go,找出go可执行文件的完整路径。然后,在你的upstart脚本中,将go替换为完整路径(例如/usr/local/go/bin)。

我不确定你为什么会遇到这个问题,但也许upstart用户的路径与普通用户不同(即它可能包含/sbin而不是/usr/bin)。

英文:

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

huangapple
  • 本文由 发表于 2014年1月13日 09:38:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/21082664.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定