openlang

How can an inets server be stopped?

Hello,

I've got a fairly elementary question about inets (which, incidentally, I find quite handy because it needs no additional dependency): how do we shut down an inets “service” we've launched (say, on version 28.4)?

The attempts below didn't succeed:


Eshell V16.3 (press Ctrl+G to abort, type help(). for help)

(demo@nodebox)1> inets:start().
ok
(demo@nodebox)2> {ok,ServerPid} = inets:start( httpd,[{profile,cedar}, {port,8080}, {server_name,"maple"}, {server_root,"."}, {document_root,"."}, {bind_address,"127.0.0.1"}]).
{ok,<0.115.0>}
(demo@nodebox)3> inets:stop( httpd, ServerPid).
{error,not_found}
(demo@nodebox)4> inets:stop( httpd, cedar).
** exception error: no function clause matching httpd:stop_service(cedar) (httpd.erl:1278)
	 in function  inets:call_service/3 (inets.erl:558)
(demo@nodebox)5> inets:stop( httpd, "maple").
** exception error: no function clause matching httpd:stop_service("maple") (httpd.erl:1278)
	 in function  inets:call_service/3 (inets.erl:558)
(demo@nodebox)7> inets:services().
[{httpc,<0.111.0>},{httpd,<0.115.0>}]
(demo@nodebox)8> ServerPid.
<0.115.0>
(demo@nodebox)9> inets:services_info().
[{httpc,<0.111.0>,[{profile,default}]},
 {httpd,<0.115.0>,
		[{bind_address,{127,0,0,1}},
		 {host,"nodebox"},
		 {port,8080},
		 {server_name,"maple"}]}]

Could the httpd entry shown above somehow be missing a {profile,cedar}?

I'd appreciate any pointers, thanks!

Tavin.

The conversation continues 2

Follow the reasoning
  1. Permalink

    Hello,

    For an httpd service started with a profile, the shutdown call is inets:stop(httpd, {BindAddress, Port, Profile})

    For one launched without any profile, either inets:stop(httpd, {BindAddress, Port}) or inets:stop(httpd, ServerPid) can be used

    I'd expect the profile name in inets:services_info() too, although I must investigate whether something explains its absence.

    Kind regards,

    Mervin

  2. Permalink

    Thanks very much Mervin, inets:stop(httpd, {{127,0,0,1}, 8080, cedar}) does exactly what I need!

    Perhaps inets — inets v9.6.2 (https://www.erlang.org/doc/apps/inets/inets.html#stop/2) might better explain the “Reference :: pid (https://www.erlang.org/doc/apps/erts/erlang.html#t:pid/0)() | term (https://www.erlang.org/doc/apps/erts/erlang.html#t:term/0)()” type more clearly and stress that, for servers, most relevant details actually live under httpd — inets v9.6.2 (https://www.erlang.org/doc/apps/inets/httpd.html) (and likewise httpc — inets v9.6.2 (https://www.erlang.org/doc/apps/inets/httpc.html) for clients).

    Thanks once more!

Other sides of the same question

  1. Opening files on Raspberry Pi 4

    On a Raspberry Pi 4 I use fopen inside a for loop to read files from a particular directory, over 1200 of them. Once the loop…

    Replies 2Latest activity c
  2. Does Go reserve SIGUSR1 and SIGUSR2?

    Dear programmers, we want to execute a go application under dmtcp (GitHub hosts dmtcp/dmtcp, the DMTCP distributed multithrea…

    Replies 2Latest activity go