Stopping an inets service

Hi,

I would have a very basic question regarding inets (that, BTW, I find very useful, as not involving any extra dependency): how (for example with version 28.4) are we to stop an inets “service” that we started?

I tried the following with no luck:

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

(xxx@yyy)1> inets:start().
ok
(xxx@yyy)2> {ok,Pid} = inets:start( httpd,[{profile,foo}, {port,8000}, {server_name,"bar"}, {server_root,"."}, {document_root,"."}, {bind_address,"127.0.0.1"}]).
{ok,<0.105.0>}
(xxx@yyy)3> inets:stop( httpd, Pid).
{error,not_found}
(xxx@yyy)4> inets:stop( httpd, foo).
** exception error: no function clause matching httpd:stop_service(foo) (httpd.erl:1278)
	 in function  inets:call_service/3 (inets.erl:558)
(xxx@yyy)5> inets:stop( httpd, "bar").
** exception error: no function clause matching httpd:stop_service("bar") (httpd.erl:1278)
	 in function  inets:call_service/3 (inets.erl:558)
(xxx@yyy)7> inets:services().
[{httpc,<0.101.0>},{httpd,<0.105.0>}]
(xxx@yyy)8> Pid.
<0.105.0>
(xxx@yyy)9> inets:services_info().
[{httpc,<0.101.0>,[{profile,default}]},
 {httpd,<0.105.0>,
		[{bind_address,{127,0,0,1}},
		 {host,"yyy"},
		 {port,8000},
		 {server_name,"bar"}]}]

In the httpd entry just above, perhaps a {profile,foo} is for some reason lacking?

Thanks in advance for any hint!

Olivier.

1 Like

Hi,
To stop a httpd service with a profile assigned you can use inets:stop(httpd, {BindAddress, Port, Profile})
When service is started without a profile you can use inets:stop(httpd, {BindAddress, Port}) or inets:stop(httpd, Pid)
I think the profile name should appear in inets:services_info() but I need to check if there is any reason it is not present there.

Best regards,
Konrad

1 Like

Many thanks Konrad, inets:stop(httpd, {{127,0,0,1}, 8000, foo}) works like a charm!

Maybe the documentation in inets — inets v9.6.2 could further clarify the “Reference :: pid() | term()” type and emphasize more on the fact that for a server most of the related information is actually to be found in httpd — inets v9.6.2 (same for a client with httpc — inets v9.6.2).

Thanks again!

2 Likes