Skip to content

Commit

Permalink
--running-config flag to query a running yaws for its config
Browse files Browse the repository at this point in the history
  • Loading branch information
Claes Wikstrom committed Oct 5, 2010
1 parent 035303b commit 713e35b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions man/yaws.1
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ Query a running yaws daemon for its status, and print it.
\fB--stats [--id id]\fR
Query a running yaws daemon for its statistics, and print it.
.TP
\fB--running-config [--id id]\fR
Query a running yaws daemon for its current configuration, and print it.
This can be useful when attempting to figure out how to set config
in embedded mode. Configure yaws to you liking in non-embedded mode, run
this command and use the output to populate the embedded mode records.
.TP
\fB--load Modules [--id id]\fR
Try to (re)load erlang modules into a running daemon. This is useful
after modifying appmods or modules used by scripts.
Expand Down
2 changes: 2 additions & 0 deletions scripts/yaws.template
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ while [ $# -gt 0 ]
ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl status";;
--stats)
ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl stats";;
--running-config)
ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl running_config";;
-load|--load)
loadid=${id:-default}
$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl load $* $loadid
Expand Down
25 changes: 23 additions & 2 deletions src/yaws_ctl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

-export([start/2, actl_trace/1]).
-export([ls/1,hup/1,stop/1,status/1,load/1,
check/1,trace/1, debug_dump/1, stats/1]).
check/1,trace/1, debug_dump/1, stats/1, running_config/1]).
%% internal
-export([run/1, aloop/3, handle_a/3]).

Expand Down Expand Up @@ -179,6 +179,9 @@ handle_a(A, GC, Key) ->
{stats, Key} ->
a_stats(A),
gen_tcp:close(A);
{running_config, Key} ->
a_running_config(A),
gen_tcp:close(A);
{Other, Key} ->
gen_tcp:send(A, io_lib:format("Other: ~p~n", [Other])),
gen_tcp:close(A);
Expand Down Expand Up @@ -286,6 +289,23 @@ format_ip(IP) ->
[A, B, C, D, E, F, G, H])
end.


a_running_config(Sock) ->
gen_tcp:send(Sock, a_running_config()).
a_running_config() ->
{ok, GC, Groups} = yaws_server:getconf(),
GcStr = ?format_record(GC, gconf),
L = lists:map(fun(Group) ->
["** GROUP ** \n",
lists:map(
fun(SC) ->
?format_record(SC, sconf)
end,
Group)
]
end, Groups),
["** GLOBAL CONF ** \n", GcStr, L].

a_stats(Sock) ->
gen_tcp:send(Sock, a_stats()).
a_stats() ->
Expand Down Expand Up @@ -544,4 +564,5 @@ debug_dump([SID]) ->

stats([SID]) ->
actl(SID, stats).

running_config([SID]) ->
actl(SID, running_config).

0 comments on commit 713e35b

Please sign in to comment.