How to embed Yaws with SSL? - yaws

I'd like to embed yaws with ssl, but it shows error message, Can anyone tell me how to set SSL property ?
Below is my code
Id = "my_server",
GconfList = [{logdir, "/Users/james/Documents/workspaces/erlang/embed_yaws/log"},
{ebin_dir, ["/Users/james/Documents/workspaces/erlang/embed_yaws/ebin"]},
{id, Id}],
Docroot = "/Users/james/Documents/workspaces/erlang/embed_yaws/www",
SconfList = [
{docroot, Docroot},
{port, 4444},
{listen, {0,0,0,0}},
{ssl,[{keyfile, "/Users/james/Develop/yaws-2.0.2/etc/yaws/yaws-key.pem"},
{certfile, "/Users/james/Develop/yaws-2.0.2/etc/yaws/yaws-cert.pem"},
{depth,0},{dhfile,"/Users/james/Develop/yaws-2.0.2/etc/yaws/dhparams.pem"}]},
{appmods, [{"/rest", myappmod1, []},{"/ws", myws, []}]}
],
yaws:start_embedded(Docroot, SconfList, GconfList, Id)
The Partial Error Message is below
=ERROR REPORT==== 16-Oct-2015::17:10:17 ===
FATAL: {noproc,
{gen_server,call,
......
=ERROR REPORT==== 16-Oct-2015::17:10:17 ===
** Generic server yaws_server terminating
** Last message in was {setconf,
.........
** When Server state == {state,undefined,[],0,true}
** Reason for termination ==
** {badbind,[{yaws_server,start_group,2,
[{file,"src/yaws_server.erl"},{line,271}]},
{lists,filtermap,2,[{file,"lists.erl"},{line,1315}]},
{yaws_server,init2,5,[{file,"src/yaws_server.erl"},{line,248}]},
{yaws_server,handle_call,3,
[{file,"src/yaws_server.erl"},{line,314}]},
{gen_server,try_handle_call,4,
[{file,"gen_server.erl"},{line,607}]},
{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,639}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,237}]}]}

The ssl application isn't running. Before calling yaws:start_embedded/4, start ssl like this:
application:ensure_all_started(ssl),
yaws:start_embedded(Docroot, SconfList, GconfList, Id)
If you're using an older version of Erlang that doesn't provide application:ensure_all_started/1, which is any version older than R16B02, you can start ssl like this instead:
[application:start(App) || App <- [crypto, public_key, ssl]],

Related

Erlang: starting gen_server on another node fails after init

