Golang 通过 supervisord 进行管理,正确配置环境变量的姿势

首先列出正确配置 supervisord 的配置文件

[program:media_8080]
command=go run main.go server
process_name=media_8080
numprocs=1
directory=/wwwroot/admin/
priority=999
autostart=true
autorestart=true
startsecs=10
startretries=3
exitcodes=0,2
stopsignal=QUIT
stopwaitsecs=10
redirect_stderr=true
stdout_logfile=/var/log/media.log
environment=HOME="/root",GOPATH="/usr/local/gopath",PATH=/usr/local/go/bin:%(ENV_PATH)s

今天在部署的时候,遇到了几个环境变量的问题。

build cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined
go env -w: GOENV can only be set using the OS environment