Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

patch from Fredrik Linder to make it easier to integrate yaws into ap…

…ps that don't use the otp application framework at all

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@709 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
commit 9624397402925d0b669aee3241a3be9632571b06 1 parent 615f723
@klacke authored
View
4 include.mk.in
@@ -2,8 +2,8 @@
PREFIX = @prefix@
-ETCDIR = $(DESTDIR)/etc
-VARDIR = $(DESTDIR)/var
+ETCDIR = $(DESTDIR)@sysconfdir@
+VARDIR = $(DESTDIR)@localstatedir@
INSTALLPREFIX = $(DESTDIR)$(PREFIX)
ERL=@ERL@
View
2  scripts/Install
@@ -12,6 +12,8 @@ y=yaws-${YAWS_VSN}
p=${prefix}
+install -d ${installprefix}/bin
+
cat yaws.template | \
./Subst %yawsdir% ${prefix}/lib/yaws | \
./Subst %erl% "${erl}" | \
View
10 scripts/Makefile
@@ -35,7 +35,7 @@ yaws.conf:
@echo PREFIX is $(PREFIX)
cat yaws.conf.template | \
./Subst %yawsdir% $(PREFIX)/lib/yaws | \
- ./Subst %logdir% /var/log/yaws | \
+ ./Subst %logdir% $(VARDIR)/log/yaws | \
./Subst %host% `hostname` | \
./Subst %port% 80 | \
./Subst %docroot% $(VARDIR)/yaws/www | \
@@ -48,13 +48,13 @@ clean:
install:
-rm -rf /tmp/yaws 2> /dev/null
sh ./Install $(PREFIX) $(INSTALLPREFIX) "$(ERL)" \
- "$(WERL)" /etc/ /var/
+ "$(WERL)" $(ETCDIR)/ $(VARDIR)/
@cp ../ssl/yaws-cert.pem $(ETCDIR)
@cp ../ssl/yaws-key.pem $(ETCDIR)
- @if [ -f $(prefix)/etc/yaws.conf ]; \
+ @if [ -f $(ETCDIR)/yaws.conf ]; \
then echo "Keeping old config file "; \
- cp yaws.conf $(prefix)/etc/yaws.conf.template; \
+ cp yaws.conf $(ETCDIR)/yaws.conf.template; \
else \
echo "Installing $(prefix)/etc/yaws.conf"; \
- cp yaws.conf $(prefix)/etc/yaws.conf; \
+ cp yaws.conf $(ETCDIR)/yaws.conf; \
fi
View
2  src/yaws.erl
@@ -36,7 +36,7 @@ hup(Sock) ->
dohup(Sock) ->
io:format("in dohup~n", []),
{Debug, Trace, TraceOut, Conf, _RunMod, _Embed} =
- yaws_server:get_app_args(),
+ yaws_sup:get_app_args(),
Res = (catch case yaws_config:load(Conf, Trace, TraceOut, Debug) of
{ok, Gconf, Sconfs} ->
yaws_api:setconf(Gconf, Sconfs);
View
2  src/yaws_revproxy.erl
@@ -69,7 +69,7 @@ init(CliSock, ARG, DecPath, QueryPart, {Prefix, URL}, N) ->
CliSock,
0, "404",
0,
- ARG,
+ ARG, no_UT_defined,
fun(A)->(SC#sconf.errormod_404):out404(A,get(gc),get(sc))
end,
fun()->yaws_server:finish_up_dyn_file(CliSock)
View
94 src/yaws_server.erl
@@ -20,7 +20,7 @@
-include_lib("kernel/include/file.hrl").
%% External exports
--export([start_link/0]).
+-export([start_link/1]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2]).
@@ -41,12 +41,13 @@
-record(state, {gc, %% Global conf #gc{} record
pairs, %% [{GservPid, ScList}]
- mnum = 0 %% dyn compiled erl module number
+ mnum = 0, %% dyn compiled erl module number
+ embedded %% true if in embedded mode, false otherwise
}).
-start_link() ->
- gen_server:start_link({local, yaws_server}, yaws_server, [], []).
+start_link(A) ->
+ gen_server:start_link({local, yaws_server}, yaws_server, A, []).
status() ->
gen_server:call(?MODULE, status).
@@ -71,75 +72,6 @@ stats() ->
end, S#state.pairs),
{Diff, R}.
-
-get_app_args() ->
- AS=init:get_arguments(),
- Debug = case application:get_env(yaws, debug) of
- undefined ->
- member({yaws, ["debug"]}, AS);
- {ok, Val} ->
- Val
- end,
- Trace = case application:get_env(yaws, trace) of
- undefined ->
- case {member({yaws, ["trace", "http"]}, AS),
- member({yaws, ["trace", "traffic"]}, AS)} of
- {true, _} ->
- {true, http};
- {_, true} ->
- {true, traffic};
- _ ->
- false
- end;
- {ok, http} ->
- {true, http};
- {ok, traffic} ->
- {true, traffic};
- _ ->
- false
- end,
- TraceOutput = case application:get_env(yaws, traceoutput) of
- undefined ->
- member({yaws, ["tracedebug"]}, AS);
- {ok, Val3} ->
- Val3
- end,
- Conf = case application:get_env(yaws, conf) of
- undefined ->
- find_c(AS);
- {ok, File} ->
- {file, File}
- end,
- RunMod = case application:get_env(yaws, runmod) of
- undefined ->
- find_runmod(AS);
- {ok,Mod} ->
- {ok,Mod}
- end,
- {Debug, Trace, TraceOutput, Conf, RunMod}.
-
-get_app_args_embedded() ->
- case application:get_env(yaws, embedded) of
- undefined ->
- false;
- {ok, Val0} ->
- Val0
- end.
-
-find_c([{conf, [File]} |_]) ->
- {file, File};
-find_c([_|T]) ->
- find_c(T);
-find_c([]) ->
- false.
-
-find_runmod([{runmod, [Mod]} |_]) ->
- {ok,l2a(Mod)};
-find_runmod([_|T]) ->
- find_runmod(T);
-find_runmod([]) ->
- false.
-
l2a(L) when list(L) -> list_to_atom(L);
l2a(A) when atom(A) -> A.
@@ -153,11 +85,10 @@ l2a(A) when atom(A) -> A.
%% {stop, Reason}
%%----------------------------------------------------------------------
-init([]) ->
+init({Debug, Trace, TraceOut, Conf, RunMod, Embedded}) ->
process_flag(trap_exit, true),
put(start_time, calendar:local_time()), %% for uptime
- {Debug, Trace, TraceOut, Conf, RunMod} = get_app_args(),
- case get_app_args_embedded() of
+ case Embedded of
false ->
Config = yaws_config:load(Conf, Trace, TraceOut, Debug),
?Debug("Config= ~p~n", [Config]),
@@ -174,7 +105,7 @@ init([]) ->
_ ->
ok
end,
- init2(Gconf, Sconfs, RunMod, true);
+ init2(Gconf, Sconfs, RunMod, Embedded, true);
{error, E} ->
case erase(logdir) of
undefined ->
@@ -195,7 +126,7 @@ init([]) ->
end.
-init2(GC, Sconfs, RunMod, FirstTime) ->
+init2(GC, Sconfs, RunMod, Embedded, FirstTime) ->
put(gc, GC),
foreach(
fun(D) ->
@@ -209,7 +140,7 @@ init2(GC, Sconfs, RunMod, FirstTime) ->
setup_dirs(GC),
- case get_app_args_embedded() of
+ case Embedded of
false ->
yaws_ctl:start(GC, FirstTime);
true ->
@@ -254,7 +185,8 @@ init2(GC, Sconfs, RunMod, FirstTime) ->
foreach(fun({Pid, _}) -> Pid ! {newuid, GC2#gconf.uid} end, L2),
{ok, #state{gc = GC2,
pairs = L2,
- mnum = 0}}.
+ mnum = 0,
+ embedded = Embedded}}.
@@ -290,7 +222,7 @@ handle_call({setconf, GC, Groups}, _From, State) ->
ok
end
end, Curr),
- case init2(GC, Groups, undef, false) of
+ case init2(GC, Groups, undef, State#state.embedded, false) of
{ok, State2} ->
{reply, ok, State2};
Err ->
View
83 src/yaws_sup.erl
@@ -16,6 +16,9 @@
%% supervisor callbacks
-export([init/1]).
+-export([get_app_args/0]).
+
+-import(lists, [member/2]).
%%%----------------------------------------------------------------------
%%% API
@@ -37,7 +40,85 @@ init([]) ->
YawsLog = {yaws_log, {yaws_log, start_link, []},
permanent, 5000, worker, [yaws_log]},
- YawsServ = {yaws_server, {yaws_server, start_link, []},
+ YawsServArgs = [get_app_args()],
+ YawsServ = {yaws_server, {yaws_server, start_link, YawsServArgs},
permanent, 5000, worker, [yaws_server]},
{ok,{{one_for_all,0,300}, [YawsLog, YawsServ, Sess]}}.
+
+%%----------------------------------------------------------------------
+%%----------------------------------------------------------------------
+get_app_args() ->
+ AS=init:get_arguments(),
+ Debug = case application:get_env(yaws, debug) of
+ undefined ->
+ member({yaws, ["debug"]}, AS);
+ {ok, Val} ->
+ Val
+ end,
+ Trace = case application:get_env(yaws, trace) of
+ undefined ->
+ case {member({yaws, ["trace", "http"]}, AS),
+ member({yaws, ["trace", "traffic"]}, AS)} of
+ {true, _} ->
+ {true, http};
+ {_, true} ->
+ {true, traffic};
+ _ ->
+ false
+ end;
+ {ok, http} ->
+ {true, http};
+ {ok, traffic} ->
+ {true, traffic};
+ _ ->
+ false
+ end,
+ TraceOutput = case application:get_env(yaws, traceoutput) of
+ undefined ->
+ member({yaws, ["tracedebug"]}, AS);
+ {ok, Val3} ->
+ Val3
+ end,
+ Conf = case application:get_env(yaws, conf) of
+ undefined ->
+ find_c(AS);
+ {ok, File} ->
+ {file, File}
+ end,
+ RunMod = case application:get_env(yaws, runmod) of
+ undefined ->
+ find_runmod(AS);
+ {ok,Mod} ->
+ {ok,Mod}
+ end,
+ Embedded = case application:get_env(yaws, embedded) of
+ undefined ->
+ false;
+ {ok, Emb} ->
+ Emb
+ end,
+ {Debug, Trace, TraceOutput, Conf, RunMod, Embedded}.
+
+%%----------------------------------------------------------------------
+%%----------------------------------------------------------------------
+find_c([{conf, [File]} |_]) ->
+ {file, File};
+find_c([_|T]) ->
+ find_c(T);
+find_c([]) ->
+ false.
+
+%%----------------------------------------------------------------------
+%%----------------------------------------------------------------------
+find_runmod([{runmod, [Mod]} |_]) ->
+ {ok,l2a(Mod)};
+find_runmod([_|T]) ->
+ find_runmod(T);
+find_runmod([]) ->
+ false.
+
+%%----------------------------------------------------------------------
+%%----------------------------------------------------------------------
+l2a(L) when list(L) -> list_to_atom(L);
+l2a(A) when atom(A) -> A.
Please sign in to comment.
Something went wrong with that request. Please try again.