今天在另外一台机器上部署新写的服务端,运行后程序崩溃,最后发现erlang的find_executable的没有找到程序。

问题重现:

在open_port处,查看日志报错如下:

1
2
3
4
5
6
7
8
9
10
[rrddir ok]^
[ResRrd:{error,{enoent,[{erlang,open_port,
                                [{spawn_executable,"/usr/local/bin/rrdtool"},^
                                 [{line,1024},{args,["-"]}]],^
                                []},^M
                        {rrdtool,init,1,[{file,"src/rrdtool.erl"},{line,83}]},
                        {gen_server,init_it,6,^M
                                    [{file,"gen_server.erl"},{line,304}]},
                        {proc_lib,init_p_do_apply,3,
                                  [{file,"proc_lib.erl"},{line,227}]}]}}]

怀疑rrdtool-erlang这个库存在bug,移到rrdtool.erl代码处调查问题

rrdtool.erl start:81
1
2
3
4
%% @hidden
init([RRDTool]) ->
    Port = open_port({spawn_executable, RRDTool}, [{line, 1024}, {args, ["-"]}]),
    {ok, Port}.

再定位到上层看gen_server的start函数

rrdtool.erl start:55
1
2
start() ->
    gen_server:start(?MODULE, [os:find_executable("rrdtool")], []).

os:find_executable(“rrdtool”),这个是用直接找到rrdtool可执行程序的调用,回到系统了输入rrdtool返回

1
2
3
4
5
6
7
8
9
10
11
12
RRDtool 1.4.7  Copyright 1997-2012 by Tobias Oetiker <tobi@oetiker.ch>
               Compiled Oct 22 2012 11:33:26

Usage: rrdtool [options] command command_options
Valid commands: create, update, updatev, graph, graphv,  dump, restore,
                last, lastupdate, first, info, fetch, tune,
                resize, xport, flushcached

RRDtool is distributed under the Terms of the GNU General
Public License Version 2. (www.gnu.org/copyleft/gpl.html)

For more information read the RRD manpages

已经装好了啊?那为什么还要报错,难道是做了alias

1
2
[yin@yin-arch monitorserver2]>alias rrdtool
/usr/lib64/rrdtool/bin/rrdtool

果不其然

解决方法

在/usr/local/bin/目录下做一个软连接

1
sudo ln -s /usr/lib64/rrdtool/bin/rrdtool /usr/local/bin/rrdtool

再次运行,enoent问题解决。

继续深入

gen_server:start如何捕捉错误?下回专门讨论。

发表评论