I am stuck in a bit of a fix trying to run gen_server on another node. So I have a common gen_server class which looks like this
start(FileName) ->
start_link(node(), FileName).
start_link(ThisNode, FileName) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [ThisNode, FileName], []).
init([ThisNode, FileName]) ->
process_flag(trap_exit, true),
{ok, Terms} = file:consult(FileName),
{A1, B1, C1} = lists:nth(1,Terms),
place_objects(A1, B1, C1).
Now I want to start multiple nodes that will run the same gen_server and somehow communicate with each other, and use a another node to orchestrate that. (All these nodes are started on my local terminal).
So I start a new node in one terminal using erl -sname bar where I intend to run the gen_server, and compile the gen_server module on this node. Then I start another node called 'sup' which I intend to use as a coordinator for all the other nodes. If I run the command my_gen_server:start("config_bar.txt"). on bar, it successfully returns but when I run the command rpc:call('bar#My-MacBook-Pro', my_gen_server, start, ["config_bar.txt"]). on sup, it successfully returns from the init method (I checked this by putting in the logs) but immediately after that, I get this error:
{ok,<9098.166.0>}
(sup#My-MacBook-Pro)2> =ERROR REPORT==== 21-Feb-2022::11:12:30.443051 ===
** Generic server my_gen_server terminating
** Last message in was {'EXIT',<9098.165.0>,
{#Ref<0.3564861827.2990800899.137513>,return,
{ok,<9098.166.0>}}}
** When Server state == {10,10,#Ref<9098.1313723616.3973185546.82660>,
'bar#My-MacBook-Pro'}
** Reason for termination ==
** {#Ref<0.3564861827.2990800899.137513>,return,{ok,<9098.166.0>}}
=CRASH REPORT==== 21-Feb-2022::11:12:30.443074 ===
crasher:
initial call: my_gen_server:init/1
pid: <9098.166.0>
registered_name: my_gen_server
exception exit: {#Ref<0.3564861827.2990800899.137513>,return,
{ok,<9098.166.0>}}
in function gen_server:decode_msg/9 (gen_server.erl, line 481)
ancestors: [<9098.165.0>]
message_queue_len: 0
messages: []
links: []
dictionary: []
trap_exit: true
status: running
heap_size: 1598
stack_size: 29
reductions: 3483
neighbours:
I can't seem to figure out what causes the error and if there's anything I need to add to my gen_server code to fix it. Would really appreciate some help on this one!
The gen_server in the remote node is linked to an ephemeral process created for the rpc call.
As this ephemeral process exits with a term that's different from normal (the actual result of the rpc call), the exit signal propagates to the gen_server, killing it.
You can use gen_server:start instead of gen_server:start_link or, if you want the gen_server to be part of the supervission tree, instruct its supervisor to spawn it:
rpc:call('bar#My-MacBook-Pro', my_gen_sup, start_child, ["config_bar.txt"]).

Can not start Erlang Application due to bad return error

I have a simple erlang application and i am trying to start it to no avail getting a bad return error:
> {error,
> {bad_return,
> {{mapp,start,[normal,[]]},
> {'EXIT',
> {undef,
> [{mapp,start,[normal,[]],[]},
> {application_master,start_it_old,4,
> [{file,"application_master.erl"},{line,277}]}]}}}}}
.app
{
application,mapp,
[
{vsn,"1.0.0"},
{description,"some description"},
{mod,{mapp,[]}},
{modules,[mapp,m1]}
]
}.
Folder structure:
-root
-mapp.app
-src
-m1.erl
-mapp.erl
-include
-state.hrl
-ebin
Application
-module(mapp).
-behaviour(application).
-export([start/2,stop/1]).
start(normal,_Args)->
Pid=m1:start_link(),
{ok,Pid}.
stop(State)->ok.
Module
-module(m1).
-include("r.hrl").
-export([start_link/0]).
start_link()->
Pid=spawn_link(?MODULE,serv,#state{count=2}),
Pid.
serv(State=#state{count=C})->
receive
{From,MSG} ->From ! {ok,MSG},
serv(State#state{count=C=1})
end.
.hrl
-record(state,{
count=0
}).
So my m1 module returns a Pid.I comply to the application:start/2 return type and return a {ok,Pid}.
What is wrong here ? I have tried both with Pid and {ok,Pid} to no avail.
The error states that the mapp:start/2 is undef. Seeing that your mapp.erl exports it, I suspect that the module mapp is not loaded.
How are you running the application? I suspect that you're not using a release tool like rebar3 or erlang.mk because usually the app files are inside src.

Error during starting the application with cowboy example ('noproc', ranch_listener_sup)

I'm trying run this cowboy example using rebar3:
cowboy version 2.0.0-pre.5
What I do is:
rebar3 new app hello_world
copy the example src into my src
updating rebar.config {cowboy,".*", {git, "https://github.com/ninenines/cowboy", {branch, "master"}}}
rebar3 compile. Everything go fine
erl -pa _build/default/lib/*/ebin
application:start(hello_world).
then error occurs
{error,{bad_return,{{hello_world_app,start,[normal,[]]},
{'EXIT',{noproc,{gen_server,call,
[ranch_sup,
{start_child,{{ranch_listener_sup,http},
{ranch_listener_sup,start_link,
[http,100,ranch_tcp,
[{connection_type,supervisor},{port,...}],
cowboy_clear,
#{connection_type => supervisor,...}]},
permanent,infinity,supervisor,
[ranch_listener_sup]}},
infinity]}}}}}}
=INFO REPORT==== 24-Jan-2017::18:34:52 ===
application: hello_world
exited: {bad_return,
{{hello_world_app,start,[normal,[]]},
{'EXIT',
{noproc,
{gen_server,call,
[ranch_sup,
{start_child,
{{ranch_listener_sup,http},
{ranch_listener_sup,start_link,
[http,100,ranch_tcp,
[{connection_type,supervisor},
{port,8080}],
cowboy_clear,
#{connection_type => supervisor,
env => #{dispatch => [{'_',[],
[{[],[],toppage_handler,
[]}]}]}}]},
permanent,infinity,supervisor,
[ranch_listener_sup]}},
infinity]}}}}}
type: temporary
It seems that runch_sup can't start.
What's wrong with my approach?
I want to run exactly the same src code as in example.
Ranch 1.3 depends on the ssl application by default. If you don't
start it, Ranch fails to start. I would recommend matching on ok when
doing ok = application:start(App), you'd have known the issue much
quicker.
by essen
here is the issue

ERROR REPORT Generic server <0.35.0> terminating Last message in was {req_timeout,#Ref<0.0.0.60>}

I am going through the riak-erlang-client https://github.com/basho/riak-erlang-client. As i am following the steps, i am facing error at storing the data.
I did the following:
2> {ok,Pid} = riakc_pb_socket:start_link("127.0.0.1",8087).
{ok,<0.35.0>}
3>
3>
3> riakc_pb_socket:ping(Pid).
pong
4> Val = 1.
1
7> Obj = riakc_obj:new(<<"Bucket">>,<<"one">>,Val).
{riakc_obj,<<"Bucket">>,<<"one">>,undefined,[],undefined,1}
everything was working here as per the documents, but when i am trying to store the data with the following command.
8> riakc_pb_socket:put(Pid,Obj).
After this command i am getting the following error,
=ERROR REPORT==== 13-May-2014::18:15:46 ===
** Generic server <0.35.0> terminating
** Last message in was {req_timeout,#Ref<0.0.0.60>}
** When Server state == {state,"127.0.0.1",8087,false,false,undefined,false,
gen_tcp,undefined,
{[],[]},
1,[],infinity,undefined,undefined,undefined,
undefined,[],100}
** Reason for termination ==
** disconnected
** exception exit: disconnected
where i am doing wrong, please suggest me.
That error means that your TCP request timed out for some reason. Is there anything in Riak's error.log or console.log files that could tell you why?
Can you test to see if your Riak node is running by going to http:127.0.0.1:8098/ping in a browser?
If it's up and running you can try your test again by either clearing your currently bound variables with f(). (or opening a new Erlang REPL), and retrying the commands.

Erlang register process

I try to spawn new process and register it:
-module(db).
-export([start/0]).
start() ->
register( db , spawn( db, abs, [-100])).
But when i try in erlang shell:
1> db:start().
I see:
true
(emacs#myhost)2>
=ERROR REPORT==== 1-Dec-2010::17:42:27 ===
Error in process <0.112.0> on node 'emacs#myhost' with exit value: {undef,[{db,abs,[-100]}]}
What's wrong?
Thank you.
This fails because db:abs/1 is not defined.

Resources