Skip to content

Commit

Permalink
added a 'yaws -ls' command that lists all yaws servers on localhost
Browse files Browse the repository at this point in the history
git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@692 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information
Claes Wikstrom committed May 26, 2004
1 parent 6dc4cca commit d659ba3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
3 changes: 3 additions & 0 deletions man/yaws.1
Expand Up @@ -96,6 +96,9 @@ HUPing the daemon is the fastest way to see the content updates.
\fB\-s [-I id]\fR
Stop the daemon (called id)
.TP
\fB\-ls \fR
Lists current ids and status of all yaws servers on localhost.
.TP
\fB-S [-I id]\fR
Query a running yaws daemon for its status, and print it.
.TP
Expand Down
2 changes: 2 additions & 0 deletions scripts/yaws.template
Expand Up @@ -113,6 +113,8 @@ do
ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl hup";;
-s)
ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl stop";;
-ls)
ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl ls";;
-S)
ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl status";;
-load)
Expand Down
52 changes: 44 additions & 8 deletions src/yaws_ctl.erl
Expand Up @@ -293,7 +293,7 @@ connect_file(CtlFile) ->
[{active, false},
{reuseaddr, true},
binary,
{packet, 2}]);
{packet, 2}], 2000);
Err ->
Err
end.
Expand Down Expand Up @@ -336,23 +336,59 @@ s_cmd(Fd, SID, Term) ->
Res.


ls() ->
%% List existing yaws nodes on this machine
ls(_) ->
case file:list_dir("/tmp/yaws") of
{ok, List} ->
io:format("~-15s~-10s~-10s~n",
["Id", "Status", "Owner"]),
io:format("-------------------------------------~n",[]),
lists:foreach(
fun(D) ->
ls(D)
lls(D)
end, List);
_ ->
ok
end.

end,
init:stop().


ls(Dir) ->
lls(Dir) ->
Ctl = ctl_file(Dir),
case file:read_file_info(Ctl) of
{ok, FI} ->
ok
case {file:read_file_info(Ctl),
file:read_file_info(filename:join("/tmp/yaws/", Dir))} of
{{ok, FI}, {ok, DI}} ->
User = yaws:uid_to_name(DI#file_info.uid),
Running = case connect(Dir) of
{ok, Sock} ->
gen_tcp:close(Sock),
"running";
{error, timeout} ->
"hanging??";
_ ->
"crashed"
end,
io:format("~-15s~-10s~-10s~n",
[Dir, Running, User]);



{{ok, FI}, {error, _}} ->
%% sick case,
ignore;

{{error, _}, {ok, DI}} ->
%% nicely terminated system
User = yaws:uid_to_name(DI#file_info.uid),
io:format("~-15s~-10s~-10s~n",
[Dir, "stopped", User]);


_Err ->
io:format("~-15s~-10s~-10s~n",
[Dir, "unknown", "unknown"])

end.


Expand Down

0 comments on commit d659ba3

Please sign in to comment.