Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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