Skip to content
Browse files

added a 'yaws -ls' command that lists all yaws servers on localhost

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@692 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
1 parent 6dc4cca commit d659ba325bce6a5132cc390d12e85c0dc2b848f3 @klacke committed
Showing with 49 additions and 8 deletions.
  1. +3 −0 man/yaws.1
  2. +2 −0 scripts/yaws.template
  3. +44 −8 src/yaws_ctl.erl
View
3 man/yaws.1
@@ -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
View
2 scripts/yaws.template
@@ -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)
View
52 src/yaws_ctl.erl
@@ -293,7 +293,7 @@ connect_file(CtlFile) ->
[{active, false},
{reuseaddr, true},
binary,
- {packet, 2}]);
+ {packet, 2}], 2000);
Err ->
Err
end.
@@ -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.

0 comments on commit d659ba3

Please sign in to comment.
Something went wrong with that request. Please try again.