英文:
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
。
另外参考:
- https://stackoverflow.com/questions/19102349/cant-start-golang-prog-via-upstart
- https://coderwall.com/p/iekaog
- https://groups.google.com/forum/m/#!topic/golang-nuts/uBrN-G7anKg(有很多示例)
英文:
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
).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论