Skip to content

Commit

Permalink
Added initial configuration file handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgastako committed May 3, 2009
1 parent 0c72953 commit 40e1762
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 5 deletions.
55 changes: 55 additions & 0 deletions erq.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
% erq config for a production system
% copied from Kestrel for now

% Port to listen on
{port, 2345}.
% Interface address to listen on.
{address, {0,0,0,0}}.

%<log>
% filename = "/var/log/kestrel/kestrel.log"
% roll = "daily"
% level = "info"
%</log>
%
%queue_path = "/var/spool/kestrel"
%
%# when to timeout clients (seconds; 0 = never)
%timeout = 0
%
%# when a queue's journal reaches this size, the queue will wait until it
%# is empty, and will then rotate the journal.
%# (this can also be overridden per queue.)
%max_journal_size = 16277216
%
%# maximum amount of a queue to keep in memory. if a queue grows larger than
%# this (in bytes), it will drop into read-behind mode, with only this amount
%# kept in memory.
%# (this can also be overridden per queue.)
%max_memory_size = 134217728
%
%# optional threshold for a forced journal roll.
%# if a journal grows this many times larger than the desired max journal
%# size, the journal will be forcably re-created.
%# for example, if max_journal_size is 16MB, and max_journal_overflow is 10,
%# then if the journal grows larger than 160MB, it will be forcably re-created.
%max_journal_overflow = 10
%
%# per-queue config
%<queues>
% <weather_updates>
% # throw away any weather update that's been waiting in the queue for 1800
% # seconds (30 mins). if a client uses a shorter expiry, that's honored
% # instead.
% max_age = 1800
%
% # refuse SET operations when the queue would exceed this many items.
% max_items = 1500000
% </weather_updates>
%
% <transient_events>
% # don't keep a journal file for this queue. when kestrel exits, any
% # remaining contents will be lost.
% journal off
% </transient_events>
%</queues>
29 changes: 24 additions & 5 deletions erq.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-module(erq).
-export([start/0, start/1, serve/1]).
-include_lib("erqconf.hrl").

-define(DEFAULT_PORT, 2345).

Expand All @@ -20,16 +21,34 @@ read_fixed_data(Socket, Size) ->
Result.


start() ->
start(?DEFAULT_PORT).
update_config([], Conf) ->
Conf;
update_config(Opts, Conf) ->
[Opt|RemainingOpts] = Opts,
{Name, Value} = Opt,
NewConf = case Name of
address -> Conf#erqconf{address=Value};
port -> Conf#erqconf{port=Value}
end,
update_config(RemainingOpts, NewConf).


read_config(Filename) ->
{ok, Opts} = file:consult(Filename),
update_config(Opts, #erqconf{}).


start() ->
start("erq.conf").

start(Port) ->
{ok, Listen} = gen_tcp:listen(Port, [list,
start(ConfigFilename) ->
Config = read_config(ConfigFilename),
{ok, Listen} = gen_tcp:listen(Config#erqconf.port, [list,
{reuseaddr, true},
{packet, line},
{ip, {127, 0, 0, 1}}
{ip, Config#erqconf.address}
]),
io:format("Listening on ~p:~p", [Config#erqconf.address, Config#erqconf.port]),
spawn(fun() -> erq:serve(Listen) end),
self().

Expand Down
4 changes: 4 additions & 0 deletions erqconf.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-record(erqconf, {
address = {127, 0, 0, 1},
port = 55255
}).

0 comments on commit 40e1762

Please sign in to comment.