Erlang/Yaws: 无法使用 .conf 文件在应用程序内启动 Web 服务器

Erlang/Yaws: Cannot start web server within application using .conf file

我有点不知所措。 YAWS 在 LXQt 19.04 的引导期间作为服务启动时运行良好。但我打算使用限速器;将其设置为 arg_rewrite_mod。有一个 VM 运行 YAWS 和另一个我的应用程序,适当地设置代码路径,我相信会产生低于标准的性能,因为速率限制调用将使用基于 OS 的 IPC 而不是 Erlang IPC。因此应该有 OS IPC 开销而不是 EVM 开销,对吗?

我基本上只是希望所有东西都集中在一个引擎盖下以消除它。这是一回事,可能有几种方法可以解决这个问题(即拆分我的项目并在需要的地方复制部分),但我喜欢 "simplicity" 一切都集中在一个地方。

我在 shell 之后收到一个错误,{badmatch, {error, enoent}}

code:add_patha("/usr/lib/yaws/ebin").
application:start(yaws).

它发生在 yaws_server:setup_dirs/1 (Github)

的第 548 行
setup_dirs(GC) ->
    Dir = yaws:id_dir(GC#gconf.id),
    Ctl = yaws:ctl_file(GC#gconf.id),
    ok = filelib:ensure_dir(Ctl),
    case file:list_dir(Dir) of
        {ok, LL} ->
            lists:foreach(
              fun(F) ->
                      file:delete(filename:join([Dir, F]))
              end, LL -- ["CTL"]); %%%  <---- LINE 548
        {error, RSN} ->
            error_logger:format("Failed to list ~p probably "
                                "due to permission errs: ~p",
                                [Dir, RSN]),
            erlang:error(RSN)
    end.

我创建了一个由我自己和用户 yaws 组成的 UNIX 组 appname。我已经遍历了用 sudo find / -group yaws -type d 找到的各种目录,并将组权限设置为与所有者相同,并将组从 yaws 重新分配到 appname...我相信自从我没有设置id它是"default"。我的日志 (/var/log/yaws/report.log) 我希望能指出问题所在。它们是空的。

我实际上是在使用默认的 /etc/yaws/yaws.conf 文件。服务器部分已被删除并放置在 /etc/yaws/conf.avail/ 中,符号链接在 /etc/yaws/conf.d/.

更新:崩溃报告----

2020-03-27T08:30:04.131073-05:00 notice: Yaws: Using config file /etc/yaws/yaws.conf

2020-03-27T08:30:04.136142-05:00 error: use_old_ssl in yaws.conf is no longer supported - ignoring

2020-03-27T08:30:04.137441-05:00 notice: Yaws: Using global subconfig file /etc/yaws/conf.d/localhost.conf

2020-03-27T08:30:04.140979-05:00 error:
    crasher:
        initial call: yaws_server:init/1,
        pid: <0.114.0>,
        registered_name: [],
        error: {{badmatch,{error,enoent}},
            [{yaws_server,setup_dirs,1,[{file,"yaws_server.erl"},{line,548}]},
            {yaws_server,init2,5,[{file,"yaws_server.erl"},{line,224}]},
            {gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},
            {gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},
            {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]},
        ancestors: [yaws_sup,<0.108.0>],
        message_queue_len: 0,
        messages: [],
        links: [<0.109.0>,#Port<0.6>],
        dictionary: [{gc,{gconf,"/usr/lib/yaws",false,612,"/var/log/yaws",
                ["/usr/local/lib/yaws-appmods/ebin","/usr/lib/yaws/examples/ebin"],
                [],[],30000,nolimit,400,1000000,8000,nolimit,[],10240,[],0,30,
                ["/usr/local/lib/yaws-appmods/include","/usr/lib/yaws/examples/include"],
                "/usr/bin/php-cgi","Yaws 2.0.6","default",false,[],8,undefined,
                [inet],yaws_session_server,undefined,120000,3600000,disable}},
        {start_time,{{2020,3,27},{8,30,4}}}],
        trap_exit: true,
        status: running,
        heap_size: 1598,
        stack_size: 27,
        reductions: 32410;
    neighbours:

2020-03-27T08:30:04.141195-05:00 error:
    supervisor: {local,yaws_sup},
    errorContext: start_error,
    reason: {{badmatch,{error,enoent}},
        [{yaws_server,setup_dirs,1,[{file,"yaws_server.erl"},{line,548}]},
        {yaws_server,init2,5,[{file,"yaws_server.erl"},{line,224}]},
        {gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},    
        {gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},
        {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]},
    offender: [{pid,undefined},
        {id,yaws_server},
        {mfargs,
            {yaws_server,start_link,
                [{env,false,false,false,false,false,false,"default",latin1}]}},
        {restart_type,permanent},
        {shutdown,120000},
        {child_type,worker}]

2020-03-27T08:30:04.145621-05:00 error: 
    crasher:
        initial call: application_master:init/4,
        pid: <0.107.0>,
        registered_name: [],
        exit: {{{shutdown,{failed_to_start_child,yaws_server,{{badmatch,{error,enoent}},
            [{yaws_server,setup_dirs,1,[{file,"yaws_server.erl"},{line,548}]},
            {yaws_server,init2,5,[{file,"yaws_server.erl"},{line,224}]},
            {gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},
            {gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},
            {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}}},
        {yaws_app,start,[normal,[]]}},
            [{application_master,init,4,[{file,"application_master.erl"},{line,138}]},
            {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]},
        ancestors: [<0.106.0>],
        message_queue_len: 1,
        messages: [{'EXIT',<0.108.0>,normal}],
        links: [<0.106.0>,<0.43.0>],
        dictionary: [],
        trap_exit: true,
        status: running,
        heap_size: 987,
        stack_size: 27,
        reductions: 225;
    neighbours:

2020-03-27T08:30:04.147171-05:00 notice:
    application: yaws,
    exited: {{shutdown,{failed_to_start_child,yaws_server,{{badmatch,{error,enoent}},
        [{yaws_server,setup_dirs,1,[{file,"yaws_server.erl"},{line,548}]},
        {yaws_server,init2,5,[{file,"yaws_server.erl"},{line,224}]},
        {gen_server,init_it,2,[{file,"gen_server.erl"},{line,374}]},
        {gen_server,init_it,6,[{file,"gen_server.erl"},{line,342}]},
        {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},
        {line,249}]}]}}},{yaws_app,start,[normal,[]]}},
    type: temporary

解决方案: 从下面的答案的帮助和使用上面的 find 探索各种 YAWS 路径,我发现 "default" 主目录对我来说是“/var/cache/yaws/”。 shell 中的以下一系列命令对我有用:

os:putenv("YAWSHOME","/var/cache/yaws/").
code:add_patha("/usr/lib/yaws/ebin").
application:start(yaws).

你的问题中显示的源代码第548行不能return {error, enoent},但是yaws_server.erl版本2.0.6的第548行是

ok = filelib:ensure_dir(Ctl),

这就是 return 错误元组,它无法匹配预期的原子 ok 并导致失败。

函数filelib:ensure_dir/1 验证其参数的父目录是否存在,如果不存在则尝试创建它们。因此,解决此问题需要确定上面代码中的 Ctl 参数路径名。

由于您的服务器 ID 是 "default",Ctl 在这种情况下被定义为路径

<HOME>/.yaws/yaws/default/CTL

其中 <HOME> 来自 YAWSHOME 环境变量的设置(如果存在),否则来自 HOME 环境变量的设置。确保将这些环境变量之一设置为合适的路径,并且其下的 .yaws/yaws/default 子目录(如果已经存在)对您的 yaws 用户 ID 和 appname 组 ID 具有适当的权限.