Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 570 lines (489 sloc) 17.427 kb
38fb85e @klacke ""
authored
1 %%%----------------------------------------------------------------------
2 %%% File : yaws_ctl.erl
3 %%% Author : Claes Wikstrom <klacke@bluetail.com>
4 %%% Purpose :
5 %%% Created : 29 Apr 2002 by Claes Wikstrom <klacke@bluetail.com>
6 %%%----------------------------------------------------------------------
7
8
9 %% some code to remoteley control a running yaws server
10
11 -module(yaws_ctl).
12 -author('klacke@bluetail.com').
13
14 -include_lib("kernel/include/file.hrl").
6cf3ece @klacke ""
authored
15 -include("../include/yaws.hrl").
16 -include("../include/yaws_api.hrl").
28e4c73 @klacke first attempt to run properly under cygwin
authored
17 -include("yaws_debug.hrl").
2f51c68 @klacke -check arg
authored
18
9a74e5a @klacke Major general code cleanup, finally got rid of all the export_all sta…
authored
19 -export([start/2, actl_trace/1]).
20 -export([ls/1,hup/1,stop/1,status/1,load/1,
713e35b @klacke --running-config flag to query a running yaws for its config
authored
21 check/1,trace/1, debug_dump/1, stats/1, running_config/1]).
9a74e5a @klacke Major general code cleanup, finally got rid of all the export_all sta…
authored
22 %% internal
aa815f2 @klacke added a set of infinity to several gen_server:calls
authored
23 -export([run/1, aloop/3, handle_a/3]).
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
24
25
26 %% assumes the appropriate file structures
27 %% are already created with the right perms
28
6dc4cca @klacke ""
authored
29 start(_GC, FirstTime) when FirstTime == false ->
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
30 ok;
31 start(GC, true) ->
d07115c @klacke Several cleanups due to dialyzer, also moved the control file into us…
authored
32 proc_lib:start_link(?MODULE, run, [GC]).
28e4c73 @klacke first attempt to run properly under cygwin
authored
33
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
34
35 run(GC) ->
36 %% First check if there is already a Yaws system running
37 %% with the same sid.
38 case connect(GC#gconf.id) of
0be3c7e @klacke untabified all of yaws
authored
39 {ok, Sock, _Key} ->
ddf3bee @klacke preparing for 1.78
authored
40 %% Not good,
0be3c7e @klacke untabified all of yaws
authored
41 gen_tcp:close(Sock),
42 e("There is already a yaws system running with the same ~n"
d07115c @klacke Several cleanups due to dialyzer, also moved the control file into us…
authored
43 " id <~p> on this computer and this user, ~n"
0be3c7e @klacke untabified all of yaws
authored
44 " set another id in the yaws conf file ~n",
45 [GC#gconf.id]);
fb694a0 @klacke eaccess typos in confd_ctl.erl - Sergei Golovan
authored
46 {error, eacces} ->
0be3c7e @klacke untabified all of yaws
authored
47 %% We're not allowed to open the ctl file
d07115c @klacke Several cleanups due to dialyzer, also moved the control file into us…
authored
48 e("Error reading ~s, you don't have access rights to read it",
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
49 [yaws:ctl_file(GC#gconf.id)]);
0be3c7e @klacke untabified all of yaws
authored
50 {error, _} ->
51 %% Fine, this should be the case
52 run_listen(GC)
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
53 end.
54
3c75160 @klacke better crypto on user/id key
authored
55 rand() ->
7871338 @klacke win32 work
authored
56 case os:type() of
57 {win32, _} ->
6e96a14 @klacke indendation cleanup
authored
58 {A1, A2, A3}=now(),
3c75160 @klacke better crypto on user/id key
authored
59 random:seed(A1, A2, A3),
7871338 @klacke win32 work
authored
60 random:uniform(1 bsl 64);
61 _ ->
62 try
63 crypto:start(),
64 crypto:rand_uniform(0, 1 bsl 64)
65 catch
9ab391e @klacke warn when crypto app is not there
authored
66 _:_ ->
67 error_logger:warning_msg("Running without crypto app\n"),
7871338 @klacke win32 work
authored
68 {A1, A2, A3}=now(),
69 random:seed(A1, A2, A3),
70 random:uniform(1 bsl 64)
71 end
3c75160 @klacke better crypto on user/id key
authored
72 end.
73
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
74
7871338 @klacke win32 work
authored
75
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
76 ctl_args() ->
0be3c7e @klacke untabified all of yaws
authored
77 [{packet, 2},
78 {active, false},
79 binary,
80 {ip, {127,0,0,1}},
81 {reuseaddr, true}].
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
82
83 run_listen(GC) ->
84 case gen_tcp:listen(0, ctl_args()) of
0be3c7e @klacke untabified all of yaws
authored
85 {ok, L} ->
86 case inet:sockname(L) of
87 {ok, {_, Port}} ->
3c75160 @klacke better crypto on user/id key
authored
88 Key = rand(),
0be3c7e @klacke untabified all of yaws
authored
89 case w_ctl_file(GC#gconf.id, Port, Key) of
90 ok ->
91 proc_lib:init_ack(ok),
92 aloop(L, GC, Key);
93 error ->
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
94 e(
0be3c7e @klacke untabified all of yaws
authored
95 "Failed to create/manipulate the ctlfile ~n"
96 "called ~s~n"
97 "Either problems with permissions or "
98 " earlier runs of yaws ~nwith the same id "
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
99 " <~p> as this, check dir for perms~n",
100 [yaws:ctl_file(GC#gconf.id), GC#gconf.id])
0be3c7e @klacke untabified all of yaws
authored
101 end;
102 Err ->
103 e("Cannot get sockname for ctlsock: ~p",[Err] )
104 end;
105 Err ->
106 e("Cannot listen on ctl socket, fatal: ~p", [Err])
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
107 end.
108
0c9da97 @klacke added ability to run as different user than root
authored
109
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
110 e(Fmt, Args) ->
111 proc_lib:init_ack({error, io_lib:format(Fmt, Args)}),
112 exit(normal).
113
114
115
116 %% write the control file, set perms of the file
117 %% so that only this user can read the file
118 %% That way we're making sure different users
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
119 %% cannot manipulate each others webservers
f4e3e44 @klacke patch by Sergei Golovan which fixed a CGI bug and made yaws_ctl safe
authored
120 w_ctl_file(Sid, Port, Key) ->
121 case catch
0be3c7e @klacke untabified all of yaws
authored
122 begin
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
123 F = yaws:ctl_file(Sid),
124 error_logger:info_msg("Ctlfile : ~s~n", [F]),
0be3c7e @klacke untabified all of yaws
authored
125 file:write_file(F, io_lib:format("~w.", [{Port,Key}])),
126 {ok, FI} = file:read_file_info(F),
127 ok = file:write_file_info(F, FI#file_info{mode = 8#00600})
128 end of
6e96a14 @klacke indendation cleanup
authored
129 {'EXIT', _} ->
0be3c7e @klacke untabified all of yaws
authored
130 error;
6e96a14 @klacke indendation cleanup
authored
131 _ ->
0be3c7e @klacke untabified all of yaws
authored
132 ok
133 end.
38fb85e @klacke ""
authored
134
135
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
136
f4e3e44 @klacke patch by Sergei Golovan which fixed a CGI bug and made yaws_ctl safe
authored
137 aloop(L, GC, Key) ->
38fb85e @klacke ""
authored
138 case gen_tcp:accept(L) of
0be3c7e @klacke untabified all of yaws
authored
139 {ok, A} ->
aa815f2 @klacke added a set of infinity to several gen_server:calls
authored
140 proc_lib:spawn (?MODULE, handle_a, [A, GC, Key]);
0be3c7e @klacke untabified all of yaws
authored
141 Err ->
142 error_logger:format("yaws_ctl failed to accept: ~p~n",
143 [Err]),
144 timer:sleep(2000),
145 ignore
38fb85e @klacke ""
authored
146 end,
f4e3e44 @klacke patch by Sergei Golovan which fixed a CGI bug and made yaws_ctl safe
authored
147 ?MODULE:aloop(L, GC, Key).
38fb85e @klacke ""
authored
148
f4e3e44 @klacke patch by Sergei Golovan which fixed a CGI bug and made yaws_ctl safe
authored
149 handle_a(A, GC, Key) ->
38fb85e @klacke ""
authored
150 case gen_tcp:recv(A, 0) of
0be3c7e @klacke untabified all of yaws
authored
151 {ok, Data} ->
152 case catch binary_to_term(Data) of
153 {hup, Key} ->
154 Res = yaws:dohup(A),
155 Res;
156 {stop, Key} ->
f3bfae3 preparing for 1.89
Claes Wikstrom authored
157 error_logger:info_msg("Stopping yaws\n",[]),
0be3c7e @klacke untabified all of yaws
authored
158 gen_tcp:send(A, io_lib:format(
159 "stopping yaws with id=~p\n",
160 [GC#gconf.id])),
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
161 file:delete(yaws:ctl_file(GC#gconf.id)),
0be3c7e @klacke untabified all of yaws
authored
162 init:stop();
163 {{trace, What}, Key} ->
164 Res = actl_trace(What),
165 gen_tcp:send(A, Res),
166 gen_tcp:close(A);
167 {status, Key} ->
168 a_status(A),
169 gen_tcp:close(A);
170 {{load, Mods}, Key} ->
171 a_load(A, Mods),
172 gen_tcp:close(A);
173 {id, Key} ->
174 a_id(A),
175 gen_tcp:close(A);
5207102 @klacke Added debug dump functionality
authored
176 {debug_dump, Key} ->
177 a_debug_dump(A),
178 gen_tcp:close(A);
dbaab8b @oliv3 Stats command
oliv3 authored
179 {stats, Key} ->
180 a_stats(A),
181 gen_tcp:close(A);
713e35b @klacke --running-config flag to query a running yaws for its config
authored
182 {running_config, Key} ->
183 a_running_config(A),
184 gen_tcp:close(A);
0be3c7e @klacke untabified all of yaws
authored
185 {Other, Key} ->
186 gen_tcp:send(A, io_lib:format("Other: ~p~n", [Other])),
187 gen_tcp:close(A);
188 _Other ->
189 gen_tcp:close(A)
190
191 end;
192 {error, _} ->
d07115c @klacke Several cleanups due to dialyzer, also moved the control file into us…
authored
193 gen_tcp:close(A)
38fb85e @klacke ""
authored
194 end.
195
6377222 @klacke ""
authored
196
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
197 %% We implement this by reloading a patched config
198 actl_trace(What) ->
199 case lists:member(What, [traffic, http, off]) of
0be3c7e @klacke untabified all of yaws
authored
200 true ->
201 {ok, GC, SCs} = yaws_api:getconf(),
202 case GC#gconf.trace of
203 false when What /= off->
204 yaws_api:setconf(GC#gconf{trace = {true, What}},SCs),
205 io_lib:format(
206 "Turning on trace of ~p to file ~s~n",
207 [What,
208 filename:join([GC#gconf.logdir,
209 "trace." ++ atom_to_list(What)])]);
210 false when What == off ->
211 io_lib:format("Tracing is already turned off ~n",[]);
212 {true, _} when What == off ->
213 yaws_api:setconf(GC#gconf{trace = false},SCs),
214 "Turning trace off \n";
215 {true, What} ->
216 io_lib:format("Trace of ~p is already turned on, ose 'off' "
217 "to turn off~n", [What]);
218 {true, _Other} ->
219 yaws_api:setconf(GC#gconf{trace = {true, What}},SCs),
220 io_lib:format(
221 "Turning on trace of ~p to file ~s~n",
222 [What,
223 filename:join([GC#gconf.logdir,
224 "trace." ++ atom_to_list(What)])])
225 end;
226 false ->
227 "Need either http | traffic | off as argument\n"
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
228 end.
229
230
6377222 @klacke ""
authored
231
232 f(Fmt, As) ->
233 io_lib:format(Fmt, As).
234
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
235
236 a_id(Sock) ->
6ef4f85 @klacke dialyzer reports
authored
237 ID = gen_server:call(yaws_server, id, infinity),
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
238 gen_tcp:send(Sock, ID),
239 ok.
240
6377222 @klacke ""
authored
241 a_status(Sock) ->
5207102 @klacke Added debug dump functionality
authored
242 gen_tcp:send(Sock, a_status()).
243 a_status() ->
244 try
6e96a14 @klacke indendation cleanup
authored
245 {UpTime, L} = yaws_server:stats(),
246 {Days, {Hours, Minutes, _Secs}} = UpTime,
247 H = f("~n Uptime: ~w Days, ~w Hours, ~w Minutes ~n",
248 [Days, Hours, Minutes]),
249
250 T =lists:map(
251 fun({Host,IP,Hits}) ->
252 L1= f("stats for ~p at ~p ~n",
253 [Host,IP]),
254 T = "\n"
255 "URL Number of hits\n",
256 L2=lists:map(
257 fun({Url, Hits2}) ->
258 f("~-30s ~-7w ~n",
259 [Url, Hits2])
260 end, Hits),
261 END = "\n",
262 [L1, T, L2, END]
263 end, L),
5207102 @klacke Added debug dump functionality
authored
264 [H, T]
265 catch
266 _:Err ->
267 io_lib:format("Cannot get status ~p~n", [Err])
268 end.
269
270
271 a_debug_dump(Sock) ->
272 gen_tcp:send(Sock, a_status()),
273 yaws_debug:do_debug_dump(Sock).
274
6377222 @klacke ""
authored
275
dbaab8b @oliv3 Stats command
oliv3 authored
276 -define(IPV4_FMT, "~p.~p.~p.~p").
277 -define(IPV6_FMT, "~2.16.0b~2.16.0b:~2.16.0b~2.16.0b:~2.16.0b~2.16.0b:~2.16.0b~2.16.0b").
278
279 format_ip(IP) ->
280 case size(IP) of
281 4 ->
282 {A, B, C, D} = IP,
283 io_lib:format(?IPV4_FMT,
284 [A, B, C, D]);
285
286 8 ->
287 {A, B, C, D, E, F, G, H} = IP,
288 io_lib:format(?IPV6_FMT,
289 [A, B, C, D, E, F, G, H])
290 end.
291
713e35b @klacke --running-config flag to query a running yaws for its config
authored
292
293 a_running_config(Sock) ->
294 gen_tcp:send(Sock, a_running_config()).
295 a_running_config() ->
296 {ok, GC, Groups} = yaws_server:getconf(),
297 GcStr = ?format_record(GC, gconf),
298 L = lists:map(fun(Group) ->
299 ["** GROUP ** \n",
300 lists:map(
301 fun(SC) ->
302 ?format_record(SC, sconf)
303 end,
304 Group)
305 ]
306 end, Groups),
307 ["** GLOBAL CONF ** \n", GcStr, L].
308
dbaab8b @oliv3 Stats command
oliv3 authored
309 a_stats(Sock) ->
310 gen_tcp:send(Sock, a_stats()).
311 a_stats() ->
312 {ok, _GC, Servers0} = yaws_server:getconf(),
313 Servers1 = lists:flatten(Servers0),
314 %% io:format("~p~n", [Servers1]),
315 Servers2 = parse(Servers1),
316
317 case Servers2 of
318 [] ->
319 f("No statistics available~n", []);
320
321 Servers2 ->
322 Stats = fstats(Servers2),
323 Header = f("Host IP Port Hits Sent~n", []),
324
325 Lines = lists:map(fun({Host, IP0, Port, {Hits, Sent}}) ->
326 %% we don't use inet_parse:ntoa/1
327 %% since it's not documented
328 IP = format_ip(IP0),
329 f("~s ~s ~p ~p ~p~n",
330 [Host, IP, Port, Hits, Sent])
331 end, Stats),
332 [Header, Lines]
333 end.
334
335 parse(V) ->
336 parse(V, []).
337 parse([], Acc) ->
338 Acc;
339 parse([#sconf{stats=undefined}|Tail], Acc) ->
340 parse(Tail, Acc);
341 parse([#sconf{listen=IP, port=Port, servername=Servername, stats=Stats}|Tail], Acc) ->
342 Host = {Servername, IP, Port, Stats},
343 parse(Tail, [Host|Acc]).
344
345 fstats(S) ->
346 fstats(S, []).
347 fstats([], Acc) ->
348 lists:keysort(1, Acc);
349 fstats([{IP, Port, Server, Stats}|Tail], Acc) ->
350 S = {IP, Port, Server, yaws_stats:get(Stats)},
351 fstats(Tail, [S|Acc]).
352
353
caa1a72 @carsten3347 Added command `-load' to yaws script.
carsten3347 authored
354 a_load(A, Mods) ->
355 case purge(Mods) of
0be3c7e @klacke untabified all of yaws
authored
356 ok ->
357 gen_tcp:send(A, f("~p~n", [loadm(Mods)]));
358 Err ->
359 gen_tcp:send(A, f("~p~n", [Err]))
caa1a72 @carsten3347 Added command `-load' to yaws script.
carsten3347 authored
360 end.
361
362 loadm([]) ->
363 [];
364 loadm([M|Ms]) ->
365 [code:load_file(M)|loadm(Ms)].
366
367 purge(Ms) ->
368 case purge(Ms, []) of
0be3c7e @klacke untabified all of yaws
authored
369 [] -> ok;
370 L -> {cannot_purge, L}
caa1a72 @carsten3347 Added command `-load' to yaws script.
carsten3347 authored
371 end.
372
373 purge([], Ack) ->
374 Ack;
375 purge([M|Ms], Ack) ->
376 case code:soft_purge(M) of
0be3c7e @klacke untabified all of yaws
authored
377 true ->
378 purge(Ms, Ack);
379 false ->
380 purge(Ms, [M|Ack])
caa1a72 @carsten3347 Added command `-load' to yaws script.
carsten3347 authored
381 end.
382
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
383 connect(Sid) ->
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
384 connect_file(yaws:ctl_file(Sid)).
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
385
386
387 %% The ctl file contains the port number the yaws server
f4e3e44 @klacke patch by Sergei Golovan which fixed a CGI bug and made yaws_ctl safe
authored
388 %% is listening at and secret key string.
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
389
390 connect_file(CtlFile) ->
f4e3e44 @klacke patch by Sergei Golovan which fixed a CGI bug and made yaws_ctl safe
authored
391 case file:consult(CtlFile) of
0be3c7e @klacke untabified all of yaws
authored
392 {ok, [{Port, Key}]} ->
393 case gen_tcp:connect({127,0,0,1}, Port,
394 [{active, false},
395 {reuseaddr, true},
396 binary,
397 {packet, 2}], 2000) of
398 {ok, Socket} ->
4cf7977 @vinoski When yaws_ctl checks the CTL file to see if any current instance
vinoski authored
399 case inet:port(Socket) of
f73d23d @klacke Fixed dialyzer bugs found by Tuncer, Issue #54
authored
400 {ok,Port} ->
4cf7977 @vinoski When yaws_ctl checks the CTL file to see if any current instance
vinoski authored
401 {error, erefused};
f73d23d @klacke Fixed dialyzer bugs found by Tuncer, Issue #54
authored
402 _X ->
4cf7977 @vinoski When yaws_ctl checks the CTL file to see if any current instance
vinoski authored
403 {ok, Socket, Key}
404 end;
0be3c7e @klacke untabified all of yaws
authored
405 Err ->
406 Err
407 end;
408 Err ->
409 Err
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
410 end.
411
412
413
414 actl(SID, Term) ->
415 case connect(SID) of
fb694a0 @klacke eaccess typos in confd_ctl.erl - Sergei Golovan
authored
416 {error, eacces} ->
0be3c7e @klacke untabified all of yaws
authored
417 io:format("Another user is using the yaws sid <~p>, ~n"
418 "You are not allowd to read the file <~s>, ~n"
419 "specify by <-I id> which yaws system you want "
420 " to control~n",
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
421 [SID, yaws:ctl_file(SID)]),
422 timer:sleep(10),
423 erlang:halt(1);
0be3c7e @klacke untabified all of yaws
authored
424 {error, econnrefused} ->
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
425 io:format("No yaws system responds~n",[]),
426 timer:sleep(10),
427 erlang:halt(2);
0be3c7e @klacke untabified all of yaws
authored
428 {error, Reason} ->
429 io:format("You failed to read the ctlfile ~s~n"
430 "error was: <~p>~n"
431 "specify by <-I id> which yaws system you want "
432 " to control~n",
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
433 [yaws:ctl_file(SID), Reason]),
434 timer:sleep(10),
435 erlang:halt(3);
0be3c7e @klacke untabified all of yaws
authored
436 {ok, Socket, Key} ->
5207102 @klacke Added debug dump functionality
authored
437 gen_tcp:send(Socket, term_to_binary({Term, Key})),
438 Ret = s_cmd(Socket, SID, 0),
439 timer:sleep(40), %% sucks bigtime, we have no good way to flush io
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
440 case Ret of
54139d8 @klacke prepare for 1.81
authored
441 ok when Term == stop ->
442 %% wait for Yaws node to truly stop.
443 case gen_tcp:recv(Socket, 0) of
444 {error, closed} ->
445 erlang:halt(0);
446 Other ->
f3bfae3 preparing for 1.89
Claes Wikstrom authored
447 io:format("Stopping yaws: ~p~n", [Other]),
54139d8 @klacke prepare for 1.81
authored
448 erlang:halt(3)
449 end;
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
450 ok ->
451 erlang:halt(0);
452 error ->
453 erlang:halt(4)
454 end
455 end.
38fb85e @klacke ""
authored
456
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
457
5207102 @klacke Added debug dump functionality
authored
458 s_cmd(Fd, SID, Count) ->
459 case gen_tcp:recv(Fd, 0) of
460 {ok, Bin} ->
461 io:format("~s", [binary_to_list(Bin)]),
462 s_cmd(Fd, SID, Count+1);
463 {error, closed} when Count > 0 ->
464 gen_tcp:close(Fd);
465 Err ->
466 io_lib:format("yaws server for yaws id <~p> not "
467 "responding: ~p ~n", [SID, Err]),
468 error
469 end.
470
3dc56a7 @klacke javascript support in ehtml
authored
471
38fb85e @klacke ""
authored
472
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
473 %% List existing yaws nodes on this machine for this user
d659ba3 @klacke added a 'yaws -ls' command that lists all yaws servers on localhost
authored
474 ls(_) ->
d63642e @vinoski do not pass the --id option if the default id is used
vinoski authored
475 Dir = filename:join([yaws:tmpdir(), "yaws"]),
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
476 case file:list_dir(Dir) of
0be3c7e @klacke untabified all of yaws
authored
477 {ok, List} ->
478 io:format("~-15s~-10s~-10s~n",
479 ["Id", "Status", "Owner"]),
480 io:format("-------------------------------------~n",[]),
481 lists:foreach(
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
482 fun(IdDir) ->
483 lls(IdDir)
0be3c7e @klacke untabified all of yaws
authored
484 end, List);
485 _ ->
486 ok
d659ba3 @klacke added a 'yaws -ls' command that lists all yaws servers on localhost
authored
487 end,
488 init:stop().
6dc4cca @klacke ""
authored
489
490
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
491 lls(IdDir) ->
492 CtlFile = yaws:ctl_file(IdDir),
c9778e0 @klacke added support for 2 additional configure
authored
493 case {file:read_file_info(CtlFile),
0be3c7e @klacke untabified all of yaws
authored
494 file:read_file(CtlFile)} of
495 {{ok, FI}, {error, eacces}} ->
496 User = yaws:uid_to_name(FI#file_info.uid),
497 io:format("~-15s~-10s~-10s~n",
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
498 [IdDir, "noaccess", User]);
0be3c7e @klacke untabified all of yaws
authored
499 {{ok, FI}, {ok, _Bin}} ->
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
500 Running = case connect(IdDir) of
0be3c7e @klacke untabified all of yaws
authored
501 {ok, Sock, _Key} ->
502 gen_tcp:close(Sock),
503 "running";
504 {error, timeout} ->
505 "hanging??";
506 {error, eacces} ->
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
507 "noaccess";
0be3c7e @klacke untabified all of yaws
authored
508 _Err ->
509 "stopped"
510 end,
511 User = yaws:uid_to_name(FI#file_info.uid),
512 io:format("~-15s~-10s~-10s~n",
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
513 [IdDir, Running, User]);
0be3c7e @klacke untabified all of yaws
authored
514 _ ->
515 ok
c105945 @klacke Redid the code which decides where the ctldir resides, now it always …
authored
516 end.
d659ba3 @klacke added a 'yaws -ls' command that lists all yaws servers on localhost
authored
517
0be3c7e @klacke untabified all of yaws
authored
518
6dc4cca @klacke ""
authored
519
38fb85e @klacke ""
authored
520 %% send a hup (kindof) to the yaws server to make it
521 %% reload its configuration and clear its caches
522
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
523 hup([SID]) ->
524 actl(SID, hup).
38fb85e @klacke ""
authored
525
3dc56a7 @klacke javascript support in ehtml
authored
526
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
527 %% stop a daemon
0be3c7e @klacke untabified all of yaws
authored
528 stop([SID]) ->
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
529 actl(SID, stop).
38fb85e @klacke ""
authored
530
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
531 %% query a daemon for status/stats
532 status([SID]) ->
533 actl(SID, status).
534
535 load(X) ->
536 [SID | Modules] = lists:reverse(X),
537 actl(SID, {load, Modules}).
caa1a72 @carsten3347 Added command `-load' to yaws script.
carsten3347 authored
538
6c84378 @klacke ""
authored
539 check([Id, File| IncludeDirs]) ->
92bafb4 @klacke removed the ability change userid, also stopped writing to /tmp/yaws …
authored
540 GC = yaws_config:make_default_gconf(false, undefined),
2f51c68 @klacke -check arg
authored
541 GC2 = GC#gconf{include_dir = lists:map(fun(X) -> atom_to_list(X) end,
0be3c7e @klacke untabified all of yaws
authored
542 IncludeDirs),
543 id = atom_to_list(Id)
544 },
745bb4a @klacke ""
authored
545 yaws_server:setup_dirs(GC2),
9ce9a25 @klacke ""
authored
546 put(sc, #sconf{}),
547 put(gc, GC2),
a7e93df @klacke patch from Magnus froberg to get better control over the files genera…
authored
548 put(use_yfile_name, true),
ef3a52a @klacke Removed the atoms in parse_post and parse query, backwards incompatib…
authored
549 case yaws_compile:compile_file(atom_to_list(File)) of
0be3c7e @klacke untabified all of yaws
authored
550 {ok, [{errors, 0}| _Spec]} ->
551 timer:sleep(100),erlang:halt(0);
552 % init:stop();
553 _Other ->
554 timer:sleep(100),erlang:halt(1)
555 % init:stop()
2f51c68 @klacke -check arg
authored
556 end.
557
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
558 %% control a daemon http/traffic tracer
559 trace([What, SID]) ->
560 actl(SID, {trace, What}).
561
5207102 @klacke Added debug dump functionality
authored
562 debug_dump([SID]) ->
563 actl(SID, debug_dump).
564
dbaab8b @oliv3 Stats command
oliv3 authored
565 stats([SID]) ->
566 actl(SID, stats).
713e35b @klacke --running-config flag to query a running yaws for its config
authored
567 running_config([SID]) ->
568 actl(SID, running_config).
6e96a14 @klacke indendation cleanup
authored
569
Something went wrong with that request. Please try again.