执行emqx ping报错

版本:4.4.1
OS:Ubuntu 18.04.5

现象:用supervisor启动emqx和服务,服务中用golang自带的os/exec包去执行emqx ping命令报错,但是直接启动服务就没问题。具体的报错信息如下:

escript: exception error: no match of right hand side value 
                 {error,
                     {{shutdown,
                          {failed_to_start_child,auth,
                              {"No home for cookie file",
                               [{auth,init_no_setcookie,0,
                                    [{file,"auth.erl"},{line,293}]},
                                {auth,init,1,[{file,"auth.erl"},{line,144}]},
                                {gen_server,init_it,2,
                                    [{file,"gen_server.erl"},{line,423}]},
                                {gen_server,init_it,6,
                                    [{file,"gen_server.erl"},{line,390}]},
                                {proc_lib,init_p_do_apply,3,
                                    [{file,"proc_lib.erl"},{line,226}]}]}}},
                      {child,undefined,net_sup_dynamic,
                          {erl_distribution,start_link,
                              [['remsh_maint_emqx118969@127.0.0.1',longnames],
                               false,net_sup_dynamic]},
                          permanent,false,1000,supervisor,
                          [erl_distribution]}}}
  in function  nodetool__escript__1693__280646__434859__8:'-main/1-fun-3-'/1 (/opt/demo/deps/emqx/bin/nodetool, line 29)
  in call from nodetool__escript__1693__280646__434859__8:do_with_ret/3 (/opt/demo/deps/emqx/bin/nodetool, line 145)
  in call from nodetool__escript__1693__280646__434859__8:main/1 (/opt/demo/deps/emqx/bin/nodetool, line 26)
  in call from escript:run/2 (escript.erl, line 750)
  in call from escript:start/1 (escript.erl, line 277)
  in call from init:start_em/1 
  in call from init:do_boot/3 

otp/kernel/src/auth.erlL378-L425 看起来是因为没有读到 erlang cookie

用 supervisor 启动服务的流程,还有 golang 代码片段可以贴到帖子里来看下

好的,谢谢。

golang代码片段:

func getMqttStatus(ctx context.Context) string {
	_ = os.Chdir("/opt/demo/deps/emqx/bin")

	cmd := exec.Command("./emqx", "ping")
	var stdOut, stdErr bytes.Buffer
	cmd.Stdout = &stdOut
	cmd.Stderr = &stdErr

	err := cmd.Run()
	if err != nil {
		if gstr.Contains(stdErr.String(), "ping") {
			return stdErr.String()
		}
		logger.Logger.Errorf(ctx, "exec emqx ping error, err: %v, stdEff: %v", err, cmd.Stderr)
		return ""
	}
	return stdOut.String()
}

supervisor启动流程:

  1. 在supervisord.conf中添加服务的配置:
[program:demo]
directory=/opt/demo
command=/opt/demo/src/demo -c /opt/demo/conf/demo.yaml
autostart=true
autorestart=true
user=root
priority=5
killasgroup=true
stopasgroup=true
depends_on=redis,mysql
stdout_logfile=/dev/null
stderr_logfile=/opt/demo/logs/demo.err.log
  1. 安装并启动supervisord服务
./supervisord service install -c /opt/Supervisor/supervisord.conf
./supervisord service start
  1. 启动服务
./supervisord ctl start demo

应该是 golang 中 exec 的问题

“No home for cookie file”

这条日志是因为 otp/kernel/src/auth.erlL378-L425 是因为没有读到 erlang cookie
也就是这读取不到这两个文件 ~/.erlang.cookie$XDG_CONFIG_HOME/erlang/.erlang.cookie

好的谢谢