From a67888aae70064de7f3ec8f9ede640f2ffa1f9c8 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Thu, 3 Jul 2008 13:46:09 +0100 Subject: Migrate branch bug17070 --- codegen.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/codegen.py b/codegen.py index 242c2418..1cad996a 100644 --- a/codegen.py +++ b/codegen.py @@ -271,6 +271,14 @@ def genHrl(spec): def fieldNameList(fields): return ', '.join([erlangize(f.name) for f in fields]) + + def fieldNameListDefaults(fields): + def fillField(field): + result = erlangize(f.name) + if field.defaultvalue != None: + result += ' = ' + field.defaultvalue + return result + return ', '.join([fillField(f) for f in fields]) methods = spec.allMethods() @@ -283,23 +291,18 @@ def genHrl(spec): print "%% Method field records." for m in methods: - print "-record(%s, {%s})." % (m.erlangName(), fieldNameList(m.arguments)) + print "-record(%s, {%s})." % (m.erlangName(), fieldNameListDefaults(m.arguments)) print "%% Class property records." for c in spec.allClasses(): print "-record('P_%s', {%s})." % (erlangize(c.name), fieldNameList(c.fields)) -#--------------------------------------------------------------------------- - def generateErl(specPath): genErl(AmqpSpec(specPath)) def generateHrl(specPath): genHrl(AmqpSpec(specPath)) - + if __name__ == "__main__": do_main(generateHrl, generateErl) - - - -- cgit v1.2.1 From d0700a23d3ce0b787c0e5333e6f39e99ec663fc8 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Thu, 3 Jul 2008 13:59:36 +0100 Subject: Migrate branch bug18784 --- src/rabbit_reader.erl | 3 +++ src/rabbit_writer.erl | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index 1d11cbaa..bfd1ea72 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -59,6 +59,7 @@ %% all states, unless specified otherwise: %% socket error -> *exit* %% socket close -> *throw* +%% writer send failure -> *throw* %% forced termination -> *exit* %% handshake_timeout -> *throw* %% pre-init: @@ -230,6 +231,8 @@ mainloop(Parent, Deb, State = #v1{sock= Sock, recv_ref = Ref}) -> %% since this termination is initiated by our parent it is %% probably more important to exit quickly. exit(Reason); + {'EXIT', _Pid, E = {writer, send_failed, _Error}} -> + throw(E); {'EXIT', Pid, Reason} -> mainloop(Parent, Deb, handle_dependent_exit(Pid, Reason, State)); {terminate_channel, Channel, Ref1} -> diff --git a/src/rabbit_writer.erl b/src/rabbit_writer.erl index eda871ec..0f6bca91 100644 --- a/src/rabbit_writer.erl +++ b/src/rabbit_writer.erl @@ -153,10 +153,15 @@ internal_send_command(Sock, Channel, MethodRecord, Content, FrameMax) -> %% when these are full. So the fact that we process the result %% asynchronously does not impact flow control. internal_send_command_async(Sock, Channel, MethodRecord) -> - true = erlang:port_command(Sock, assemble_frames(Channel, MethodRecord)), + true = port_cmd(Sock, assemble_frames(Channel, MethodRecord)), ok. internal_send_command_async(Sock, Channel, MethodRecord, Content, FrameMax) -> - true = erlang:port_command(Sock, assemble_frames(Channel, MethodRecord, - Content, FrameMax)), + true = port_cmd(Sock, assemble_frames(Channel, MethodRecord, + Content, FrameMax)), ok. + +port_cmd(Sock, Data) -> + try erlang:port_command(Sock, Data) + catch error:Error -> exit({writer, send_failed, Error}) + end. -- cgit v1.2.1 From 4dcea129a99d7523a3173358833818a32f0061b3 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Sun, 6 Jul 2008 00:39:50 +0100 Subject: Migrated branch bug18752 --- include/rabbit.hrl | 4 +- src/rabbit_misc.erl | 2 +- src/rabbit_mnesia.erl | 4 ++ src/rabbit_realm.erl | 137 ++++++++++++++++++++++---------------------------- src/rabbit_ticket.erl | 34 ++++++------- 5 files changed, 85 insertions(+), 96 deletions(-) diff --git a/include/rabbit.hrl b/include/rabbit.hrl index d8af670a..5a3006dd 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -29,7 +29,9 @@ -record(vhost, {virtual_host, dummy}). -record(vhost_realm, {virtual_host, realm}). --record(realm, {name, exchanges, queues}). +-record(realm, {name,ignore}). +-record(realm_resource, {realm, resource}). + -record(user_realm, {username, realm, ticket_pattern}). -record(realm_visitor, {realm, pid}). diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 927d7712..08e15817 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -284,7 +284,7 @@ execute_mnesia_transaction(TxFun) -> %% Making this a sync_transaction allows us to use dirty_read %% elsewhere and get a consistent result even when that read %% executes on a different node. - case mnesia:sync_transaction(TxFun) of + case mnesia:transaction(TxFun) of {atomic, Result} -> Result; {aborted, Reason} -> throw({error, Reason}) end. diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl index 82b80cb4..f18f3d50 100644 --- a/src/rabbit_mnesia.erl +++ b/src/rabbit_mnesia.erl @@ -108,6 +108,10 @@ table_definitions() -> {index, [realm]}]}, {realm, [{disc_copies, [node()]}, {attributes, record_info(fields, realm)}]}, + {realm_exchange, [{disc_copies, [node()]}, + {attributes, record_info(fields, realm_resource)}]}, + {realm_queue, [{disc_copies, [node()]}, + {attributes, record_info(fields, realm_resource)}]}, {user_realm, [{type, bag}, {disc_copies, [node()]}, {attributes, record_info(fields, user_realm)}, diff --git a/src/rabbit_realm.erl b/src/rabbit_realm.erl index 4463954d..959ab546 100644 --- a/src/rabbit_realm.erl +++ b/src/rabbit_realm.erl @@ -63,12 +63,7 @@ recover() -> %% preens resource lists, limiting them to currently-extant resources - rabbit_misc:execute_mnesia_transaction( - fun () -> - Realms = mnesia:foldl(fun preen_realm/2, [], realm), - lists:foreach(fun mnesia:write/1, Realms), - ok - end). + rabbit_misc:execute_mnesia_transaction(fun preen_realms/0). add_realm(Name = #resource{virtual_host = VHostPath, kind = realm}) -> rabbit_misc:execute_mnesia_transaction( @@ -77,9 +72,7 @@ add_realm(Name = #resource{virtual_host = VHostPath, kind = realm}) -> fun () -> case mnesia:read({realm, Name}) of [] -> - NewRealm = #realm{name = Name, - exchanges = ordsets:new(), - queues = ordsets:new()}, + NewRealm = #realm{name = Name}, ok = mnesia:write(NewRealm), ok = mnesia:write( #vhost_realm{virtual_host = VHostPath, @@ -116,45 +109,46 @@ list_vhost_realms(VHostPath) -> VHostPath, fun () -> mnesia:read({vhost_realm, VHostPath}) end))]. -add(Name = #resource{kind = realm}, Resource) -> - internal_update_realm_byname(Name, Resource, fun ordsets:add_element/2). +add(Name = #resource{kind = realm}, R = #resource{name = Resource}) -> + manage_link(link,realm_table_for_resource(R),Name,Resource). + +delete(Name = #resource{kind = realm}, R = #resource{name = Resource}) -> + manage_link(unlink,realm_table_for_resource(R),Name,Resource). + +% This links or unlinks a resource to a realm +manage_link(Action,LinkTable,Realm,Resource) -> + rabbit_misc:execute_mnesia_transaction( + fun () -> + case mnesia:read({realm, Realm}) of + [] -> + mnesia:abort(not_found); + [_] -> + case Action of + link -> mnesia:write({LinkTable,Realm,Resource}); + unlink -> mnesia:delete_object({LinkTable,Realm,Resource}) + end + end + end). + +realm_table_for_resource(#resource{kind = exchange}) -> realm_exchange; +realm_table_for_resource(#resource{kind = queue}) -> realm_queue. +parent_table_for_resource(#resource{kind = exchange}) -> exchange; +parent_table_for_resource(#resource{kind = queue}) -> amqqueue. -delete(Name = #resource{kind = realm}, Resource) -> - internal_update_realm_byname(Name, Resource, fun ordsets:del_element/2). -check(Name = #resource{kind = realm}, Resource = #resource{kind = Kind}) -> - case rabbit_misc:dirty_read({realm, Name}) of - {ok, R} -> - case Kind of - exchange -> ordsets:is_element(Resource, R#realm.exchanges); - queue -> ordsets:is_element(Resource, R#realm.queues) - end; - Other -> Other +check(#resource{kind = realm, name = Realm}, Resource = #resource{}) -> + F = qlc:e(qlc:q([R || R <- mnesia:table(realm_table_for_resource(Resource)), + R#realm_resource.realm == Realm, + R#realm_resource.resource == Resource#resource.name])), + case mnesia:async_dirty(F) of + {atomic,[]} -> false; + {atomic,_} -> true; + _ -> false end. % Requires a mnesia transaction. -delete_from_all(Resource = #resource{kind = Kind}) -> - Realms = mnesia:foldl - (fun (Realm = #realm{exchanges = E0, - queues = Q0}, - Acc) -> - IsMember = lists:member(Resource, - case Kind of - exchange -> E0; - queue -> Q0 - end), - if - IsMember -> - [internal_update_realm_record( - Realm, Resource, - fun ordsets:del_element/2) - | Acc]; - true -> - Acc - end - end, [], realm), - lists:foreach(fun mnesia:write/1, Realms), - ok. +delete_from_all(Resource = #resource{name = Name}) -> + mnesia:delete_object({realm_table_for_resource(Resource),'_',Name}). access_request(Username, Exclusive, Ticket = #ticket{realm_name = RealmName}) when is_binary(Username) -> @@ -237,41 +231,30 @@ on_node_down(Node) -> %%-------------------------------------------------------------------- -preen_realm(Realm = #realm{name = #resource{kind = realm}, - exchanges = E0, - queues = Q0}, - Realms) -> - [Realm#realm{exchanges = filter_out_missing(E0, exchange), - queues = filter_out_missing(Q0, amqqueue)} - | Realms]. - -filter_out_missing(Items, TableName) -> - ordsets:filter(fun (Item) -> - case mnesia:read({TableName, Item}) of - [] -> false; - _ -> true - end - end, Items). - -internal_update_realm_byname(Name, Resource, SetUpdater) -> - rabbit_misc:execute_mnesia_transaction( - fun () -> - case mnesia:read({realm, Name}) of - [] -> - mnesia:abort(not_found); - [R] -> - ok = mnesia:write(internal_update_realm_record - (R, Resource, SetUpdater)) - end - end). +%% This iterates through the realm_exchange and realm_queue link tables +%% and deletes rows that have no underlying exchange or queue record. +preen_realms() -> + Resources = [#resource{kind = exchange},#resource{kind = queue}], + [preen_realm(Resource) || Resource <- Resources ], + ok. +preen_realm(Resource = #resource{}) -> + LinkType = realm_table_for_resource(Resource), + Q = qlc:q([L#realm_resource.resource || L <- mnesia:table(LinkType)]), + Cursor = qlc:cursor(Q), + preen_next(Cursor,LinkType,parent_table_for_resource(Resource)), + qlc:delete_cursor(Cursor). -internal_update_realm_record(R = #realm{exchanges = E0, queues = Q0}, - Resource = #resource{kind = Kind}, - SetUpdater) -> - case Kind of - exchange -> R#realm{exchanges = SetUpdater(Resource, E0)}; - queue -> R#realm{queues = SetUpdater(Resource, Q0)} - end. +preen_next(Cursor,LinkType,ParentTable) -> + case qlc:next_answers(Cursor,1) of + [] -> ok; + [ResourceKey] -> + case mnesia:read({ParentTable,ResourceKey}) of + [] -> + mnesia:delete_object({LinkType,'_',ResourceKey}); + _ -> ok + end, + preen_next(Cursor,LinkType,ParentTable) + end. check_and_lookup(RealmName = #resource{kind = realm, name = <<"/data", _/binary>>}) -> diff --git a/src/rabbit_ticket.erl b/src/rabbit_ticket.erl index 3a608faa..24c5a0af 100644 --- a/src/rabbit_ticket.erl +++ b/src/rabbit_ticket.erl @@ -97,23 +97,23 @@ maybe_relax_checks(TicketNumber, Username, VHostPath) -> check_ticket(TicketNumber, FieldIndex, Name = #resource{virtual_host = VHostPath}, Username) -> #ticket{realm_name = RealmName} = - lookup_ticket(TicketNumber, FieldIndex, Username, VHostPath), - case resource_in_realm(RealmName, Name) of - false -> - case rabbit_misc:strict_ticket_checking() of - true -> - rabbit_misc:protocol_error( - access_refused, - "insufficient permissions in ticket ~w to access ~s in ~s", - [TicketNumber, rabbit_misc:rs(Name), - rabbit_misc:rs(RealmName)]); - false -> - rabbit_log:warning("Lax ticket check mode: ignoring cross-realm access for ticket ~p~n", [TicketNumber]), - ok - end; - true -> - ok - end. + lookup_ticket(TicketNumber, FieldIndex, Username, VHostPath). + % case resource_in_realm(RealmName, Name) of + % false -> + % case rabbit_misc:strict_ticket_checking() of + % true -> + % rabbit_misc:protocol_error( + % access_refused, + % "insufficient permissions in ticket ~w to access ~s in ~s", + % [TicketNumber, rabbit_misc:rs(Name), + % rabbit_misc:rs(RealmName)]); + % false -> + % rabbit_log:warning("Lax ticket check mode: ignoring cross-realm access for ticket ~p~n", [TicketNumber]), + % ok + % end; + % true -> + % ok + % end. resource_in_realm(RealmName, ResourceName = #resource{kind = Kind}) -> CacheKey = {resource_cache, RealmName, Kind}, -- cgit v1.2.1 From ccdf9a6065af6fb7523b25b694ea8e62c27a776f Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Sun, 6 Jul 2008 18:30:05 +0100 Subject: Fixed some of the QA notes --- src/rabbit_realm.erl | 19 +++++++++---------- src/rabbit_ticket.erl | 34 +++++++++++++++++----------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/rabbit_realm.erl b/src/rabbit_realm.erl index 959ab546..46071ed5 100644 --- a/src/rabbit_realm.erl +++ b/src/rabbit_realm.erl @@ -110,23 +110,24 @@ list_vhost_realms(VHostPath) -> fun () -> mnesia:read({vhost_realm, VHostPath}) end))]. add(Name = #resource{kind = realm}, R = #resource{name = Resource}) -> - manage_link(link,realm_table_for_resource(R),Name,Resource). + Table = realm_table_for_resource(R), + Fun = fun() -> mnesia:write({Table,Name,Resource}) end, + manage_link(Fun,Name). delete(Name = #resource{kind = realm}, R = #resource{name = Resource}) -> - manage_link(unlink,realm_table_for_resource(R),Name,Resource). + Table = realm_table_for_resource(R), + Fun = fun() -> mnesia:delete_object({Table,Name,Resource}) end, + manage_link(Fun,Name). % This links or unlinks a resource to a realm -manage_link(Action,LinkTable,Realm,Resource) -> +manage_link(Action, Realm) -> rabbit_misc:execute_mnesia_transaction( fun () -> case mnesia:read({realm, Realm}) of [] -> mnesia:abort(not_found); [_] -> - case Action of - link -> mnesia:write({LinkTable,Realm,Resource}); - unlink -> mnesia:delete_object({LinkTable,Realm,Resource}) - end + apply(Action,[]) end end). @@ -137,9 +138,7 @@ parent_table_for_resource(#resource{kind = queue}) -> amqqueue. check(#resource{kind = realm, name = Realm}, Resource = #resource{}) -> - F = qlc:e(qlc:q([R || R <- mnesia:table(realm_table_for_resource(Resource)), - R#realm_resource.realm == Realm, - R#realm_resource.resource == Resource#resource.name])), + F = mnesia:match_object(#realm_resource{resource = Resource#resource.name, realm = Realm}), case mnesia:async_dirty(F) of {atomic,[]} -> false; {atomic,_} -> true; diff --git a/src/rabbit_ticket.erl b/src/rabbit_ticket.erl index 24c5a0af..16475a98 100644 --- a/src/rabbit_ticket.erl +++ b/src/rabbit_ticket.erl @@ -97,23 +97,23 @@ maybe_relax_checks(TicketNumber, Username, VHostPath) -> check_ticket(TicketNumber, FieldIndex, Name = #resource{virtual_host = VHostPath}, Username) -> #ticket{realm_name = RealmName} = - lookup_ticket(TicketNumber, FieldIndex, Username, VHostPath). - % case resource_in_realm(RealmName, Name) of - % false -> - % case rabbit_misc:strict_ticket_checking() of - % true -> - % rabbit_misc:protocol_error( - % access_refused, - % "insufficient permissions in ticket ~w to access ~s in ~s", - % [TicketNumber, rabbit_misc:rs(Name), - % rabbit_misc:rs(RealmName)]); - % false -> - % rabbit_log:warning("Lax ticket check mode: ignoring cross-realm access for ticket ~p~n", [TicketNumber]), - % ok - % end; - % true -> - % ok - % end. + lookup_ticket(TicketNumber, FieldIndex, Username, VHostPath), + case resource_in_realm(RealmName, Name) of + false -> + case rabbit_misc:strict_ticket_checking() of + true -> + rabbit_misc:protocol_error( + access_refused, + "insufficient permissions in ticket ~w to access ~s in ~s", + [TicketNumber, rabbit_misc:rs(Name), + rabbit_misc:rs(RealmName)]); + false -> + rabbit_log:warning("Lax ticket check mode: ignoring cross-realm access for ticket ~p~n", [TicketNumber]), + ok + end; + true -> + ok + end. resource_in_realm(RealmName, ResourceName = #resource{kind = Kind}) -> CacheKey = {resource_cache, RealmName, Kind}, -- cgit v1.2.1 From b985a1832ba273eb7589bac5a3c44da130067d43 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Sun, 6 Jul 2008 22:12:38 +0100 Subject: Tightened up the code in rabbit_realm a little bit --- src/rabbit_realm.erl | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/rabbit_realm.erl b/src/rabbit_realm.erl index 46071ed5..2ededb5f 100644 --- a/src/rabbit_realm.erl +++ b/src/rabbit_realm.erl @@ -109,25 +109,21 @@ list_vhost_realms(VHostPath) -> VHostPath, fun () -> mnesia:read({vhost_realm, VHostPath}) end))]. -add(Name = #resource{kind = realm}, R = #resource{name = Resource}) -> - Table = realm_table_for_resource(R), - Fun = fun() -> mnesia:write({Table,Name,Resource}) end, - manage_link(Fun,Name). +add(Realm = #resource{kind = realm}, Resource = #resource{}) -> + manage_link(fun mnesia:write/1, Realm, Resource). -delete(Name = #resource{kind = realm}, R = #resource{name = Resource}) -> - Table = realm_table_for_resource(R), - Fun = fun() -> mnesia:delete_object({Table,Name,Resource}) end, - manage_link(Fun,Name). +delete(Realm = #resource{kind = realm}, Resource = #resource{}) -> + manage_link(fun mnesia:delete_object/1, Realm, Resource). % This links or unlinks a resource to a realm -manage_link(Action, Realm) -> +manage_link(Action, Realm = #resource{kind = realm, name = RealmName}, + Resource = #resource{name = ResourceName}) -> + Table = realm_table_for_resource(Resource), rabbit_misc:execute_mnesia_transaction( fun () -> case mnesia:read({realm, Realm}) of - [] -> - mnesia:abort(not_found); - [_] -> - apply(Action,[]) + [] -> mnesia:abort(not_found); + [_] -> Action({Table, RealmName, ResourceName}) end end). -- cgit v1.2.1 From f07b581df9e25cc5ba1960286a646efcb0461bad Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 8 Jul 2008 12:12:42 +0100 Subject: Avoid copying the codegen directory's .hg dir when building a source dist. --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 680003cf..a32a89ea 100644 --- a/Makefile +++ b/Makefile @@ -118,7 +118,8 @@ generic_stage: srcdist: distclean $(MAKE) VERSION=$(VERSION) GENERIC_STAGE_DIR=dist/$(TARBALL_NAME) generic_stage - cp -r $(AMQP_CODEGEN_DIR) dist/$(TARBALL_NAME)/codegen + mkdir -p dist/$(TARBALL_NAME)/codegen + cp -r $(AMQP_CODEGEN_DIR)/* dist/$(TARBALL_NAME)/codegen/. cp codegen.py Makefile dist/$(TARBALL_NAME) cp -r scripts dist/$(TARBALL_NAME) -- cgit v1.2.1 From 25a636b431c74fd2c60afcdd1bb7090f5ad14d0a Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 8 Jul 2008 12:13:14 +0100 Subject: Migrate .hgignore entries from umbrella. --- .hgignore | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .hgignore diff --git a/.hgignore b/.hgignore new file mode 100644 index 00000000..d23b4225 --- /dev/null +++ b/.hgignore @@ -0,0 +1,11 @@ +^cover/ +^dist/ +^include/rabbit_framing.hrl$ +^src/rabbit_framing.erl$ +^rabbit.plt$ + +^packaging/RPMS/Fedora/(BUILD|RPMS|SOURCES|SPECS|SRPMS)$ +^packaging/debs/Debian/rabbitmq-server_.*\.(dsc|tar\.gz|deb|changes)$ +^packaging/debs/apt-repository/debian$ +^packaging/generic-unix/rabbitmq-server-generic-unix-.*\.tar\.gz$ +^packaging/windows/rabbitmq-server-windows-.*\.zip$ -- cgit v1.2.1 From bb63114ae61e50aec7ce8f888ad5b2b673016b9d Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 8 Jul 2008 12:16:59 +0100 Subject: More .hgignore entries from umbrella --- .hgignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.hgignore b/.hgignore index d23b4225..0781e32f 100644 --- a/.hgignore +++ b/.hgignore @@ -1,3 +1,9 @@ +syntax: glob +*.beam +*~ +erl_crash.dump + +syntax: regexp ^cover/ ^dist/ ^include/rabbit_framing.hrl$ -- cgit v1.2.1 From 0cf76f887a34afa6ec9f04a33fb254fea580b6b5 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Wed, 9 Jul 2008 14:39:07 +0100 Subject: New changelog entries for 1.4.0 --- packaging/RPMS/Fedora/rabbitmq-server.spec | 3 +++ packaging/debs/Debian/debian/changelog | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec index 4f3dafaa..ca0b6b8e 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.spec +++ b/packaging/RPMS/Fedora/rabbitmq-server.spec @@ -119,6 +119,9 @@ fi rm -rf $RPM_BUILD_ROOT %changelog +* Wed Jul 9 2008 Tony Garnock-Jones 1.4.0 +- New upstream release + * Mon Mar 3 2008 Adrien Pierard 1.3.0 - New upstream release diff --git a/packaging/debs/Debian/debian/changelog b/packaging/debs/Debian/debian/changelog index 08b760e9..e6b12937 100644 --- a/packaging/debs/Debian/debian/changelog +++ b/packaging/debs/Debian/debian/changelog @@ -1,3 +1,9 @@ +rabbitmq-server (1.4.0-1) testing; urgency=low + + * New Upstream Release + + -- Tony Garnock-Jones Wed, 09 Jul 2008 14:31:23 +0100 + rabbitmq-server (1.3.0-1) testing; urgency=low * New Upstream Release -- cgit v1.2.1 From ac559c126eef34dda5d209b0f88ee7b906fe7e39 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Fri, 11 Jul 2008 16:22:59 +0100 Subject: Rolling back misunderstanding about how preening works --- include/rabbit.hrl | 2 +- src/rabbit_amqqueue.erl | 2 +- src/rabbit_exchange.erl | 2 +- src/rabbit_realm.erl | 26 +++++++++++--------------- src/rabbit_tests.erl | 23 ++++++++++++++++++++++- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/include/rabbit.hrl b/include/rabbit.hrl index 5a3006dd..c7415f45 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -30,7 +30,7 @@ -record(vhost_realm, {virtual_host, realm}). -record(realm, {name,ignore}). --record(realm_resource, {realm, resource}). +-record(realm_resource, {realm, resource, durable}). -record(user_realm, {username, realm, ticket_pattern}). diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 63f043ba..59c41fb8 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -142,7 +142,7 @@ declare(RealmName, NameBin, Durable, AutoDelete, Args) -> fun () -> case mnesia:wread({amqqueue, QName}) of [] -> ok = recover_queue(Q), - ok = rabbit_realm:add(RealmName, QName), + ok = rabbit_realm:add(RealmName, QName, Durable), Q; [ExistingQ] -> ExistingQ end diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 113b7878..32418ca2 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -106,7 +106,7 @@ declare(RealmName, NameBin, Type, Durable, AutoDelete, Args) -> durable_exchanges, Exchange, write); true -> ok end, - ok = rabbit_realm:add(RealmName, XName), + ok = rabbit_realm:add(RealmName, XName, Durable), Exchange; [ExistingX] -> ExistingX end diff --git a/src/rabbit_realm.erl b/src/rabbit_realm.erl index 2ededb5f..2887158b 100644 --- a/src/rabbit_realm.erl +++ b/src/rabbit_realm.erl @@ -27,7 +27,7 @@ -export([recover/0]). -export([add_realm/1, delete_realm/1, list_vhost_realms/1]). --export([add/2, delete/2, check/2, delete_from_all/1]). +-export([add/3, check/2, delete_from_all/1]). -export([access_request/3, enter_realm/3, leave_realms/1]). -export([on_node_down/1]). @@ -44,8 +44,8 @@ -spec(add_realm/1 :: (realm_name()) -> 'ok'). -spec(delete_realm/1 :: (realm_name()) -> 'ok'). -spec(list_vhost_realms/1 :: (vhost()) -> [name()]). --spec(add/2 :: (realm_name(), r(e_or_q())) -> 'ok'). --spec(delete/2 :: (realm_name(), r(e_or_q())) -> 'ok'). +% -spec(add/3 :: (realm_name(), r(e_or_q())) -> 'ok'). +% -spec(delete/3 :: (realm_name(), r(e_or_q())) -> 'ok'). -spec(check/2 :: (realm_name(), r(e_or_q())) -> bool() | not_found()). -spec(delete_from_all/1 :: (r(e_or_q())) -> 'ok'). -spec(access_request/3 :: (username(), bool(), ticket()) -> @@ -109,21 +109,18 @@ list_vhost_realms(VHostPath) -> VHostPath, fun () -> mnesia:read({vhost_realm, VHostPath}) end))]. -add(Realm = #resource{kind = realm}, Resource = #resource{}) -> - manage_link(fun mnesia:write/1, Realm, Resource). - -delete(Realm = #resource{kind = realm}, Resource = #resource{}) -> - manage_link(fun mnesia:delete_object/1, Realm, Resource). +add(Realm = #resource{kind = realm}, Resource = #resource{}, Durable) -> + manage_link(fun mnesia:write/1, Realm, Resource, Durable). % This links or unlinks a resource to a realm manage_link(Action, Realm = #resource{kind = realm, name = RealmName}, - Resource = #resource{name = ResourceName}) -> + Resource = #resource{name = ResourceName}, Durable) -> Table = realm_table_for_resource(Resource), rabbit_misc:execute_mnesia_transaction( fun () -> case mnesia:read({realm, Realm}) of [] -> mnesia:abort(not_found); - [_] -> Action({Table, RealmName, ResourceName}) + [_] -> Action({Table, RealmName, ResourceName, Durable}) end end). @@ -132,7 +129,6 @@ realm_table_for_resource(#resource{kind = queue}) -> realm_queue. parent_table_for_resource(#resource{kind = exchange}) -> exchange; parent_table_for_resource(#resource{kind = queue}) -> amqqueue. - check(#resource{kind = realm, name = Realm}, Resource = #resource{}) -> F = mnesia:match_object(#realm_resource{resource = Resource#resource.name, realm = Realm}), case mnesia:async_dirty(F) of @@ -236,14 +232,14 @@ preen_realm(Resource = #resource{}) -> LinkType = realm_table_for_resource(Resource), Q = qlc:q([L#realm_resource.resource || L <- mnesia:table(LinkType)]), Cursor = qlc:cursor(Q), - preen_next(Cursor,LinkType,parent_table_for_resource(Resource)), + preen_next(Cursor, LinkType, parent_table_for_resource(Resource)), qlc:delete_cursor(Cursor). - -preen_next(Cursor,LinkType,ParentTable) -> + +preen_next(Cursor, LinkType, ParentTable) -> case qlc:next_answers(Cursor,1) of [] -> ok; [ResourceKey] -> - case mnesia:read({ParentTable,ResourceKey}) of + case mnesia:match_object({ParentTable,ResourceKey,'_'}) of [] -> mnesia:delete_object({LinkType,'_',ResourceKey}); _ -> ok diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index beeb3508..5c265633 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -25,7 +25,9 @@ -module(rabbit_tests). --export([all_tests/0, test_parsing/0]). +-include("rabbit.hrl"). + +-export([all_tests/0, test_parsing/0,preening_test/0]). -import(lists). @@ -46,6 +48,25 @@ all_tests() -> test_parsing() -> passed = test_content_properties(), passed. + +preening_test() -> + Realm = #resource{virtual_host = <<"/">>,kind = realm, name = <<"/data">>}, + loop(Realm,1), + rabbit_realm:recover(). + +loop(_,0) -> ok; +loop(Realm,N) -> + declare(Realm,true), + declare(Realm,false), + loop(Realm,N-1). + +declare(Realm,Durable) -> + X = rabbit_misc:binstring_guid("x"), + Q = rabbit_misc:binstring_guid("amq.gen"), + AutoDelete = false, + rabbit_exchange:declare(Realm,X, <<"direct">>, Durable, AutoDelete, undefined), + rabbit_amqqueue:declare(Realm, Q, Durable, AutoDelete, undefined). + test_content_properties() -> test_content_prop_roundtrip([], <<0, 0>>), -- cgit v1.2.1 From c3a84592c8547eb306fca94c363c308e49d0c98d Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 11 Jul 2008 16:38:19 +0100 Subject: Backed out changeset a764527adf12 --- include/rabbit.hrl | 2 +- src/rabbit_amqqueue.erl | 2 +- src/rabbit_exchange.erl | 2 +- src/rabbit_realm.erl | 26 +++++++++++++++----------- src/rabbit_tests.erl | 23 +---------------------- 5 files changed, 19 insertions(+), 36 deletions(-) diff --git a/include/rabbit.hrl b/include/rabbit.hrl index c7415f45..5a3006dd 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -30,7 +30,7 @@ -record(vhost_realm, {virtual_host, realm}). -record(realm, {name,ignore}). --record(realm_resource, {realm, resource, durable}). +-record(realm_resource, {realm, resource}). -record(user_realm, {username, realm, ticket_pattern}). diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 59c41fb8..63f043ba 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -142,7 +142,7 @@ declare(RealmName, NameBin, Durable, AutoDelete, Args) -> fun () -> case mnesia:wread({amqqueue, QName}) of [] -> ok = recover_queue(Q), - ok = rabbit_realm:add(RealmName, QName, Durable), + ok = rabbit_realm:add(RealmName, QName), Q; [ExistingQ] -> ExistingQ end diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 32418ca2..113b7878 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -106,7 +106,7 @@ declare(RealmName, NameBin, Type, Durable, AutoDelete, Args) -> durable_exchanges, Exchange, write); true -> ok end, - ok = rabbit_realm:add(RealmName, XName, Durable), + ok = rabbit_realm:add(RealmName, XName), Exchange; [ExistingX] -> ExistingX end diff --git a/src/rabbit_realm.erl b/src/rabbit_realm.erl index 2887158b..2ededb5f 100644 --- a/src/rabbit_realm.erl +++ b/src/rabbit_realm.erl @@ -27,7 +27,7 @@ -export([recover/0]). -export([add_realm/1, delete_realm/1, list_vhost_realms/1]). --export([add/3, check/2, delete_from_all/1]). +-export([add/2, delete/2, check/2, delete_from_all/1]). -export([access_request/3, enter_realm/3, leave_realms/1]). -export([on_node_down/1]). @@ -44,8 +44,8 @@ -spec(add_realm/1 :: (realm_name()) -> 'ok'). -spec(delete_realm/1 :: (realm_name()) -> 'ok'). -spec(list_vhost_realms/1 :: (vhost()) -> [name()]). -% -spec(add/3 :: (realm_name(), r(e_or_q())) -> 'ok'). -% -spec(delete/3 :: (realm_name(), r(e_or_q())) -> 'ok'). +-spec(add/2 :: (realm_name(), r(e_or_q())) -> 'ok'). +-spec(delete/2 :: (realm_name(), r(e_or_q())) -> 'ok'). -spec(check/2 :: (realm_name(), r(e_or_q())) -> bool() | not_found()). -spec(delete_from_all/1 :: (r(e_or_q())) -> 'ok'). -spec(access_request/3 :: (username(), bool(), ticket()) -> @@ -109,18 +109,21 @@ list_vhost_realms(VHostPath) -> VHostPath, fun () -> mnesia:read({vhost_realm, VHostPath}) end))]. -add(Realm = #resource{kind = realm}, Resource = #resource{}, Durable) -> - manage_link(fun mnesia:write/1, Realm, Resource, Durable). +add(Realm = #resource{kind = realm}, Resource = #resource{}) -> + manage_link(fun mnesia:write/1, Realm, Resource). + +delete(Realm = #resource{kind = realm}, Resource = #resource{}) -> + manage_link(fun mnesia:delete_object/1, Realm, Resource). % This links or unlinks a resource to a realm manage_link(Action, Realm = #resource{kind = realm, name = RealmName}, - Resource = #resource{name = ResourceName}, Durable) -> + Resource = #resource{name = ResourceName}) -> Table = realm_table_for_resource(Resource), rabbit_misc:execute_mnesia_transaction( fun () -> case mnesia:read({realm, Realm}) of [] -> mnesia:abort(not_found); - [_] -> Action({Table, RealmName, ResourceName, Durable}) + [_] -> Action({Table, RealmName, ResourceName}) end end). @@ -129,6 +132,7 @@ realm_table_for_resource(#resource{kind = queue}) -> realm_queue. parent_table_for_resource(#resource{kind = exchange}) -> exchange; parent_table_for_resource(#resource{kind = queue}) -> amqqueue. + check(#resource{kind = realm, name = Realm}, Resource = #resource{}) -> F = mnesia:match_object(#realm_resource{resource = Resource#resource.name, realm = Realm}), case mnesia:async_dirty(F) of @@ -232,14 +236,14 @@ preen_realm(Resource = #resource{}) -> LinkType = realm_table_for_resource(Resource), Q = qlc:q([L#realm_resource.resource || L <- mnesia:table(LinkType)]), Cursor = qlc:cursor(Q), - preen_next(Cursor, LinkType, parent_table_for_resource(Resource)), + preen_next(Cursor,LinkType,parent_table_for_resource(Resource)), qlc:delete_cursor(Cursor). - -preen_next(Cursor, LinkType, ParentTable) -> + +preen_next(Cursor,LinkType,ParentTable) -> case qlc:next_answers(Cursor,1) of [] -> ok; [ResourceKey] -> - case mnesia:match_object({ParentTable,ResourceKey,'_'}) of + case mnesia:read({ParentTable,ResourceKey}) of [] -> mnesia:delete_object({LinkType,'_',ResourceKey}); _ -> ok diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 5c265633..beeb3508 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -25,9 +25,7 @@ -module(rabbit_tests). --include("rabbit.hrl"). - --export([all_tests/0, test_parsing/0,preening_test/0]). +-export([all_tests/0, test_parsing/0]). -import(lists). @@ -48,25 +46,6 @@ all_tests() -> test_parsing() -> passed = test_content_properties(), passed. - -preening_test() -> - Realm = #resource{virtual_host = <<"/">>,kind = realm, name = <<"/data">>}, - loop(Realm,1), - rabbit_realm:recover(). - -loop(_,0) -> ok; -loop(Realm,N) -> - declare(Realm,true), - declare(Realm,false), - loop(Realm,N-1). - -declare(Realm,Durable) -> - X = rabbit_misc:binstring_guid("x"), - Q = rabbit_misc:binstring_guid("amq.gen"), - AutoDelete = false, - rabbit_exchange:declare(Realm,X, <<"direct">>, Durable, AutoDelete, undefined), - rabbit_amqqueue:declare(Realm, Q, Durable, AutoDelete, undefined). - test_content_properties() -> test_content_prop_roundtrip([], <<0, 0>>), -- cgit v1.2.1 From 37b37bec445c3af76c8ea9815ffe152e8d4bb6df Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 12 Jul 2008 10:00:15 +0100 Subject: cosmetic changes --- include/rabbit.hrl | 2 +- src/rabbit_realm.erl | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/rabbit.hrl b/include/rabbit.hrl index 5a3006dd..21900294 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -29,7 +29,7 @@ -record(vhost, {virtual_host, dummy}). -record(vhost_realm, {virtual_host, realm}). --record(realm, {name,ignore}). +-record(realm, {name, ignore}). -record(realm_resource, {realm, resource}). -record(user_realm, {username, realm, ticket_pattern}). diff --git a/src/rabbit_realm.erl b/src/rabbit_realm.erl index 2ededb5f..dad3deef 100644 --- a/src/rabbit_realm.erl +++ b/src/rabbit_realm.erl @@ -128,9 +128,9 @@ manage_link(Action, Realm = #resource{kind = realm, name = RealmName}, end). realm_table_for_resource(#resource{kind = exchange}) -> realm_exchange; -realm_table_for_resource(#resource{kind = queue}) -> realm_queue. +realm_table_for_resource(#resource{kind = queue}) -> realm_queue. parent_table_for_resource(#resource{kind = exchange}) -> exchange; -parent_table_for_resource(#resource{kind = queue}) -> amqqueue. +parent_table_for_resource(#resource{kind = queue}) -> amqqueue. check(#resource{kind = realm, name = Realm}, Resource = #resource{}) -> @@ -143,7 +143,7 @@ check(#resource{kind = realm, name = Realm}, Resource = #resource{}) -> % Requires a mnesia transaction. delete_from_all(Resource = #resource{name = Name}) -> - mnesia:delete_object({realm_table_for_resource(Resource),'_',Name}). + mnesia:delete_object({realm_table_for_resource(Resource), '_', Name}). access_request(Username, Exclusive, Ticket = #ticket{realm_name = RealmName}) when is_binary(Username) -> @@ -234,21 +234,22 @@ preen_realms() -> ok. preen_realm(Resource = #resource{}) -> LinkType = realm_table_for_resource(Resource), - Q = qlc:q([L#realm_resource.resource || L <- mnesia:table(LinkType)]), - Cursor = qlc:cursor(Q), - preen_next(Cursor,LinkType,parent_table_for_resource(Resource)), + Cursor = qlc:cursor( + qlc:q([L#realm_resource.resource || + L <- mnesia:table(LinkType)])), + preen_next(Cursor, LinkType, parent_table_for_resource(Resource)), qlc:delete_cursor(Cursor). -preen_next(Cursor,LinkType,ParentTable) -> - case qlc:next_answers(Cursor,1) of +preen_next(Cursor, LinkType, ParentTable) -> + case qlc:next_answers(Cursor, 1) of [] -> ok; - [ResourceKey] -> - case mnesia:read({ParentTable,ResourceKey}) of + [ResourceName] -> + case mnesia:read({ParentTable, ResourceName}) of [] -> - mnesia:delete_object({LinkType,'_',ResourceKey}); + mnesia:delete_object({LinkType, '_', ResourceName}); _ -> ok end, - preen_next(Cursor,LinkType,ParentTable) + preen_next(Cursor, LinkType, ParentTable) end. check_and_lookup(RealmName = #resource{kind = realm, -- cgit v1.2.1 From 59b0187504a41ea31a7dee3f4442f0a76bf31c50 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 12 Jul 2008 10:20:36 +0100 Subject: cosmetic --- src/rabbit_realm.erl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/rabbit_realm.erl b/src/rabbit_realm.erl index dad3deef..7b2d730c 100644 --- a/src/rabbit_realm.erl +++ b/src/rabbit_realm.erl @@ -117,13 +117,13 @@ delete(Realm = #resource{kind = realm}, Resource = #resource{}) -> % This links or unlinks a resource to a realm manage_link(Action, Realm = #resource{kind = realm, name = RealmName}, - Resource = #resource{name = ResourceName}) -> - Table = realm_table_for_resource(Resource), + R = #resource{name = Name}) -> + Table = realm_table_for_resource(R), rabbit_misc:execute_mnesia_transaction( fun () -> case mnesia:read({realm, Realm}) of [] -> mnesia:abort(not_found); - [_] -> Action({Table, RealmName, ResourceName}) + [_] -> Action({Table, RealmName, Name}) end end). @@ -142,8 +142,8 @@ check(#resource{kind = realm, name = Realm}, Resource = #resource{}) -> end. % Requires a mnesia transaction. -delete_from_all(Resource = #resource{name = Name}) -> - mnesia:delete_object({realm_table_for_resource(Resource), '_', Name}). +delete_from_all(R = #resource{name = Name}) -> + mnesia:delete_object({realm_table_for_resource(R), '_', Name}). access_request(Username, Exclusive, Ticket = #ticket{realm_name = RealmName}) when is_binary(Username) -> @@ -232,21 +232,21 @@ preen_realms() -> Resources = [#resource{kind = exchange},#resource{kind = queue}], [preen_realm(Resource) || Resource <- Resources ], ok. -preen_realm(Resource = #resource{}) -> - LinkType = realm_table_for_resource(Resource), +preen_realm(R = #resource{}) -> + LinkType = realm_table_for_resource(R), Cursor = qlc:cursor( qlc:q([L#realm_resource.resource || L <- mnesia:table(LinkType)])), - preen_next(Cursor, LinkType, parent_table_for_resource(Resource)), + preen_next(Cursor, LinkType, parent_table_for_resource(R)), qlc:delete_cursor(Cursor). preen_next(Cursor, LinkType, ParentTable) -> case qlc:next_answers(Cursor, 1) of [] -> ok; - [ResourceName] -> - case mnesia:read({ParentTable, ResourceName}) of + [Name] -> + case mnesia:read({ParentTable, Name}) of [] -> - mnesia:delete_object({LinkType, '_', ResourceName}); + mnesia:delete_object({LinkType, '_', Name}); _ -> ok end, preen_next(Cursor, LinkType, ParentTable) -- cgit v1.2.1 From 30e6d7a967673e7ca4ca5cf6b07f099521bf3c49 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 12 Jul 2008 10:24:41 +0100 Subject: rabbit_realm:check/2 is run outside tx --- src/rabbit_realm.erl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/rabbit_realm.erl b/src/rabbit_realm.erl index 7b2d730c..4668be26 100644 --- a/src/rabbit_realm.erl +++ b/src/rabbit_realm.erl @@ -133,12 +133,11 @@ parent_table_for_resource(#resource{kind = exchange}) -> exchange; parent_table_for_resource(#resource{kind = queue}) -> amqqueue. -check(#resource{kind = realm, name = Realm}, Resource = #resource{}) -> - F = mnesia:match_object(#realm_resource{resource = Resource#resource.name, realm = Realm}), - case mnesia:async_dirty(F) of - {atomic,[]} -> false; - {atomic,_} -> true; - _ -> false +check(#resource{kind = realm, name = Realm}, R = #resource{name = Name}) -> + case mnesia:dirty_match_object( + {realm_table_for_resource(R), Realm, Name}) of + [] -> false; + _ -> true end. % Requires a mnesia transaction. -- cgit v1.2.1 From 2538ff288eb028235049b47c524fff53747a1a6e Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 12 Jul 2008 10:36:48 +0100 Subject: minor refactoring of preen_realm --- src/rabbit_realm.erl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rabbit_realm.erl b/src/rabbit_realm.erl index 4668be26..b2c721fc 100644 --- a/src/rabbit_realm.erl +++ b/src/rabbit_realm.erl @@ -228,10 +228,11 @@ on_node_down(Node) -> %% This iterates through the realm_exchange and realm_queue link tables %% and deletes rows that have no underlying exchange or queue record. preen_realms() -> - Resources = [#resource{kind = exchange},#resource{kind = queue}], - [preen_realm(Resource) || Resource <- Resources ], + lists:foreach(fun preen_realm/1, [exchange, queue]), ok. -preen_realm(R = #resource{}) -> + +preen_realm(Kind) -> + R = #resource{kind = Kind}, LinkType = realm_table_for_resource(R), Cursor = qlc:cursor( qlc:q([L#realm_resource.resource || @@ -244,9 +245,8 @@ preen_next(Cursor, LinkType, ParentTable) -> [] -> ok; [Name] -> case mnesia:read({ParentTable, Name}) of - [] -> - mnesia:delete_object({LinkType, '_', Name}); - _ -> ok + [] -> mnesia:delete_object({LinkType, '_', Name}); + _ -> ok end, preen_next(Cursor, LinkType, ParentTable) end. -- cgit v1.2.1 From 8764bf5a85b5281a372889b9e0780405de47662b Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 12 Jul 2008 11:06:07 +0100 Subject: proper use of #realm_resource{} --- src/rabbit_mnesia.erl | 4 +++- src/rabbit_realm.erl | 36 ++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl index f18f3d50..18df11fe 100644 --- a/src/rabbit_mnesia.erl +++ b/src/rabbit_mnesia.erl @@ -109,9 +109,11 @@ table_definitions() -> {realm, [{disc_copies, [node()]}, {attributes, record_info(fields, realm)}]}, {realm_exchange, [{disc_copies, [node()]}, + {record_name, realm_resource}, {attributes, record_info(fields, realm_resource)}]}, {realm_queue, [{disc_copies, [node()]}, - {attributes, record_info(fields, realm_resource)}]}, + {record_name, realm_resource}, + {attributes, record_info(fields, realm_resource)}]}, {user_realm, [{type, bag}, {disc_copies, [node()]}, {attributes, record_info(fields, user_realm)}, diff --git a/src/rabbit_realm.erl b/src/rabbit_realm.erl index b2c721fc..4bd6db84 100644 --- a/src/rabbit_realm.erl +++ b/src/rabbit_realm.erl @@ -110,20 +110,22 @@ list_vhost_realms(VHostPath) -> fun () -> mnesia:read({vhost_realm, VHostPath}) end))]. add(Realm = #resource{kind = realm}, Resource = #resource{}) -> - manage_link(fun mnesia:write/1, Realm, Resource). + manage_link(fun mnesia:write/3, Realm, Resource). delete(Realm = #resource{kind = realm}, Resource = #resource{}) -> - manage_link(fun mnesia:delete_object/1, Realm, Resource). + manage_link(fun mnesia:delete_object/3, Realm, Resource). % This links or unlinks a resource to a realm manage_link(Action, Realm = #resource{kind = realm, name = RealmName}, R = #resource{name = Name}) -> - Table = realm_table_for_resource(R), rabbit_misc:execute_mnesia_transaction( fun () -> case mnesia:read({realm, Realm}) of - [] -> mnesia:abort(not_found); - [_] -> Action({Table, RealmName, Name}) + [] -> mnesia:abort(not_found); + [_] -> Action(realm_table_for_resource(R), + #realm_resource{realm = RealmName, + resource = Name}, + write) end end). @@ -134,15 +136,18 @@ parent_table_for_resource(#resource{kind = queue}) -> amqqueue. check(#resource{kind = realm, name = Realm}, R = #resource{name = Name}) -> - case mnesia:dirty_match_object( - {realm_table_for_resource(R), Realm, Name}) of + case mnesia:dirty_match_object(realm_table_for_resource(R), + #realm_resource{realm = Realm, + resource = Name}) of [] -> false; _ -> true end. % Requires a mnesia transaction. delete_from_all(R = #resource{name = Name}) -> - mnesia:delete_object({realm_table_for_resource(R), '_', Name}). + mnesia:delete_object(realm_table_for_resource(R), + #realm_resource{realm = '_', resource = Name}, + write). access_request(Username, Exclusive, Ticket = #ticket{realm_name = RealmName}) when is_binary(Username) -> @@ -233,22 +238,25 @@ preen_realms() -> preen_realm(Kind) -> R = #resource{kind = Kind}, - LinkType = realm_table_for_resource(R), + Table = realm_table_for_resource(R), Cursor = qlc:cursor( qlc:q([L#realm_resource.resource || - L <- mnesia:table(LinkType)])), - preen_next(Cursor, LinkType, parent_table_for_resource(R)), + L <- mnesia:table(Table)])), + preen_next(Cursor, Table, parent_table_for_resource(R)), qlc:delete_cursor(Cursor). -preen_next(Cursor, LinkType, ParentTable) -> +preen_next(Cursor, Table, ParentTable) -> case qlc:next_answers(Cursor, 1) of [] -> ok; [Name] -> case mnesia:read({ParentTable, Name}) of - [] -> mnesia:delete_object({LinkType, '_', Name}); + [] -> mnesia:delete_object( + Table, + #realm_resource{realm = '_', resource = Name}, + write); _ -> ok end, - preen_next(Cursor, LinkType, ParentTable) + preen_next(Cursor, Table, ParentTable) end. check_and_lookup(RealmName = #resource{kind = realm, -- cgit v1.2.1 From ec4276159237469a09902e29a5bf83d41667eb46 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Sun, 13 Jul 2008 19:34:00 +0100 Subject: Savepoint for lifecycle test that now works without realms or tickets --- ebin/rabbit.app | 1 - include/rabbit.hrl | 15 -- src/rabbit.erl | 18 +-- src/rabbit_access_control.erl | 118 +--------------- src/rabbit_amqqueue.erl | 36 ++--- src/rabbit_channel.erl | 78 ++--------- src/rabbit_control.erl | 26 ++-- src/rabbit_error_logger.erl | 3 - src/rabbit_exchange.erl | 19 ++- src/rabbit_misc.erl | 46 +----- src/rabbit_mnesia.erl | 17 --- src/rabbit_node_monitor.erl | 1 - src/rabbit_realm.erl | 316 ------------------------------------------ src/rabbit_ticket.erl | 131 ----------------- 14 files changed, 58 insertions(+), 767 deletions(-) delete mode 100644 src/rabbit_realm.erl delete mode 100644 src/rabbit_ticket.erl diff --git a/ebin/rabbit.app b/ebin/rabbit.app index 20d5afcf..730546b4 100644 --- a/ebin/rabbit.app +++ b/ebin/rabbit.app @@ -25,7 +25,6 @@ rabbit_node_monitor, rabbit_persister, rabbit_reader, - rabbit_realm, rabbit_router, rabbit_sup, rabbit_tests, diff --git a/include/rabbit.hrl b/include/rabbit.hrl index d8af670a..f153e7c4 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -27,12 +27,6 @@ -record(user_vhost, {username, virtual_host}). -record(vhost, {virtual_host, dummy}). --record(vhost_realm, {virtual_host, realm}). - --record(realm, {name, exchanges, queues}). --record(user_realm, {username, realm, ticket_pattern}). - --record(realm_visitor, {realm, pid}). -record(connection, {user, timeout_sec, frame_max, vhost}). @@ -45,8 +39,6 @@ -record(resource, {virtual_host, kind, name}). --record(ticket, {realm_name, passive_flag, active_flag, write_flag, read_flag}). - -record(exchange, {name, type, durable, auto_delete, arguments}). -record(amqqueue, {name, durable, auto_delete, arguments, binding_specs, pid}). @@ -78,18 +70,11 @@ #resource{virtual_host :: vhost(), kind :: Kind, name :: name()}). --type(realm_name() :: r('realm')). -type(queue_name() :: r('queue')). -type(exchange_name() :: r('exchange')). -type(user() :: #user{username :: username(), password :: password()}). --type(ticket() :: - #ticket{realm_name :: realm_name(), - passive_flag :: bool(), - active_flag :: bool(), - write_flag :: bool(), - read_flag :: bool()}). -type(permission() :: 'passive' | 'active' | 'write' | 'read'). -type(binding_spec() :: #binding_spec{exchange_name :: exchange_name(), diff --git a/src/rabbit.erl b/src/rabbit.erl index e65d532b..2c5fd614 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -150,10 +150,8 @@ start(normal, []) -> {"recovery", fun () -> ok = maybe_insert_default_data(), - ok = rabbit_exchange:recover(), - ok = rabbit_amqqueue:recover(), - ok = rabbit_realm:recover() + ok = rabbit_amqqueue:recover() end}, {"persister", fun () -> @@ -222,18 +220,8 @@ insert_default_data() -> insert_default_user(Username, Password, VHostSpecs) -> ok = rabbit_access_control:add_user(Username, Password), lists:foreach( - fun ({VHostPath, Realms}) -> - ok = rabbit_access_control:map_user_vhost( - Username, VHostPath), - lists:foreach( - fun (Realm) -> - RealmFullName = - rabbit_misc:r(VHostPath, realm, Realm), - ok = rabbit_access_control:map_user_realm( - Username, - rabbit_access_control:full_ticket( - RealmFullName)) - end, Realms) + fun (VHostPath) -> + ok = rabbit_access_control:map_user_vhost(Username, VHostPath) end, VHostSpecs), ok. diff --git a/src/rabbit_access_control.erl b/src/rabbit_access_control.erl index 2be07b19..0a410991 100644 --- a/src/rabbit_access_control.erl +++ b/src/rabbit_access_control.erl @@ -28,12 +28,11 @@ -include("rabbit.hrl"). -export([check_login/2, user_pass_login/2, - check_vhost_access/2, lookup_realm_access/2]). + check_vhost_access/2]). -export([add_user/2, delete_user/1, change_password/2, list_users/0, lookup_user/1]). -export([add_vhost/1, delete_vhost/1, list_vhosts/0, list_vhost_users/1]). -export([list_user_vhosts/1, map_user_vhost/2, unmap_user_vhost/2]). --export([list_user_realms/2, map_user_realm/2, full_ticket/1]). %%---------------------------------------------------------------------------- @@ -42,7 +41,6 @@ -spec(check_login/2 :: (binary(), binary()) -> user()). -spec(user_pass_login/2 :: (username(), password()) -> user()). -spec(check_vhost_access/2 :: (user(), vhost()) -> 'ok'). --spec(lookup_realm_access/2 :: (user(), realm_name()) -> maybe(ticket())). -spec(add_user/2 :: (username(), password()) -> 'ok'). -spec(delete_user/1 :: (username()) -> 'ok'). -spec(change_password/2 :: (username(), password()) -> 'ok'). @@ -55,9 +53,6 @@ -spec(list_user_vhosts/1 :: (username()) -> [vhost()]). -spec(map_user_vhost/2 :: (username(), vhost()) -> 'ok'). -spec(unmap_user_vhost/2 :: (username(), vhost()) -> 'ok'). --spec(map_user_realm/2 :: (username(), ticket()) -> 'ok'). --spec(list_user_realms/2 :: (username(), vhost()) -> [{name(), ticket()}]). --spec(full_ticket/1 :: (realm_name()) -> ticket()). -endif. @@ -130,18 +125,6 @@ check_vhost_access(#user{username = Username}, VHostPath) -> [VHostPath, Username]) end. -lookup_realm_access(#user{username = Username}, RealmName = #resource{kind = realm}) -> - %% TODO: use dirty ops instead - rabbit_misc:execute_mnesia_transaction( - fun () -> - case user_realms(Username, RealmName) of - [] -> - none; - [#user_realm{ticket_pattern = TicketPattern}] -> - TicketPattern - end - end). - add_user(Username, Password) -> R = rabbit_misc:execute_mnesia_transaction( fun () -> @@ -162,8 +145,7 @@ delete_user(Username) -> Username, fun () -> ok = mnesia:delete({user, Username}), - ok = mnesia:delete({user_vhost, Username}), - ok = mnesia:delete({user_realm, Username}) + ok = mnesia:delete({user_vhost, Username}) end)), rabbit_log:info("Deleted user ~p~n", [Username]), R. @@ -191,24 +173,10 @@ add_vhost(VHostPath) -> case mnesia:read({vhost, VHostPath}) of [] -> ok = mnesia:write(#vhost{virtual_host = VHostPath}), - DataRealm = - rabbit_misc:r(VHostPath, realm, <<"/data">>), - AdminRealm = - rabbit_misc:r(VHostPath, realm, <<"/admin">>), - ok = rabbit_realm:add_realm(DataRealm), - ok = rabbit_realm:add_realm(AdminRealm), - #exchange{} = rabbit_exchange:declare( - DataRealm, <<"">>, - direct, true, false, []), - #exchange{} = rabbit_exchange:declare( - DataRealm, <<"amq.direct">>, - direct, true, false, []), - #exchange{} = rabbit_exchange:declare( - DataRealm, <<"amq.topic">>, - topic, true, false, []), - #exchange{} = rabbit_exchange:declare( - DataRealm, <<"amq.fanout">>, - fanout, true, false, []), + #exchange{} = rabbit_exchange:declare(<<"">>, direct, true, false, []), + #exchange{} = rabbit_exchange:declare(<<"amq.direct">>, direct, true, false, []), + #exchange{} = rabbit_exchange:declare(<<"amq.topic">>, topic, true, false, []), + #exchange{} = rabbit_exchange:declare(<<"amq.fanout">>, fanout, true, false, []), ok; [_] -> mnesia:abort({vhost_already_exists, VHostPath}) @@ -240,11 +208,6 @@ internal_delete_vhost(VHostPath) -> ok = rabbit_exchange:delete(Name, false) end, rabbit_exchange:list_vhost_exchanges(VHostPath)), - lists:foreach(fun (RealmName) -> - ok = rabbit_realm:delete_realm( - rabbit_misc:r(VHostPath, realm, RealmName)) - end, - rabbit_realm:list_vhost_realms(VHostPath)), lists:foreach(fun (Username) -> ok = unmap_user_vhost(Username, VHostPath) end, @@ -290,77 +253,8 @@ unmap_user_vhost(Username, VHostPath) -> rabbit_misc:with_user_and_vhost( Username, VHostPath, fun () -> - lists:foreach(fun mnesia:delete_object/1, - user_realms(Username, - rabbit_misc:r(VHostPath, realm))), ok = mnesia:delete_object( #user_vhost{username = Username, virtual_host = VHostPath}) end)). -map_user_realm(Username, - Ticket = #ticket{realm_name = RealmName = - #resource{virtual_host = VHostPath, - kind = realm}}) -> - rabbit_misc:execute_mnesia_transaction( - rabbit_misc:with_user_and_vhost( - Username, VHostPath, - rabbit_misc:with_realm( - RealmName, - fun () -> - lists:foreach(fun mnesia:delete_object/1, - user_realms(Username, RealmName)), - case internal_lookup_vhost_access(Username, VHostPath) of - {ok, _R} -> - case ticket_liveness(Ticket) of - alive -> - ok = mnesia:write( - #user_realm{username = Username, - realm = RealmName, - ticket_pattern = Ticket}); - dead -> - ok - end; - not_found -> - mnesia:abort(not_mapped_to_vhost) - end - end))). - -list_user_realms(Username, VHostPath) -> - [{Name, Pattern} || - #user_realm{realm = #resource{name = Name}, - ticket_pattern = Pattern} <- - %% TODO: use dirty ops instead - rabbit_misc:execute_mnesia_transaction( - rabbit_misc:with_user_and_vhost( - Username, VHostPath, - fun () -> - case internal_lookup_vhost_access( - Username, VHostPath) of - {ok, _R} -> - user_realms(Username, - rabbit_misc:r(VHostPath, realm)); - not_found -> - mnesia:abort(not_mapped_to_vhost) - end - end))]. - -ticket_liveness(#ticket{passive_flag = false, - active_flag = false, - write_flag = false, - read_flag = false}) -> - dead; -ticket_liveness(_) -> - alive. - -full_ticket(RealmName) -> - #ticket{realm_name = RealmName, - passive_flag = true, - active_flag = true, - write_flag = true, - read_flag = true}. - -user_realms(Username, RealmName) -> - mnesia:match_object(#user_realm{username = Username, - realm = RealmName, - _ = '_'}). diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 63f043ba..5a9849df 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -25,8 +25,8 @@ -module(rabbit_amqqueue). --export([start/0, recover/0, declare/5, delete/3, purge/1, internal_delete/1]). --export([pseudo_queue/3]). +-export([start/0, recover/0, declare/4, delete/3, purge/1, internal_delete/1]). +-export([pseudo_queue/2]). -export([lookup/1, with/2, with_or_die/2, list_vhost_queues/1, stat/1, stat_all/0, deliver/5, redeliver/2, requeue/3, ack/4, commit/2, rollback/2]). @@ -55,7 +55,7 @@ {'error', 'queue_not_found' | 'exchange_not_found'}). -spec(start/0 :: () -> 'ok'). -spec(recover/0 :: () -> 'ok'). --spec(declare/5 :: (realm_name(), name(), bool(), bool(), amqp_table()) -> +-spec(declare/4 :: (name(), bool(), bool(), amqp_table()) -> amqqueue()). -spec(add_binding/4 :: (queue_name(), exchange_name(), routing_key(), amqp_table()) -> @@ -96,7 +96,7 @@ -spec(notify_sent/2 :: (pid(), pid()) -> 'ok'). -spec(internal_delete/1 :: (queue_name()) -> 'ok' | not_found()). -spec(on_node_down/1 :: (node()) -> 'ok'). --spec(pseudo_queue/3 :: (realm_name(), binary(), pid()) -> amqqueue()). +-spec(pseudo_queue/2 :: (binary(), pid()) -> amqqueue()). -endif. @@ -130,9 +130,8 @@ recover_durable_queues() -> ok end). -declare(RealmName, NameBin, Durable, AutoDelete, Args) -> - QName = rabbit_misc:r(RealmName, queue, NameBin), - Q = start_queue_process(#amqqueue{name = QName, +declare(NameBin, Durable, AutoDelete, Args) -> + Q = start_queue_process(#amqqueue{name = NameBin, durable = Durable, auto_delete = AutoDelete, arguments = Args, @@ -140,9 +139,8 @@ declare(RealmName, NameBin, Durable, AutoDelete, Args) -> pid = none}), case rabbit_misc:execute_mnesia_transaction( fun () -> - case mnesia:wread({amqqueue, QName}) of + case mnesia:wread({amqqueue, NameBin}) of [] -> ok = recover_queue(Q), - ok = rabbit_realm:add(RealmName, QName), Q; [ExistingQ] -> ExistingQ end @@ -169,8 +167,8 @@ recover_queue(Q) -> ok = recover_bindings(Q), ok. -default_binding_spec(#resource{virtual_host = VHost, name = Name}) -> - #binding_spec{exchange_name = rabbit_misc:r(VHost, exchange, <<>>), +default_binding_spec(Name) -> + #binding_spec{exchange_name = <<>>, routing_key = Name, arguments = []}. @@ -181,7 +179,7 @@ recover_bindings(Q = #amqqueue{name = QueueName, binding_specs = Specs}) -> end, Specs), ok. -modify_bindings(QueueName, ExchangeName, RoutingKey, Arguments, +modify_bindings(#resource{name = QueueName}, ExchangeName, RoutingKey, Arguments, SpecPresentFun, SpecAbsentFun) -> rabbit_misc:execute_mnesia_transaction( fun () -> @@ -244,6 +242,7 @@ delete_binding(QueueName, ExchangeName, RoutingKey, Arguments) -> lookup(Name) -> rabbit_misc:dirty_read({amqqueue, Name}). +with(#resource{name = Name}, F, E) -> with(Name, F, E); with(Name, F, E) -> case lookup(Name) of {ok, Q} -> rabbit_misc:with_exit_handler(E, fun () -> F(Q) end); @@ -340,7 +339,6 @@ internal_delete(QueueName) -> [Q] -> ok = delete_temp(Q), ok = mnesia:delete({durable_queues, QueueName}), - ok = rabbit_realm:delete_from_all(QueueName), ok end end). @@ -353,12 +351,8 @@ delete_temp(Q = #amqqueue{name = QueueName}) -> ok. delete_queue(Q = #amqqueue{name = QueueName, durable = Durable}) -> - ok = delete_temp(Q), - if - Durable -> ok; - true -> ok = rabbit_realm:delete_from_all(QueueName) - end. - + ok = delete_temp(Q). + on_node_down(Node) -> rabbit_misc:execute_mnesia_transaction( fun () -> @@ -370,8 +364,8 @@ on_node_down(Node) -> node(Pid) == Node])) end). -pseudo_queue(RealmName, NameBin, Pid) -> - #amqqueue{name = rabbit_misc:r(RealmName, queue, NameBin), +pseudo_queue(NameBin, Pid) -> + #amqqueue{name = NameBin, durable = false, auto_delete = false, arguments = [], diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index ec1d1fba..e1a6b4e6 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -37,7 +37,7 @@ transaction_id, tx_participants, next_tag, uncommitted_ack_q, unacked_message_q, username, virtual_host, - most_recently_declared_queue, consumer_mapping, next_ticket}). + most_recently_declared_queue, consumer_mapping}). %%---------------------------------------------------------------------------- @@ -94,8 +94,7 @@ init(ProxyPid, [ReaderPid, WriterPid, Username, VHost]) -> username = Username, virtual_host = VHost, most_recently_declared_queue = <<>>, - consumer_mapping = dict:new(), - next_ticket = 101}. + consumer_mapping = dict:new()}. handle_message({method, Method, Content}, State) -> case (catch handle_method(Method, Content, State)) of @@ -140,7 +139,6 @@ handle_message(Other, State) -> terminate(Reason, State = #ch{writer_pid = WriterPid}) -> Res = notify_queues(internal_rollback(State)), - ok = rabbit_realm:leave_realms(self()), case Reason of normal -> ok = Res; _ -> ok @@ -155,8 +153,7 @@ ok_msg(true, _Msg) -> undefined; ok_msg(false, Msg) -> Msg. return_queue_declare_ok(State, NoWait, Q) -> - NewState = State#ch{most_recently_declared_queue = - (Q#amqqueue.name)#resource.name}, + NewState = State#ch{most_recently_declared_queue = Q#amqqueue.name}, case NoWait of true -> {noreply, NewState}; false -> @@ -164,7 +161,7 @@ return_queue_declare_ok(State, NoWait, Q) -> rabbit_misc:with_exit_handler( fun () -> {ok, Q#amqqueue.name, 0, 0} end, fun () -> rabbit_amqqueue:stat(Q) end), - Reply = #'queue.declare_ok'{queue = ActualName#resource.name, + Reply = #'queue.declare_ok'{queue = ActualName, message_count = MessageCount, consumer_count = ConsumerCount}, {reply, Reply, NewState} @@ -195,14 +192,6 @@ die_precondition_failed(Fmt, Params) -> rabbit_misc:protocol_error({false, 406, <<"PRECONDITION_FAILED">>}, Fmt, Params). -check_ticket(TicketNumber, FieldIndex, Name, #ch{ username = Username}) -> - rabbit_ticket:check_ticket(TicketNumber, FieldIndex, Name, Username). - -lookup_ticket(TicketNumber, FieldIndex, - #ch{ username = Username, virtual_host = VHostPath }) -> - rabbit_ticket:lookup_ticket(TicketNumber, FieldIndex, - Username, VHostPath). - %% check that an exchange/queue name does not contain the reserved %% "amq." prefix. %% @@ -235,7 +224,6 @@ handle_method(_Method, _, #ch{state = starting}) -> handle_method(#'channel.close'{}, _, State = #ch{writer_pid = WriterPid}) -> ok = notify_queues(internal_rollback(State)), - ok = rabbit_realm:leave_realms(self()), ok = rabbit_writer:send_command(WriterPid, #'channel.close_ok'{}), ok = rabbit_writer:shutdown(WriterPid), stop; @@ -245,38 +233,8 @@ handle_method(#'access.request'{realm = RealmNameBin, passive = Passive, active = Active, write = Write, - read = Read}, - _, State = #ch{username = Username, - virtual_host = VHostPath, - next_ticket = NextTicket}) -> - RealmName = rabbit_misc:r(VHostPath, realm, RealmNameBin), - Ticket = #ticket{realm_name = RealmName, - passive_flag = Passive, - active_flag = Active, - write_flag = Write, - read_flag = Read}, - case rabbit_realm:access_request(Username, Exclusive, Ticket) of - ok -> - rabbit_ticket:record_ticket(NextTicket, Ticket), - NewState = State#ch{next_ticket = NextTicket + 1}, - {reply, #'access.request_ok'{ticket = NextTicket}, NewState}; - {error, not_found} -> - rabbit_misc:protocol_error( - invalid_path, "no ~s", [rabbit_misc:rs(RealmName)]); - {error, bad_realm_path} -> - %% FIXME: spec bug? access_refused is a soft error, spec requires it to be hard - rabbit_misc:protocol_error( - access_refused, "bad path for ~s", [rabbit_misc:rs(RealmName)]); - {error, resource_locked} -> - rabbit_misc:protocol_error( - resource_locked, "~s is locked", [rabbit_misc:rs(RealmName)]); - {error, access_refused} -> - rabbit_misc:protocol_error( - access_refused, - "~w permissions denied for user '~s' attempting to access ~s", - [rabbit_misc:permission_list(Ticket), - Username, rabbit_misc:rs(RealmName)]) - end; + read = Read},_, State) -> + {reply, #'access.request_ok'{ticket = 1}, State}; handle_method(#'basic.publish'{ticket = TicketNumber, exchange = ExchangeNameBin, @@ -285,7 +243,6 @@ handle_method(#'basic.publish'{ticket = TicketNumber, immediate = Immediate}, Content, State = #ch{ virtual_host = VHostPath}) -> ExchangeName = rabbit_misc:r(VHostPath, exchange, ExchangeNameBin), - check_ticket(TicketNumber, #ticket.write_flag, ExchangeName, State), Exchange = rabbit_exchange:lookup_or_die(ExchangeName), %% We decode the content's properties here because we're almost %% certain to want to look at delivery-mode and priority. @@ -329,7 +286,6 @@ handle_method(#'basic.get'{ticket = TicketNumber, _, State = #ch{ proxy_pid = ProxyPid, writer_pid = WriterPid, next_tag = DeliveryTag }) -> QueueName = expand_queue_name_shortcut(QueueNameBin, State), - check_ticket(TicketNumber, #ticket.read_flag, QueueName, State), case rabbit_amqqueue:with_or_die( QueueName, fun (Q) -> rabbit_amqqueue:basic_get(Q, ProxyPid, NoAck) end) of @@ -365,7 +321,6 @@ handle_method(#'basic.consume'{ticket = TicketNumber, case dict:find(ConsumerTag, ConsumerMapping) of error -> QueueName = expand_queue_name_shortcut(QueueNameBin, State), - check_ticket(TicketNumber, #ticket.read_flag, QueueName, State), ActualConsumerTag = case ConsumerTag of <<>> -> rabbit_misc:binstring_guid("amq.ctag"); @@ -505,8 +460,6 @@ handle_method(#'exchange.declare'{ticket = TicketNumber, nowait = NoWait, arguments = Args}, _, State = #ch{ virtual_host = VHostPath }) -> - #ticket{realm_name = RealmName} = - lookup_ticket(TicketNumber, #ticket.active_flag, State), CheckedType = rabbit_exchange:check_type(TypeNameBin), %% FIXME: clarify spec as per declare wrt differing realms X = case rabbit_exchange:lookup( @@ -514,8 +467,7 @@ handle_method(#'exchange.declare'{ticket = TicketNumber, {ok, FoundX} -> FoundX; {error, not_found} -> ActualNameBin = check_name('exchange', ExchangeNameBin), - rabbit_exchange:declare(RealmName, - ActualNameBin, + rabbit_exchange:declare(ActualNameBin, CheckedType, Durable, AutoDelete, @@ -530,8 +482,6 @@ handle_method(#'exchange.declare'{ticket = TicketNumber, passive = true, nowait = NoWait}, _, State = #ch{ virtual_host = VHostPath }) -> - %% FIXME: spec issue: permit active_flag here as well as passive_flag? - #ticket{} = lookup_ticket(TicketNumber, #ticket.passive_flag, State), ExchangeName = rabbit_misc:r(VHostPath, exchange, ExchangeNameBin), X = rabbit_exchange:lookup_or_die(ExchangeName), ok = rabbit_exchange:assert_type(X, rabbit_exchange:check_type(TypeNameBin)), @@ -543,7 +493,6 @@ handle_method(#'exchange.delete'{ticket = TicketNumber, nowait = NoWait}, _, State = #ch { virtual_host = VHostPath }) -> ExchangeName = rabbit_misc:r(VHostPath, exchange, ExchangeNameBin), - check_ticket(TicketNumber, #ticket.active_flag, ExchangeName, State), case rabbit_exchange:delete(ExchangeName, IfUnused) of {error, not_found} -> rabbit_misc:protocol_error( @@ -565,8 +514,6 @@ handle_method(#'queue.declare'{ticket = TicketNumber, arguments = Args}, _, State = #ch { virtual_host = VHostPath, reader_pid = ReaderPid }) -> - #ticket{realm_name = RealmName} = - lookup_ticket(TicketNumber, #ticket.active_flag, State), %% FIXME: atomic create&claim Finish = fun (Q) -> @@ -597,8 +544,7 @@ handle_method(#'queue.declare'{ticket = TicketNumber, <<>> -> rabbit_misc:binstring_guid("amq.gen"); Other -> check_name('queue', Other) end, - Finish(rabbit_amqqueue:declare(RealmName, - ActualNameBin, + Finish(rabbit_amqqueue:declare(ActualNameBin, Durable, AutoDelete, Args)); @@ -611,7 +557,6 @@ handle_method(#'queue.declare'{ticket = TicketNumber, passive = true, nowait = NoWait}, _, State = #ch{ virtual_host = VHostPath }) -> - #ticket{} = lookup_ticket(TicketNumber, #ticket.passive_flag, State), QueueName = rabbit_misc:r(VHostPath, queue, QueueNameBin), Q = rabbit_amqqueue:with_or_die(QueueName, fun (Q) -> Q end), return_queue_declare_ok(State, NoWait, Q); @@ -624,7 +569,6 @@ handle_method(#'queue.delete'{ticket = TicketNumber, }, _, State) -> QueueName = expand_queue_name_shortcut(QueueNameBin, State), - check_ticket(TicketNumber, #ticket.active_flag, QueueName, State), case rabbit_amqqueue:with_or_die( QueueName, fun (Q) -> rabbit_amqqueue:delete(Q, IfUnused, IfEmpty) end) of @@ -652,14 +596,13 @@ handle_method(#'queue.bind'{ticket = TicketNumber, QueueName = expand_queue_name_shortcut(QueueNameBin, State), ActualRoutingKey = expand_routing_key_shortcut(QueueNameBin, RoutingKey, State), - check_ticket(TicketNumber, #ticket.active_flag, QueueName, State), ExchangeName = rabbit_misc:r(VHostPath, exchange, ExchangeNameBin), case rabbit_amqqueue:add_binding(QueueName, ExchangeName, ActualRoutingKey, Arguments) of - {error, queue_not_found} -> + {error, queue_not_found} -> rabbit_misc:protocol_error( not_found, "no ~s", [rabbit_misc:rs(QueueName)]); - {error, exchange_not_found} -> + {error, exchange_not_found} -> rabbit_misc:protocol_error( not_found, "no ~s", [rabbit_misc:rs(ExchangeName)]); {error, durability_settings_incompatible} -> @@ -675,7 +618,6 @@ handle_method(#'queue.purge'{ticket = TicketNumber, nowait = NoWait}, _, State) -> QueueName = expand_queue_name_shortcut(QueueNameBin, State), - check_ticket(TicketNumber, #ticket.read_flag, QueueName, State), {ok, PurgedMessageCount} = rabbit_amqqueue:with_or_die( QueueName, fun (Q) -> rabbit_amqqueue:purge(Q) end), diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index ad796b61..9f95df1e 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -198,19 +198,19 @@ action(list_realms, Node, Args = [_VHostPath]) -> io:format("Listing realms for vhost ~p ...", Args), display_list(call(Node, {rabbit_realm, list_vhost_realms, Args})); -action(set_permissions, Node, - [Username, VHostPath, RealmName | Permissions]) -> - io:format("Setting permissions for user ~p, vhost ~p, realm ~p ...", - [Username, VHostPath, RealmName]), - CheckedPermissions = check_permissions(Permissions), - Ticket = #ticket{ - realm_name = realm_rsrc(VHostPath, RealmName), - passive_flag = lists:member(passive, CheckedPermissions), - active_flag = lists:member(active, CheckedPermissions), - write_flag = lists:member(write, CheckedPermissions), - read_flag = lists:member(read, CheckedPermissions)}, - rpc_call(Node, rabbit_access_control, map_user_realm, - [list_to_binary(Username), Ticket]); +% action(set_permissions, Node, +% [Username, VHostPath, RealmName | Permissions]) -> +% io:format("Setting permissions for user ~p, vhost ~p, realm ~p ...", +% [Username, VHostPath, RealmName]), +% CheckedPermissions = check_permissions(Permissions), +% Ticket = #ticket{ +% realm_name = realm_rsrc(VHostPath, RealmName), +% passive_flag = lists:member(passive, CheckedPermissions), +% active_flag = lists:member(active, CheckedPermissions), +% write_flag = lists:member(write, CheckedPermissions), +% read_flag = lists:member(read, CheckedPermissions)}, +% rpc_call(Node, rabbit_access_control, map_user_realm, +% [list_to_binary(Username), Ticket]); action(list_permissions, Node, Args = [_Username, _VHostPath]) -> io:format("Listing permissions for user ~p in vhost ~p ...", Args), diff --git a/src/rabbit_error_logger.erl b/src/rabbit_error_logger.erl index 0ae116bb..5bc538d5 100644 --- a/src/rabbit_error_logger.erl +++ b/src/rabbit_error_logger.erl @@ -34,9 +34,6 @@ init([DefaultVHost]) -> #exchange{} = rabbit_exchange:declare( - #resource{virtual_host = DefaultVHost, - kind = realm, - name = <<"/admin">>}, ?LOG_EXCH_NAME, topic, true, false, []), {ok, #resource{virtual_host = DefaultVHost, diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 113b7878..1fbfcd7e 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -28,7 +28,7 @@ -include("rabbit.hrl"). -include("rabbit_framing.hrl"). --export([recover/0, declare/6, lookup/1, lookup_or_die/1, +-export([recover/0, declare/5, lookup/1, lookup_or_die/1, list_vhost_exchanges/1, list_exchange_bindings/1, simple_publish/6, simple_publish/3, route/2]). @@ -50,7 +50,7 @@ not_found() | {'error', 'unroutable' | 'not_delivered'}). -spec(recover/0 :: () -> 'ok'). --spec(declare/6 :: (realm_name(), name(), exchange_type(), bool(), bool(), +-spec(declare/5 :: (name(), exchange_type(), bool(), bool(), amqp_table()) -> exchange()). -spec(check_type/1 :: (binary()) -> atom()). -spec(assert_type/2 :: (exchange(), atom()) -> 'ok'). @@ -90,23 +90,21 @@ recover_durable_exchanges() -> end, ok, durable_exchanges) end). -declare(RealmName, NameBin, Type, Durable, AutoDelete, Args) -> - XName = rabbit_misc:r(RealmName, exchange, NameBin), - Exchange = #exchange{name = XName, +declare(NameBin, Type, Durable, AutoDelete, Args) -> + Exchange = #exchange{name = NameBin, type = Type, durable = Durable, auto_delete = AutoDelete, arguments = Args}, rabbit_misc:execute_mnesia_transaction( fun () -> - case mnesia:wread({exchange, XName}) of + case mnesia:wread({exchange, NameBin}) of [] -> ok = mnesia:write(Exchange), if Durable -> ok = mnesia:write( durable_exchanges, Exchange, write); true -> ok end, - ok = rabbit_realm:add(RealmName, XName), Exchange; [ExistingX] -> ExistingX end @@ -217,6 +215,7 @@ delivery_key_for_type(fanout, Name, _RoutingKey) -> delivery_key_for_type(_Type, Name, RoutingKey) -> {Name, RoutingKey}. +call_with_exchange(#resource{name = Name}, Fun) -> call_with_exchange(Name, Fun); call_with_exchange(Name, Fun) -> case mnesia:wread({exchange, Name}) of [] -> {error, not_found}; @@ -290,7 +289,7 @@ add_handler_to_binding(BindingKey, Handler) -> ok = mnesia:write( B#binding{handlers = extend_handlers(H, Handler)}) end. - + %% Must run within a transaction. remove_handler_from_binding(BindingKey, Handler) -> case mnesia:wread({binding, BindingKey}) of @@ -334,6 +333,7 @@ last_topic_match(P, R, []) -> last_topic_match(P, R, [BacktrackNext | BacktrackList]) -> topic_matches1(P, R) or last_topic_match(P, [BacktrackNext | R], BacktrackList). +delete(#resource{name = ExchangeName}, IfUnused) -> delete(ExchangeName, IfUnused); delete(ExchangeName, IfUnused) -> rabbit_misc:execute_mnesia_transaction( fun () -> internal_delete(ExchangeName, IfUnused) end). @@ -375,6 +375,5 @@ do_internal_delete(ExchangeName, Bindings) -> ok = mnesia:delete({binding, K}) end, Bindings), ok = mnesia:delete({durable_exchanges, ExchangeName}), - ok = mnesia:delete({exchange, ExchangeName}), - ok = rabbit_realm:delete_from_all(ExchangeName) + ok = mnesia:delete({exchange, ExchangeName}) end. diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 927d7712..259dc0d8 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -29,14 +29,12 @@ -export([method_record_type/1, polite_pause/0, polite_pause/1]). -export([die/1, frame_error/2, protocol_error/3, protocol_error/4]). --export([strict_ticket_checking/0]). -export([get_config/1, get_config/2, set_config/2]). -export([dirty_read/1]). -export([r/3, r/2, rs/1]). --export([permission_list/1]). -export([enable_cover/0, report_cover/0]). -export([with_exit_handler/2]). --export([with_user/2, with_vhost/2, with_realm/2, with_user_and_vhost/3]). +-export([with_user/2, with_vhost/2, with_user_and_vhost/3]). -export([execute_mnesia_transaction/1]). -export([ensure_ok/2]). -export([localnode/1, tcp_name/3]). @@ -64,25 +62,20 @@ (atom() | amqp_error(), string(), [any()]) -> no_return()). -spec(protocol_error/4 :: (atom() | amqp_error(), string(), [any()], atom()) -> no_return()). --spec(strict_ticket_checking/0 :: () -> bool()). -spec(get_config/1 :: (atom()) -> {'ok', any()} | not_found()). -spec(get_config/2 :: (atom(), A) -> A). -spec(set_config/2 :: (atom(), any()) -> 'ok'). -spec(dirty_read/1 :: ({atom(), any()}) -> {'ok', any()} | not_found()). --spec(r/3 :: (realm_name() | vhost(), K, name()) -> - r(K) when is_subtype(K, atom())). -spec(r/2 :: (vhost(), K) -> #resource{virtual_host :: vhost(), kind :: K, name :: '_'} when is_subtype(K, atom())). --spec(rs/1 :: (r(atom())) -> string()). --spec(permission_list/1 :: (ticket()) -> [permission()]). +-spec(rs/1 :: (r(atom())) -> string()). -spec(enable_cover/0 :: () -> 'ok' | {'error', any()}). -spec(report_cover/0 :: () -> 'ok'). -spec(with_exit_handler/2 :: (thunk(A), thunk(A)) -> A). -spec(with_user/2 :: (username(), thunk(A)) -> A). -spec(with_vhost/2 :: (vhost(), thunk(A)) -> A). --spec(with_realm/2 :: (realm_name(), thunk(A)) -> A). -spec(with_user_and_vhost/3 :: (username(), vhost(), thunk(A)) -> A). -spec(execute_mnesia_transaction/1 :: (thunk(A)) -> A). -spec(ensure_ok/2 :: ('ok' | {'error', any()}, atom()) -> 'ok'). @@ -143,9 +136,6 @@ boolean_config_param(Name, TrueValue, FalseValue, DefaultValue) -> DefaultValue == TrueValue end. -strict_ticket_checking() -> - boolean_config_param(strict_ticket_checking, enabled, disabled, disabled). - get_config(Key) -> case dirty_read({rabbit_config, Key}) of {ok, {rabbit_config, Key, V}} -> {ok, V}; @@ -180,19 +170,6 @@ rs(#resource{virtual_host = VHostPath, kind = Kind, name = Name}) -> lists:flatten(io_lib:format("~s '~s' in vhost '~s'", [Kind, Name, VHostPath])). -permission_list(Ticket = #ticket{}) -> - lists:foldr(fun ({Field, Label}, L) -> - case element(Field, Ticket) of - true -> [Label | L]; - false -> L - end - end, - [], - [{#ticket.passive_flag, passive}, - {#ticket.active_flag, active}, - {#ticket.write_flag, write}, - {#ticket.read_flag, read}]). - enable_cover() -> case cover:compile_beam_directory("ebin") of {error,Reason} -> {error,Reason}; @@ -258,25 +235,6 @@ with_vhost(VHostPath, Thunk) -> end end. -with_realm(Name = #resource{virtual_host = VHostPath, kind = realm}, - Thunk) -> - fun () -> - case mnesia:read({realm, Name}) of - [] -> - mnesia:abort({no_such_realm, Name}); - [_R] -> - case mnesia:match_object( - #vhost_realm{virtual_host = VHostPath, - realm = Name}) of - [] -> - %% This should never happen - mnesia:abort({no_such_realm, Name}); - [_VR] -> - Thunk() - end - end - end. - with_user_and_vhost(Username, VHostPath, Thunk) -> with_user(Username, with_vhost(VHostPath, Thunk)). diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl index 82b80cb4..b1ab3da2 100644 --- a/src/rabbit_mnesia.erl +++ b/src/rabbit_mnesia.erl @@ -102,23 +102,6 @@ table_definitions() -> {index, [virtual_host]}]}, {vhost, [{disc_copies, [node()]}, {attributes, record_info(fields, vhost)}]}, - {vhost_realm, [{type, bag}, - {disc_copies, [node()]}, - {attributes, record_info(fields, vhost_realm)}, - {index, [realm]}]}, - {realm, [{disc_copies, [node()]}, - {attributes, record_info(fields, realm)}]}, - {user_realm, [{type, bag}, - {disc_copies, [node()]}, - {attributes, record_info(fields, user_realm)}, - {index, [realm]}]}, - {exclusive_realm_visitor, - [{record_name, realm_visitor}, - {attributes, record_info(fields, realm_visitor)}, - {index, [pid]}]}, - {realm_visitor, [{type, bag}, - {attributes, record_info(fields, realm_visitor)}, - {index, [pid]}]}, {rabbit_config, [{disc_copies, [node()]}]}, {listener, [{type, bag}, {attributes, record_info(fields, listener)}]}, diff --git a/src/rabbit_node_monitor.erl b/src/rabbit_node_monitor.erl index beef5285..2fb582a9 100644 --- a/src/rabbit_node_monitor.erl +++ b/src/rabbit_node_monitor.erl @@ -60,7 +60,6 @@ handle_info({nodedown, Node}, State) -> %% lots of nodes. We really only need to execute this code on %% *one* node, rather than all of them. ok = rabbit_networking:on_node_down(Node), - ok = rabbit_realm:on_node_down(Node), ok = rabbit_amqqueue:on_node_down(Node), {noreply, State}; handle_info(_Info, State) -> diff --git a/src/rabbit_realm.erl b/src/rabbit_realm.erl deleted file mode 100644 index 4463954d..00000000 --- a/src/rabbit_realm.erl +++ /dev/null @@ -1,316 +0,0 @@ -%% The contents of this file are subject to the Mozilla Public License -%% Version 1.1 (the "License"); you may not use this file except in -%% compliance with the License. You may obtain a copy of the License at -%% http://www.mozilla.org/MPL/ -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -%% License for the specific language governing rights and limitations -%% under the License. -%% -%% The Original Code is RabbitMQ. -%% -%% The Initial Developers of the Original Code are LShift Ltd., -%% Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd. -%% -%% Portions created by LShift Ltd., Cohesive Financial Technologies -%% LLC., and Rabbit Technologies Ltd. are Copyright (C) 2007-2008 -%% LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit -%% Technologies Ltd.; -%% -%% All Rights Reserved. -%% -%% Contributor(s): ______________________________________. -%% - --module(rabbit_realm). - --export([recover/0]). --export([add_realm/1, delete_realm/1, list_vhost_realms/1]). --export([add/2, delete/2, check/2, delete_from_all/1]). --export([access_request/3, enter_realm/3, leave_realms/1]). --export([on_node_down/1]). - --include("rabbit.hrl"). --include_lib("stdlib/include/qlc.hrl"). - -%%---------------------------------------------------------------------------- - --ifdef(use_specs). - --type(e_or_q() :: 'exchange' | 'queue'). - --spec(recover/0 :: () -> 'ok'). --spec(add_realm/1 :: (realm_name()) -> 'ok'). --spec(delete_realm/1 :: (realm_name()) -> 'ok'). --spec(list_vhost_realms/1 :: (vhost()) -> [name()]). --spec(add/2 :: (realm_name(), r(e_or_q())) -> 'ok'). --spec(delete/2 :: (realm_name(), r(e_or_q())) -> 'ok'). --spec(check/2 :: (realm_name(), r(e_or_q())) -> bool() | not_found()). --spec(delete_from_all/1 :: (r(e_or_q())) -> 'ok'). --spec(access_request/3 :: (username(), bool(), ticket()) -> - 'ok' | not_found() | {'error', 'bad_realm_path' | - 'access_refused' | - 'resource_locked'}). --spec(enter_realm/3 :: (realm_name(), bool(), pid()) -> - 'ok' | {'error', 'resource_locked'}). --spec(leave_realms/1 :: (pid()) -> 'ok'). --spec(on_node_down/1 :: (node()) -> 'ok'). - --endif. - -%%-------------------------------------------------------------------- - -recover() -> - %% preens resource lists, limiting them to currently-extant resources - rabbit_misc:execute_mnesia_transaction( - fun () -> - Realms = mnesia:foldl(fun preen_realm/2, [], realm), - lists:foreach(fun mnesia:write/1, Realms), - ok - end). - -add_realm(Name = #resource{virtual_host = VHostPath, kind = realm}) -> - rabbit_misc:execute_mnesia_transaction( - rabbit_misc:with_vhost( - VHostPath, - fun () -> - case mnesia:read({realm, Name}) of - [] -> - NewRealm = #realm{name = Name, - exchanges = ordsets:new(), - queues = ordsets:new()}, - ok = mnesia:write(NewRealm), - ok = mnesia:write( - #vhost_realm{virtual_host = VHostPath, - realm = Name}), - ok; - [_R] -> - mnesia:abort({realm_already_exists, Name}) - end - end)). - -delete_realm(Name = #resource{virtual_host = VHostPath, kind = realm}) -> - rabbit_misc:execute_mnesia_transaction( - rabbit_misc:with_vhost( - VHostPath, - rabbit_misc:with_realm( - Name, - fun () -> - ok = mnesia:delete({realm, Name}), - ok = mnesia:delete_object( - #vhost_realm{virtual_host = VHostPath, - realm = Name}), - lists:foreach(fun mnesia:delete_object/1, - mnesia:index_read(user_realm, Name, - #user_realm.realm)), - ok - end))). - -list_vhost_realms(VHostPath) -> - [Name || - #vhost_realm{realm = #resource{name = Name}} <- - %% TODO: use dirty ops instead - rabbit_misc:execute_mnesia_transaction( - rabbit_misc:with_vhost( - VHostPath, - fun () -> mnesia:read({vhost_realm, VHostPath}) end))]. - -add(Name = #resource{kind = realm}, Resource) -> - internal_update_realm_byname(Name, Resource, fun ordsets:add_element/2). - -delete(Name = #resource{kind = realm}, Resource) -> - internal_update_realm_byname(Name, Resource, fun ordsets:del_element/2). - -check(Name = #resource{kind = realm}, Resource = #resource{kind = Kind}) -> - case rabbit_misc:dirty_read({realm, Name}) of - {ok, R} -> - case Kind of - exchange -> ordsets:is_element(Resource, R#realm.exchanges); - queue -> ordsets:is_element(Resource, R#realm.queues) - end; - Other -> Other - end. - -% Requires a mnesia transaction. -delete_from_all(Resource = #resource{kind = Kind}) -> - Realms = mnesia:foldl - (fun (Realm = #realm{exchanges = E0, - queues = Q0}, - Acc) -> - IsMember = lists:member(Resource, - case Kind of - exchange -> E0; - queue -> Q0 - end), - if - IsMember -> - [internal_update_realm_record( - Realm, Resource, - fun ordsets:del_element/2) - | Acc]; - true -> - Acc - end - end, [], realm), - lists:foreach(fun mnesia:write/1, Realms), - ok. - -access_request(Username, Exclusive, Ticket = #ticket{realm_name = RealmName}) - when is_binary(Username) -> - %% FIXME: We should do this all in a single tx. Otherwise we may - %% a) get weird answers, b) create inconsistencies in the db - %% (e.g. realm_visitor records referring to non-existing realms). - case check_and_lookup(RealmName) of - {error, Reason} -> - {error, Reason}; - {ok, _Realm} -> - {ok, U} = rabbit_access_control:lookup_user(Username), - case rabbit_access_control:lookup_realm_access(U, RealmName) of - none -> - {error, access_refused}; - TicketPattern -> - case match_ticket(TicketPattern, Ticket) of - no_match -> - {error, access_refused}; - match -> - enter_realm(RealmName, Exclusive, self()) - end - end - end. - -enter_realm(Name = #resource{kind = realm}, IsExclusive, Pid) -> - RealmVisitor = #realm_visitor{realm = Name, pid = Pid}, - rabbit_misc:execute_mnesia_transaction( - fun () -> - case mnesia:read({exclusive_realm_visitor, Name}) of - [] when IsExclusive -> - ok = mnesia:delete_object(RealmVisitor), - %% TODO: find a more efficient way of checking - %% for "no machting results" that doesn't - %% involve retrieving all the records - case mnesia:read({realm_visitor, Name}) of - [] -> - mnesia:write( - exclusive_realm_visitor, RealmVisitor, write), - ok; - [_|_] -> - {error, resource_locked} - end; - [] -> - ok = mnesia:write(RealmVisitor), - ok; - [RealmVisitor] when IsExclusive -> ok; - [RealmVisitor] -> - ok = mnesia:delete({exclusive_realm_visitor, Name}), - ok = mnesia:write(RealmVisitor), - ok; - [_] -> - {error, resource_locked} - end - end). - -leave_realms(Pid) -> - rabbit_misc:execute_mnesia_transaction( - fun () -> - case mnesia:index_read(exclusive_realm_visitor, Pid, - #realm_visitor.pid) of - [] -> ok; - [R] -> - ok = mnesia:delete_object( - exclusive_realm_visitor, R, write) - end, - lists:foreach(fun mnesia:delete_object/1, - mnesia:index_read(realm_visitor, Pid, - #realm_visitor.pid)), - ok - end). - -on_node_down(Node) -> - rabbit_misc:execute_mnesia_transaction( - fun () -> - lists:foreach( - fun (T) -> ok = remove_visitors(Node, T) end, - [exclusive_realm_visitor, realm_visitor]), - ok - end). - -%%-------------------------------------------------------------------- - -preen_realm(Realm = #realm{name = #resource{kind = realm}, - exchanges = E0, - queues = Q0}, - Realms) -> - [Realm#realm{exchanges = filter_out_missing(E0, exchange), - queues = filter_out_missing(Q0, amqqueue)} - | Realms]. - -filter_out_missing(Items, TableName) -> - ordsets:filter(fun (Item) -> - case mnesia:read({TableName, Item}) of - [] -> false; - _ -> true - end - end, Items). - -internal_update_realm_byname(Name, Resource, SetUpdater) -> - rabbit_misc:execute_mnesia_transaction( - fun () -> - case mnesia:read({realm, Name}) of - [] -> - mnesia:abort(not_found); - [R] -> - ok = mnesia:write(internal_update_realm_record - (R, Resource, SetUpdater)) - end - end). - -internal_update_realm_record(R = #realm{exchanges = E0, queues = Q0}, - Resource = #resource{kind = Kind}, - SetUpdater) -> - case Kind of - exchange -> R#realm{exchanges = SetUpdater(Resource, E0)}; - queue -> R#realm{queues = SetUpdater(Resource, Q0)} - end. - -check_and_lookup(RealmName = #resource{kind = realm, - name = <<"/data", _/binary>>}) -> - lookup(RealmName); -check_and_lookup(RealmName = #resource{kind = realm, - name = <<"/admin", _/binary>>}) -> - lookup(RealmName); -check_and_lookup(_) -> - {error, bad_realm_path}. - -lookup(Name = #resource{kind = realm}) -> - rabbit_misc:dirty_read({realm, Name}). - -match_ticket(#ticket{passive_flag = PP, - active_flag = PA, - write_flag = PW, - read_flag = PR}, - #ticket{passive_flag = TP, - active_flag = TA, - write_flag = TW, - read_flag = TR}) -> - if - %% Matches if either we're not requesting passive access, or - %% passive access is permitted, and ... - (not(TP) orelse PP) andalso - (not(TA) orelse PA) andalso - (not(TW) orelse PW) andalso - (not(TR) orelse PR) -> - match; - true -> - no_match - end. - -remove_visitors(Node, T) -> - qlc:fold( - fun (R, Acc) -> - ok = mnesia:delete_object(T, R, write), - Acc - end, - ok, - qlc:q([R || R = #realm_visitor{pid = Pid} <- mnesia:table(T), - node(Pid) == Node])). diff --git a/src/rabbit_ticket.erl b/src/rabbit_ticket.erl deleted file mode 100644 index 3a608faa..00000000 --- a/src/rabbit_ticket.erl +++ /dev/null @@ -1,131 +0,0 @@ -%% The contents of this file are subject to the Mozilla Public License -%% Version 1.1 (the "License"); you may not use this file except in -%% compliance with the License. You may obtain a copy of the License at -%% http://www.mozilla.org/MPL/ -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -%% License for the specific language governing rights and limitations -%% under the License. -%% -%% The Original Code is RabbitMQ. -%% -%% The Initial Developers of the Original Code are LShift Ltd., -%% Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd. -%% -%% Portions created by LShift Ltd., Cohesive Financial Technologies -%% LLC., and Rabbit Technologies Ltd. are Copyright (C) 2007-2008 -%% LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit -%% Technologies Ltd.; -%% -%% All Rights Reserved. -%% -%% Contributor(s): ______________________________________. -%% - --module(rabbit_ticket). --include("rabbit.hrl"). - --export([record_ticket/2, lookup_ticket/4, check_ticket/4]). - --import(application). - -%%---------------------------------------------------------------------------- - --ifdef(use_specs). - --type(ticket_number() :: non_neg_integer()). -%% we'd like to write #ticket.passive_flag | #ticket.active_flag | ... -%% but dialyzer doesn't support that. --type(ticket_field() :: 3..6). - --spec(record_ticket/2 :: (ticket_number(), ticket()) -> 'ok'). --spec(lookup_ticket/4 :: - (ticket_number(), ticket_field(), username(), vhost()) -> - ticket()). --spec(check_ticket/4 :: - (ticket_number(), ticket_field(), r('exchange' | 'queue'), username()) -> - 'ok'). - --endif. - -%%---------------------------------------------------------------------------- - -record_ticket(TicketNumber, Ticket) -> - put({ticket, TicketNumber}, Ticket), - ok. - -lookup_ticket(TicketNumber, FieldIndex, Username, VHostPath) -> - case get({ticket, TicketNumber}) of - undefined -> - %% Spec: "The server MUST isolate access tickets per - %% channel and treat an attempt by a client to mix these - %% as a connection exception." - rabbit_log:warning("Attempt by client to use invalid ticket ~p~n", [TicketNumber]), - maybe_relax_checks(TicketNumber, Username, VHostPath); - Ticket = #ticket{} -> - case element(FieldIndex, Ticket) of - false -> rabbit_misc:protocol_error( - access_refused, - "ticket ~w has insufficient permissions", - [TicketNumber]); - true -> Ticket - end - end. - -maybe_relax_checks(TicketNumber, Username, VHostPath) -> - case rabbit_misc:strict_ticket_checking() of - true -> - rabbit_misc:protocol_error( - access_refused, "invalid ticket ~w", [TicketNumber]); - false -> - rabbit_log:warning("Lax ticket check mode: fabricating full ticket ~p for user ~p, vhost ~p~n", - [TicketNumber, Username, VHostPath]), - Ticket = rabbit_access_control:full_ticket( - rabbit_misc:r(VHostPath, realm, <<"/data">>)), - case rabbit_realm:access_request(Username, false, Ticket) of - ok -> record_ticket(TicketNumber, Ticket), - Ticket; - {error, Reason} -> - rabbit_misc:protocol_error( - Reason, - "fabrication of ticket ~w for user '~s' in vhost '~s' failed", - [TicketNumber, Username, VHostPath]) - end - end. - -check_ticket(TicketNumber, FieldIndex, - Name = #resource{virtual_host = VHostPath}, Username) -> - #ticket{realm_name = RealmName} = - lookup_ticket(TicketNumber, FieldIndex, Username, VHostPath), - case resource_in_realm(RealmName, Name) of - false -> - case rabbit_misc:strict_ticket_checking() of - true -> - rabbit_misc:protocol_error( - access_refused, - "insufficient permissions in ticket ~w to access ~s in ~s", - [TicketNumber, rabbit_misc:rs(Name), - rabbit_misc:rs(RealmName)]); - false -> - rabbit_log:warning("Lax ticket check mode: ignoring cross-realm access for ticket ~p~n", [TicketNumber]), - ok - end; - true -> - ok - end. - -resource_in_realm(RealmName, ResourceName = #resource{kind = Kind}) -> - CacheKey = {resource_cache, RealmName, Kind}, - case get(CacheKey) of - Name when Name == ResourceName -> - true; - _ -> - case rabbit_realm:check(RealmName, ResourceName) of - true -> - put(CacheKey, ResourceName), - true; - _ -> - false - end - end. -- cgit v1.2.1 From 4f0d663610209e1ec7527a69e81b78a5beda5cef Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Sun, 13 Jul 2008 19:41:57 +0100 Subject: Network test suite now passes completely --- src/rabbit_exchange.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 1fbfcd7e..380ff243 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -131,12 +131,13 @@ assert_type(#exchange{ name = Name, type = ActualType }, RequiredType) -> lookup(Name) -> rabbit_misc:dirty_read({exchange, Name}). +lookup_or_die(#resource{name = Name}) -> lookup_or_die(Name); lookup_or_die(Name) -> case lookup(Name) of {ok, X} -> X; {error, not_found} -> rabbit_misc:protocol_error( - not_found, "no ~s", [rabbit_misc:rs(Name)]) + not_found, "no ~s", [rabbit_misc:rs(#resource{virtual_host = <<"/">>, kind = exchange, name = Name})]) end. list_vhost_exchanges(VHostPath) -> -- cgit v1.2.1 From c6210473559eed2ee8d959d30fc08dd60e09a425 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Sun, 13 Jul 2008 19:56:31 +0100 Subject: Removed reference to rabbit_ticket module --- ebin/rabbit.app | 1 - 1 file changed, 1 deletion(-) diff --git a/ebin/rabbit.app b/ebin/rabbit.app index 730546b4..0326f461 100644 --- a/ebin/rabbit.app +++ b/ebin/rabbit.app @@ -28,7 +28,6 @@ rabbit_router, rabbit_sup, rabbit_tests, - rabbit_ticket, rabbit_tracer, rabbit_writer, tcp_acceptor, -- cgit v1.2.1 From 59af33d7f86fa9903ec859e9fc7739eab95a032f Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Mon, 14 Jul 2008 11:14:43 +0100 Subject: Reverted sync transaction to its previous state (QA note from Matthias) --- src/rabbit_misc.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 08e15817..927d7712 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -284,7 +284,7 @@ execute_mnesia_transaction(TxFun) -> %% Making this a sync_transaction allows us to use dirty_read %% elsewhere and get a consistent result even when that read %% executes on a different node. - case mnesia:transaction(TxFun) of + case mnesia:sync_transaction(TxFun) of {atomic, Result} -> Result; {aborted, Reason} -> throw({error, Reason}) end. -- cgit v1.2.1 From 6c3c8aba51c6d56845a1f2b2f373ec959a9d486e Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Mon, 21 Jul 2008 19:43:23 +0100 Subject: Re-keyed exchange and queue persistence on the vhost --- src/rabbit.erl | 10 +++------- src/rabbit_access_control.erl | 8 ++++---- src/rabbit_amqqueue.erl | 19 ++++++++++--------- src/rabbit_channel.erl | 13 +++++++------ src/rabbit_error_logger.erl | 2 +- src/rabbit_exchange.erl | 15 +++++++-------- 6 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index 2c5fd614..2cd04d0a 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -213,16 +213,12 @@ insert_default_data() -> {ok, DefaultPass} = application:get_env(default_pass), {ok, DefaultVHost} = application:get_env(default_vhost), ok = rabbit_access_control:add_vhost(DefaultVHost), - ok = insert_default_user(DefaultUser, DefaultPass, - [{DefaultVHost, [<<"/data">>, <<"/admin">>]}]), + ok = insert_default_user(DefaultUser, DefaultPass,DefaultVHost), ok. -insert_default_user(Username, Password, VHostSpecs) -> +insert_default_user(Username, Password, VHostPath) -> ok = rabbit_access_control:add_user(Username, Password), - lists:foreach( - fun (VHostPath) -> - ok = rabbit_access_control:map_user_vhost(Username, VHostPath) - end, VHostSpecs), + ok = rabbit_access_control:map_user_vhost(Username, VHostPath), ok. start_builtin_amq_applications() -> diff --git a/src/rabbit_access_control.erl b/src/rabbit_access_control.erl index 0a410991..a53ea307 100644 --- a/src/rabbit_access_control.erl +++ b/src/rabbit_access_control.erl @@ -173,10 +173,10 @@ add_vhost(VHostPath) -> case mnesia:read({vhost, VHostPath}) of [] -> ok = mnesia:write(#vhost{virtual_host = VHostPath}), - #exchange{} = rabbit_exchange:declare(<<"">>, direct, true, false, []), - #exchange{} = rabbit_exchange:declare(<<"amq.direct">>, direct, true, false, []), - #exchange{} = rabbit_exchange:declare(<<"amq.topic">>, topic, true, false, []), - #exchange{} = rabbit_exchange:declare(<<"amq.fanout">>, fanout, true, false, []), + #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath,exchange,<<"">>), direct, true, false, []), + #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath,exchange,<<"amq.direct">>), direct, true, false, []), + #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath,exchange,<<"amq.topic">>), topic, true, false, []), + #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath,exchange,<<"amq.fanout">>), fanout, true, false, []), ok; [_] -> mnesia:abort({vhost_already_exists, VHostPath}) diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 5a9849df..7da0ab01 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -130,8 +130,8 @@ recover_durable_queues() -> ok end). -declare(NameBin, Durable, AutoDelete, Args) -> - Q = start_queue_process(#amqqueue{name = NameBin, +declare(Resource = #resource{name = Name}, Durable, AutoDelete, Args) -> + Q = start_queue_process(#amqqueue{name = Resource, durable = Durable, auto_delete = AutoDelete, arguments = Args, @@ -139,7 +139,7 @@ declare(NameBin, Durable, AutoDelete, Args) -> pid = none}), case rabbit_misc:execute_mnesia_transaction( fun () -> - case mnesia:wread({amqqueue, NameBin}) of + case mnesia:wread({amqqueue, Resource}) of [] -> ok = recover_queue(Q), Q; [ExistingQ] -> ExistingQ @@ -172,20 +172,22 @@ default_binding_spec(Name) -> routing_key = Name, arguments = []}. -recover_bindings(Q = #amqqueue{name = QueueName, binding_specs = Specs}) -> - ok = rabbit_exchange:add_binding(default_binding_spec(QueueName), Q), +recover_bindings(Q = #amqqueue{name = #resource{name = QueueName}, + binding_specs = Specs}) -> + % TODO I don't this should be commented out + %ok = rabbit_exchange:add_binding(default_binding_spec(QueueName), Q), lists:foreach(fun (B) -> ok = rabbit_exchange:add_binding(B, Q) end, Specs), ok. -modify_bindings(#resource{name = QueueName}, ExchangeName, RoutingKey, Arguments, +modify_bindings(Queue = #resource{name = QueueName}, X = #resource{name = ExchangeName}, RoutingKey, Arguments, SpecPresentFun, SpecAbsentFun) -> rabbit_misc:execute_mnesia_transaction( fun () -> - case mnesia:wread({amqqueue, QueueName}) of + case mnesia:wread({amqqueue, Queue}) of [Q = #amqqueue{binding_specs = Specs0}] -> - Spec = #binding_spec{exchange_name = ExchangeName, + Spec = #binding_spec{exchange_name = X, routing_key = RoutingKey, arguments = Arguments}, case (case lists:member(Spec, Specs0) of @@ -242,7 +244,6 @@ delete_binding(QueueName, ExchangeName, RoutingKey, Arguments) -> lookup(Name) -> rabbit_misc:dirty_read({amqqueue, Name}). -with(#resource{name = Name}, F, E) -> with(Name, F, E); with(Name, F, E) -> case lookup(Name) of {ok, Q} -> rabbit_misc:with_exit_handler(E, fun () -> F(Q) end); diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index e1a6b4e6..05ce07f2 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -161,7 +161,8 @@ return_queue_declare_ok(State, NoWait, Q) -> rabbit_misc:with_exit_handler( fun () -> {ok, Q#amqqueue.name, 0, 0} end, fun () -> rabbit_amqqueue:stat(Q) end), - Reply = #'queue.declare_ok'{queue = ActualName, + QueueName = ActualName#resource.name, + Reply = #'queue.declare_ok'{queue = QueueName, message_count = MessageCount, consumer_count = ConsumerCount}, {reply, Reply, NewState} @@ -462,12 +463,12 @@ handle_method(#'exchange.declare'{ticket = TicketNumber, _, State = #ch{ virtual_host = VHostPath }) -> CheckedType = rabbit_exchange:check_type(TypeNameBin), %% FIXME: clarify spec as per declare wrt differing realms - X = case rabbit_exchange:lookup( - rabbit_misc:r(VHostPath, exchange, ExchangeNameBin)) of + ExchangeName = rabbit_misc:r(VHostPath, exchange, ExchangeNameBin), + X = case rabbit_exchange:lookup(ExchangeName) of {ok, FoundX} -> FoundX; {error, not_found} -> ActualNameBin = check_name('exchange', ExchangeNameBin), - rabbit_exchange:declare(ActualNameBin, + rabbit_exchange:declare(ExchangeName, CheckedType, Durable, AutoDelete, @@ -544,7 +545,7 @@ handle_method(#'queue.declare'{ticket = TicketNumber, <<>> -> rabbit_misc:binstring_guid("amq.gen"); Other -> check_name('queue', Other) end, - Finish(rabbit_amqqueue:declare(ActualNameBin, + Finish(rabbit_amqqueue:declare(rabbit_misc:r(VHostPath, queue, ActualNameBin), Durable, AutoDelete, Args)); @@ -567,7 +568,7 @@ handle_method(#'queue.delete'{ticket = TicketNumber, if_empty = IfEmpty, nowait = NoWait }, - _, State) -> + _, State = #ch{ virtual_host = VHostPath }) -> QueueName = expand_queue_name_shortcut(QueueNameBin, State), case rabbit_amqqueue:with_or_die( QueueName, diff --git a/src/rabbit_error_logger.erl b/src/rabbit_error_logger.erl index 5bc538d5..e4ce3aa3 100644 --- a/src/rabbit_error_logger.erl +++ b/src/rabbit_error_logger.erl @@ -34,7 +34,7 @@ init([DefaultVHost]) -> #exchange{} = rabbit_exchange:declare( - ?LOG_EXCH_NAME, + rabbit_misc:r(DefaultVHost,exchange,?LOG_EXCH_NAME), topic, true, false, []), {ok, #resource{virtual_host = DefaultVHost, kind = exchange, diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 380ff243..970e874a 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -90,15 +90,15 @@ recover_durable_exchanges() -> end, ok, durable_exchanges) end). -declare(NameBin, Type, Durable, AutoDelete, Args) -> - Exchange = #exchange{name = NameBin, +declare(Resource = #resource{name = Name}, Type, Durable, AutoDelete, Args) -> + Exchange = #exchange{name = Resource, type = Type, durable = Durable, auto_delete = AutoDelete, arguments = Args}, rabbit_misc:execute_mnesia_transaction( fun () -> - case mnesia:wread({exchange, NameBin}) of + case mnesia:wread({exchange, Resource}) of [] -> ok = mnesia:write(Exchange), if Durable -> ok = mnesia:write( @@ -131,9 +131,8 @@ assert_type(#exchange{ name = Name, type = ActualType }, RequiredType) -> lookup(Name) -> rabbit_misc:dirty_read({exchange, Name}). -lookup_or_die(#resource{name = Name}) -> lookup_or_die(Name); -lookup_or_die(Name) -> - case lookup(Name) of +lookup_or_die(Resource = #resource{name = Name}) -> + case lookup(Resource) of {ok, X} -> X; {error, not_found} -> rabbit_misc:protocol_error( @@ -152,6 +151,7 @@ list_exchange_bindings(Name) -> queue = QueueName} <- Handlers]. bindings_for_exchange(Name) -> + Q1 = qlc:e(qlc:q([B1 || B1 = #binding{} <- mnesia:table(binding)])), qlc:e(qlc:q([B || B = #binding{key = K} <- mnesia:table(binding), element(1, K) == Name])). @@ -216,7 +216,7 @@ delivery_key_for_type(fanout, Name, _RoutingKey) -> delivery_key_for_type(_Type, Name, RoutingKey) -> {Name, RoutingKey}. -call_with_exchange(#resource{name = Name}, Fun) -> call_with_exchange(Name, Fun); +%call_with_exchange(R = #resource{name = Name}, Fun) -> call_with_exchange(R, Fun); call_with_exchange(Name, Fun) -> case mnesia:wread({exchange, Name}) of [] -> {error, not_found}; @@ -334,7 +334,6 @@ last_topic_match(P, R, []) -> last_topic_match(P, R, [BacktrackNext | BacktrackList]) -> topic_matches1(P, R) or last_topic_match(P, [BacktrackNext | R], BacktrackList). -delete(#resource{name = ExchangeName}, IfUnused) -> delete(ExchangeName, IfUnused); delete(ExchangeName, IfUnused) -> rabbit_misc:execute_mnesia_transaction( fun () -> internal_delete(ExchangeName, IfUnused) end). -- cgit v1.2.1 From d9b8cf315ac294dbf937bfaec172c0f426752542 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Mon, 21 Jul 2008 19:44:56 +0100 Subject: Deleted superfluous qlc statement --- src/rabbit_exchange.erl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 970e874a..0a5f0aad 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -151,7 +151,6 @@ list_exchange_bindings(Name) -> queue = QueueName} <- Handlers]. bindings_for_exchange(Name) -> - Q1 = qlc:e(qlc:q([B1 || B1 = #binding{} <- mnesia:table(binding)])), qlc:e(qlc:q([B || B = #binding{key = K} <- mnesia:table(binding), element(1, K) == Name])). -- cgit v1.2.1 From 834f77f3ce997d846ee4710940e5508566f2b0a6 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Tue, 22 Jul 2008 09:06:22 +0100 Subject: Converted some tabs to spaces --- src/rabbit_exchange.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 0a5f0aad..b09ac24e 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -145,10 +145,10 @@ list_vhost_exchanges(VHostPath) -> list_exchange_bindings(Name) -> [{QueueName, RoutingKey, Arguments} || - #binding{handlers = Handlers} <- bindings_for_exchange(Name), - #handler{binding_spec = #binding_spec{routing_key = RoutingKey, - arguments = Arguments}, - queue = QueueName} <- Handlers]. + #binding{handlers = Handlers} <- bindings_for_exchange(Name), + #handler{binding_spec = #binding_spec{routing_key = RoutingKey, + arguments = Arguments}, + queue = QueueName} <- Handlers]. bindings_for_exchange(Name) -> qlc:e(qlc:q([B || -- cgit v1.2.1 From 0b8916a1b7f354d1936a75115b5cdc4b7b0cc817 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Tue, 22 Jul 2008 10:25:51 +0100 Subject: Put the default bindings back in --- src/rabbit_amqqueue.erl | 10 ++++------ src/rabbit_exchange.erl | 6 ++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 7da0ab01..2ca78699 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -167,15 +167,13 @@ recover_queue(Q) -> ok = recover_bindings(Q), ok. -default_binding_spec(Name) -> - #binding_spec{exchange_name = <<>>, +default_binding_spec(#resource{virtual_host = VHostPath, name = Name}) -> + #binding_spec{exchange_name = rabbit_misc:r(VHostPath,exchange,<<"">>), routing_key = Name, arguments = []}. -recover_bindings(Q = #amqqueue{name = #resource{name = QueueName}, - binding_specs = Specs}) -> - % TODO I don't this should be commented out - %ok = rabbit_exchange:add_binding(default_binding_spec(QueueName), Q), +recover_bindings(Q = #amqqueue{name = QueueName, binding_specs = Specs}) -> + ok = rabbit_exchange:add_binding(default_binding_spec(QueueName), Q), lists:foreach(fun (B) -> ok = rabbit_exchange:add_binding(B, Q) end, Specs), diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index b09ac24e..5a462e4b 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -151,9 +151,8 @@ list_exchange_bindings(Name) -> queue = QueueName} <- Handlers]. bindings_for_exchange(Name) -> - qlc:e(qlc:q([B || - B = #binding{key = K} <- mnesia:table(binding), - element(1, K) == Name])). + qlc:e(qlc:q([B || B = #binding{key = K} <- mnesia:table(binding), + element(1, K) == Name])). empty_handlers() -> []. @@ -215,7 +214,6 @@ delivery_key_for_type(fanout, Name, _RoutingKey) -> delivery_key_for_type(_Type, Name, RoutingKey) -> {Name, RoutingKey}. -%call_with_exchange(R = #resource{name = Name}, Fun) -> call_with_exchange(R, Fun); call_with_exchange(Name, Fun) -> case mnesia:wread({exchange, Name}) of [] -> {error, not_found}; -- cgit v1.2.1 From 2f7b2c9dae6726b65d5e1436fdb37b47aeba1c11 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Tue, 22 Jul 2008 10:50:34 +0100 Subject: Deleted a lot of stuff to do with permissions --- src/rabbit_control.erl | 67 +------------------------------------------------- src/rabbit_tests.erl | 51 -------------------------------------- 2 files changed, 1 insertion(+), 117 deletions(-) diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 9f95df1e..12040725 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -88,10 +88,6 @@ Available commands: list_user_vhosts list_vhost_users - add_realm - delete_realm - list_realms - set_permissions [ ...] Permissions management. The available permissions are 'passive', 'active', 'write' and 'read', corresponding to the permissions @@ -182,68 +178,7 @@ action(list_user_vhosts, Node, Args = [_Username]) -> action(list_vhost_users, Node, Args = [_VHostPath]) -> io:format("Listing users for vhosts ~p...", Args), - display_list(call(Node, {rabbit_access_control, list_vhost_users, Args})); - -action(add_realm, Node, [VHostPath, RealmName]) -> - io:format("Adding realm ~p to vhost ~p ...", [RealmName, VHostPath]), - rpc_call(Node, rabbit_realm, add_realm, - [realm_rsrc(VHostPath, RealmName)]); - -action(delete_realm, Node, [VHostPath, RealmName]) -> - io:format("Deleting realm ~p from vhost ~p ...", [RealmName, VHostPath]), - rpc_call(Node, rabbit_realm, delete_realm, - [realm_rsrc(VHostPath, RealmName)]); - -action(list_realms, Node, Args = [_VHostPath]) -> - io:format("Listing realms for vhost ~p ...", Args), - display_list(call(Node, {rabbit_realm, list_vhost_realms, Args})); - -% action(set_permissions, Node, -% [Username, VHostPath, RealmName | Permissions]) -> -% io:format("Setting permissions for user ~p, vhost ~p, realm ~p ...", -% [Username, VHostPath, RealmName]), -% CheckedPermissions = check_permissions(Permissions), -% Ticket = #ticket{ -% realm_name = realm_rsrc(VHostPath, RealmName), -% passive_flag = lists:member(passive, CheckedPermissions), -% active_flag = lists:member(active, CheckedPermissions), -% write_flag = lists:member(write, CheckedPermissions), -% read_flag = lists:member(read, CheckedPermissions)}, -% rpc_call(Node, rabbit_access_control, map_user_realm, -% [list_to_binary(Username), Ticket]); - -action(list_permissions, Node, Args = [_Username, _VHostPath]) -> - io:format("Listing permissions for user ~p in vhost ~p ...", Args), - Perms = call(Node, {rabbit_access_control, list_user_realms, Args}), - if is_list(Perms) -> - lists:foreach( - fun ({RealmName, Pattern}) -> - io:format("~n~s: ~p", - [binary_to_list(RealmName), - rabbit_misc:permission_list(Pattern)]) - end, - lists:sort(Perms)), - io:nl(), - ok; - true -> Perms - end. - -check_permissions([]) -> []; -check_permissions(["all" | R]) -> - [passive, active, write, read | check_permissions(R)]; -check_permissions([P | R]) when (P == "passive") or - (P == "active") or - (P == "write") or - (P == "read") -> - [list_to_atom(P) | check_permissions(R)]; -check_permissions([P | _R]) -> - io:format("~nError: invalid permission flag ~p~n", [P]), - usage(). - -realm_rsrc(VHostPath, RealmName) -> - rabbit_misc:r(list_to_binary(VHostPath), - realm, - list_to_binary(RealmName)). + display_list(call(Node, {rabbit_access_control, list_vhost_users, Args})). display_list(L) when is_list(L) -> lists:foreach(fun (I) -> diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index beeb3508..6f43b08a 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -284,31 +284,12 @@ test_user_management() -> control_action(unmap_user_vhost, ["foo", "/"]), {error, {no_such_user, _}} = control_action(list_user_vhosts, ["foo"]), - {error, {no_such_user, _}} = - control_action(set_permissions, ["foo", "/", "/data"]), - {error, {no_such_user, _}} = - control_action(list_permissions, ["foo", "/"]), {error, {no_such_vhost, _}} = control_action(map_user_vhost, ["guest", "/testhost"]), {error, {no_such_vhost, _}} = control_action(unmap_user_vhost, ["guest", "/testhost"]), {error, {no_such_vhost, _}} = control_action(list_vhost_users, ["/testhost"]), - {error, {no_such_vhost, _}} = - control_action(set_permissions, ["guest", "/testhost", "/data"]), - {error, {no_such_vhost, _}} = - control_action(list_permissions, ["guest", "/testhost"]), - {error, {no_such_vhost, _}} = - control_action(add_realm, ["/testhost", "/data/test"]), - {error, {no_such_vhost, _}} = - control_action(delete_realm, ["/testhost", "/data/test"]), - {error, {no_such_vhost, _}} = - control_action(list_realms, ["/testhost"]), - {error, {no_such_realm, _}} = - control_action(set_permissions, ["guest", "/", "/data/test"]), - {error, {no_such_realm, _}} = - control_action(delete_realm, ["/", "/data/test"]), - %% user creation ok = control_action(add_user, ["foo", "bar"]), {error, {user_already_exists, _}} = @@ -327,32 +308,6 @@ test_user_management() -> ok = control_action(map_user_vhost, ["foo", "/testhost"]), ok = control_action(list_user_vhosts, ["foo"]), - %% realm creation - ok = control_action(add_realm, ["/testhost", "/data/test"]), - {error, {realm_already_exists, _}} = - control_action(add_realm, ["/testhost", "/data/test"]), - ok = control_action(list_realms, ["/testhost"]), - - %% user permissions - ok = control_action(set_permissions, - ["foo", "/testhost", "/data/test", - "passive", "active", "write", "read"]), - ok = control_action(list_permissions, ["foo", "/testhost"]), - ok = control_action(set_permissions, - ["foo", "/testhost", "/data/test", "all"]), - ok = control_action(set_permissions, - ["foo", "/testhost", "/data/test"]), - {error, not_mapped_to_vhost} = - control_action(set_permissions, - ["guest", "/testhost", "/data/test"]), - {error, not_mapped_to_vhost} = - control_action(list_permissions, ["guest", "/testhost"]), - - %% realm deletion - ok = control_action(delete_realm, ["/testhost", "/data/test"]), - {error, {no_such_realm, _}} = - control_action(delete_realm, ["/testhost", "/data/test"]), - %% user/vhost unmapping ok = control_action(unmap_user_vhost, ["foo", "/testhost"]), ok = control_action(unmap_user_vhost, ["foo", "/testhost"]), @@ -364,13 +319,7 @@ test_user_management() -> %% deleting a populated vhost ok = control_action(add_vhost, ["/testhost"]), - ok = control_action(add_realm, ["/testhost", "/data/test"]), ok = control_action(map_user_vhost, ["foo", "/testhost"]), - ok = control_action(set_permissions, - ["foo", "/testhost", "/data/test", "all"]), - _ = rabbit_amqqueue:declare( - rabbit_misc:r(<<"/testhost">>, realm, <<"/data/test">>), - <<"bar">>, true, false, []), ok = control_action(delete_vhost, ["/testhost"]), %% user deletion -- cgit v1.2.1 From 0d9d88f384a5bdce8ab843052975b3d2f68cadd9 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Tue, 22 Jul 2008 15:02:39 +0100 Subject: Removed some unused fields --- src/rabbit_amqqueue.erl | 6 +++--- src/rabbit_channel.erl | 48 +++++++++++++++--------------------------------- src/rabbit_exchange.erl | 2 +- src/rabbit_misc.erl | 15 --------------- 4 files changed, 19 insertions(+), 52 deletions(-) diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 2ca78699..c3fac998 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -130,7 +130,7 @@ recover_durable_queues() -> ok end). -declare(Resource = #resource{name = Name}, Durable, AutoDelete, Args) -> +declare(Resource = #resource{}, Durable, AutoDelete, Args) -> Q = start_queue_process(#amqqueue{name = Resource, durable = Durable, auto_delete = AutoDelete, @@ -179,7 +179,7 @@ recover_bindings(Q = #amqqueue{name = QueueName, binding_specs = Specs}) -> end, Specs), ok. -modify_bindings(Queue = #resource{name = QueueName}, X = #resource{name = ExchangeName}, RoutingKey, Arguments, +modify_bindings(Queue = #resource{}, X = #resource{}, RoutingKey, Arguments, SpecPresentFun, SpecAbsentFun) -> rabbit_misc:execute_mnesia_transaction( fun () -> @@ -349,7 +349,7 @@ delete_temp(Q = #amqqueue{name = QueueName}) -> ok = mnesia:delete({amqqueue, QueueName}), ok. -delete_queue(Q = #amqqueue{name = QueueName, durable = Durable}) -> +delete_queue(Q = #amqqueue{}) -> ok = delete_temp(Q). on_node_down(Node) -> diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 05ce07f2..144253f8 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -229,16 +229,9 @@ handle_method(#'channel.close'{}, _, State = #ch{writer_pid = WriterPid}) -> ok = rabbit_writer:shutdown(WriterPid), stop; -handle_method(#'access.request'{realm = RealmNameBin, - exclusive = Exclusive, - passive = Passive, - active = Active, - write = Write, - read = Read},_, State) -> - {reply, #'access.request_ok'{ticket = 1}, State}; - -handle_method(#'basic.publish'{ticket = TicketNumber, - exchange = ExchangeNameBin, +handle_method(#'access.request'{},_, State) -> {reply, #'access.request_ok'{ticket = 1}, State}; + +handle_method(#'basic.publish'{exchange = ExchangeNameBin, routing_key = RoutingKey, mandatory = Mandatory, immediate = Immediate}, @@ -281,8 +274,7 @@ handle_method(#'basic.ack'{delivery_tag = DeliveryTag, uncommitted_ack_q = NewUAQ}) end}; -handle_method(#'basic.get'{ticket = TicketNumber, - queue = QueueNameBin, +handle_method(#'basic.get'{queue = QueueNameBin, no_ack = NoAck}, _, State = #ch{ proxy_pid = ProxyPid, writer_pid = WriterPid, next_tag = DeliveryTag }) -> @@ -309,8 +301,7 @@ handle_method(#'basic.get'{ticket = TicketNumber, {reply, #'basic.get_empty'{cluster_id = <<>>}, State} end; -handle_method(#'basic.consume'{ticket = TicketNumber, - queue = QueueNameBin, +handle_method(#'basic.consume'{queue = QueueNameBin, consumer_tag = ConsumerTag, no_local = _, % FIXME: implement no_ack = NoAck, @@ -451,8 +442,7 @@ handle_method(#'basic.recover'{}, _, _State) -> rabbit_misc:protocol_error( not_allowed, "attempt to recover a transactional channel",[]); -handle_method(#'exchange.declare'{ticket = TicketNumber, - exchange = ExchangeNameBin, +handle_method(#'exchange.declare'{exchange = ExchangeNameBin, type = TypeNameBin, passive = false, durable = Durable, @@ -467,7 +457,7 @@ handle_method(#'exchange.declare'{ticket = TicketNumber, X = case rabbit_exchange:lookup(ExchangeName) of {ok, FoundX} -> FoundX; {error, not_found} -> - ActualNameBin = check_name('exchange', ExchangeNameBin), + check_name('exchange', ExchangeNameBin), rabbit_exchange:declare(ExchangeName, CheckedType, Durable, @@ -477,8 +467,7 @@ handle_method(#'exchange.declare'{ticket = TicketNumber, ok = rabbit_exchange:assert_type(X, CheckedType), return_ok(State, NoWait, #'exchange.declare_ok'{}); -handle_method(#'exchange.declare'{ticket = TicketNumber, - exchange = ExchangeNameBin, +handle_method(#'exchange.declare'{exchange = ExchangeNameBin, type = TypeNameBin, passive = true, nowait = NoWait}, @@ -488,8 +477,7 @@ handle_method(#'exchange.declare'{ticket = TicketNumber, ok = rabbit_exchange:assert_type(X, rabbit_exchange:check_type(TypeNameBin)), return_ok(State, NoWait, #'exchange.declare_ok'{}); -handle_method(#'exchange.delete'{ticket = TicketNumber, - exchange = ExchangeNameBin, +handle_method(#'exchange.delete'{exchange = ExchangeNameBin, if_unused = IfUnused, nowait = NoWait}, _, State = #ch { virtual_host = VHostPath }) -> @@ -505,8 +493,7 @@ handle_method(#'exchange.delete'{ticket = TicketNumber, return_ok(State, NoWait, #'exchange.delete_ok'{}) end; -handle_method(#'queue.declare'{ticket = TicketNumber, - queue = QueueNameBin, +handle_method(#'queue.declare'{queue = QueueNameBin, passive = false, durable = Durable, exclusive = ExclusiveDeclare, @@ -553,8 +540,7 @@ handle_method(#'queue.declare'{ticket = TicketNumber, end, return_queue_declare_ok(State, NoWait, Q); -handle_method(#'queue.declare'{ticket = TicketNumber, - queue = QueueNameBin, +handle_method(#'queue.declare'{queue = QueueNameBin, passive = true, nowait = NoWait}, _, State = #ch{ virtual_host = VHostPath }) -> @@ -562,13 +548,11 @@ handle_method(#'queue.declare'{ticket = TicketNumber, Q = rabbit_amqqueue:with_or_die(QueueName, fun (Q) -> Q end), return_queue_declare_ok(State, NoWait, Q); -handle_method(#'queue.delete'{ticket = TicketNumber, - queue = QueueNameBin, +handle_method(#'queue.delete'{queue = QueueNameBin, if_unused = IfUnused, if_empty = IfEmpty, nowait = NoWait - }, - _, State = #ch{ virtual_host = VHostPath }) -> + },_, State) -> QueueName = expand_queue_name_shortcut(QueueNameBin, State), case rabbit_amqqueue:with_or_die( QueueName, @@ -585,8 +569,7 @@ handle_method(#'queue.delete'{ticket = TicketNumber, message_count = PurgedMessageCount}) end; -handle_method(#'queue.bind'{ticket = TicketNumber, - queue = QueueNameBin, +handle_method(#'queue.bind'{queue = QueueNameBin, exchange = ExchangeNameBin, routing_key = RoutingKey, nowait = NoWait, @@ -614,8 +597,7 @@ handle_method(#'queue.bind'{ticket = TicketNumber, return_ok(State, NoWait, #'queue.bind_ok'{}) end; -handle_method(#'queue.purge'{ticket = TicketNumber, - queue = QueueNameBin, +handle_method(#'queue.purge'{queue = QueueNameBin, nowait = NoWait}, _, State) -> QueueName = expand_queue_name_shortcut(QueueNameBin, State), diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 5a462e4b..17d9fd97 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -90,7 +90,7 @@ recover_durable_exchanges() -> end, ok, durable_exchanges) end). -declare(Resource = #resource{name = Name}, Type, Durable, AutoDelete, Args) -> +declare(Resource = #resource{}, Type, Durable, AutoDelete, Args) -> Exchange = #exchange{name = Resource, type = Type, durable = Durable, diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 259dc0d8..c78a4ec3 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -121,21 +121,6 @@ protocol_error(Error, Explanation, Params, Method) -> CompleteExplanation = lists:flatten(io_lib:format(Explanation, Params)), exit({amqp, Error, CompleteExplanation, Method}). -boolean_config_param(Name, TrueValue, FalseValue, DefaultValue) -> - ActualValue = get_config(Name, DefaultValue), - if - ActualValue == TrueValue -> - true; - ActualValue == FalseValue -> - false; - true -> - rabbit_log:error( - "Bad setting for config param '~w': ~p~n" ++ - "legal values are '~w', '~w'; using default value '~w'", - [Name, ActualValue, TrueValue, FalseValue, DefaultValue]), - DefaultValue == TrueValue - end. - get_config(Key) -> case dirty_read({rabbit_config, Key}) of {ok, {rabbit_config, Key, V}} -> {ok, V}; -- cgit v1.2.1 From 7b76516c1bff9d54bd29ae37ac977272af4c08b6 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Thu, 24 Jul 2008 13:23:06 +0100 Subject: Freshen packaging changelogs --- packaging/RPMS/Fedora/rabbitmq-server.spec | 2 +- packaging/debs/Debian/debian/changelog | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec index ca0b6b8e..dd12e1e5 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.spec +++ b/packaging/RPMS/Fedora/rabbitmq-server.spec @@ -119,7 +119,7 @@ fi rm -rf $RPM_BUILD_ROOT %changelog -* Wed Jul 9 2008 Tony Garnock-Jones 1.4.0 +* Thu Jul 24 2008 Tony Garnock-Jones 1.4.0 - New upstream release * Mon Mar 3 2008 Adrien Pierard 1.3.0 diff --git a/packaging/debs/Debian/debian/changelog b/packaging/debs/Debian/debian/changelog index e6b12937..07f5a8dd 100644 --- a/packaging/debs/Debian/debian/changelog +++ b/packaging/debs/Debian/debian/changelog @@ -2,7 +2,7 @@ rabbitmq-server (1.4.0-1) testing; urgency=low * New Upstream Release - -- Tony Garnock-Jones Wed, 09 Jul 2008 14:31:23 +0100 + -- Tony Garnock-Jones Thu, 24 Jul 2008 13:21:48 +0100 rabbitmq-server (1.3.0-1) testing; urgency=low -- cgit v1.2.1 From f8499df1397a0f4b74eadb7614a3942a07091040 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Fri, 25 Jul 2008 11:59:45 +0100 Subject: Bug fix for basic-get, exposed by running qpid test suite --- src/rabbit_channel.erl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 144253f8..b02a3c0a 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -171,9 +171,7 @@ return_queue_declare_ok(State, NoWait, Q) -> expand_queue_name_shortcut(<<>>, #ch{ most_recently_declared_queue = <<>> }) -> rabbit_misc:protocol_error( not_allowed, "no previously declared queue", []); -expand_queue_name_shortcut(<<>>, #ch{ virtual_host = VHostPath, - most_recently_declared_queue = MRDQ }) -> - rabbit_misc:r(VHostPath, queue, MRDQ); +expand_queue_name_shortcut(<<>>, #ch{ most_recently_declared_queue = MRDQ }) -> MRDQ; expand_queue_name_shortcut(QueueNameBin, #ch{ virtual_host = VHostPath }) -> rabbit_misc:r(VHostPath, queue, QueueNameBin). -- cgit v1.2.1 From 9708ba0df8c8c620b80cf47fedff4d80292b11c6 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 28 Jul 2008 10:01:54 +0100 Subject: Move schema integrity check into the top of wait_for_tables. --- src/rabbit_mnesia.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl index 18df11fe..b8b437b0 100644 --- a/src/rabbit_mnesia.erl +++ b/src/rabbit_mnesia.erl @@ -263,7 +263,6 @@ init_db(ClusterNodes) -> ClusterNodes}}) end; {ok, [_|_]} -> - ok = ensure_schema_integrity(), ok = wait_for_tables(), ok = create_local_table_copies( case IsDiskNode of @@ -347,6 +346,7 @@ create_local_table_copy(Tab, Type) -> ok. wait_for_tables() -> + ok = ensure_schema_integrity(), case mnesia:wait_for_tables(table_names(), 30000) of ok -> ok; {timeout, BadTabs} -> -- cgit v1.2.1 From 6e59166e654530dac9a7405472320fbb6acf3f96 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 29 Jul 2008 15:33:44 +0100 Subject: Use dirname $0 consistently to find the ebin dir. --- scripts/rabbitmq-multi | 2 +- scripts/rabbitmq-server | 2 +- scripts/rabbitmqctl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/rabbitmq-multi b/scripts/rabbitmq-multi index 4709ca0b..5e4f4b38 100755 --- a/scripts/rabbitmq-multi +++ b/scripts/rabbitmq-multi @@ -36,7 +36,7 @@ SCRIPT_HOME=$(dirname $0) export NODENAME NODE_IP_ADDRESS NODE_PORT SCRIPT_HOME PIDS_FILE exec erl \ - -pa ../ebin \ + -pa "`dirname $0`/../ebin" \ -noinput \ -hidden \ ${ERL_ARGS} \ diff --git a/scripts/rabbitmq-server b/scripts/rabbitmq-server index a44dd6da..e5fb93cc 100755 --- a/scripts/rabbitmq-server +++ b/scripts/rabbitmq-server @@ -51,7 +51,7 @@ else fi erl \ - -pa $(dirname $0)/../ebin \ + -pa "`dirname $0`/../ebin" \ ${START_RABBIT} \ -sname ${NODENAME} \ -boot start_sasl \ diff --git a/scripts/rabbitmqctl b/scripts/rabbitmqctl index eb359dad..419dcf63 100755 --- a/scripts/rabbitmqctl +++ b/scripts/rabbitmqctl @@ -31,7 +31,7 @@ ERL_ARGS= MNESIA_DIR=${MNESIA_BASE}/${NODENAME} exec erl \ - -pa ../ebin \ + -pa "`dirname $0`/../ebin" \ -noinput \ -hidden \ ${ERL_ARGS} \ -- cgit v1.2.1 -- cgit v1.2.1 From d60d983b618591b13414d6ca7133f0c79710d485 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 29 Jul 2008 16:26:55 +0100 Subject: Use %~dp0 to find the ebin directory under windows --- scripts/rabbitmq-multi.bat | 2 +- scripts/rabbitmq-server.bat | 2 +- scripts/rabbitmqctl.bat | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/rabbitmq-multi.bat b/scripts/rabbitmq-multi.bat index 34e34ef9..d1b7b000 100644 --- a/scripts/rabbitmq-multi.bat +++ b/scripts/rabbitmq-multi.bat @@ -59,5 +59,5 @@ if not exist "%ERLANG_HOME%\bin\erl.exe" ( exit /B ) -"%ERLANG_HOME%\bin\erl.exe" -pa ../ebin -noinput -hidden -sname rabbitmq_multi -s rabbit_multi %START_ARGS% -extra %* +"%ERLANG_HOME%\bin\erl.exe" -pa "%~dp0..\ebin" -noinput -hidden -sname rabbitmq_multi -s rabbit_multi %START_ARGS% -extra %* diff --git a/scripts/rabbitmq-server.bat b/scripts/rabbitmq-server.bat index 46f4bd92..8b06c0b4 100644 --- a/scripts/rabbitmq-server.bat +++ b/scripts/rabbitmq-server.bat @@ -92,7 +92,7 @@ set CLUSTER_CONFIG=-rabbit cluster_config \""%CLUSTER_CONFIG_FILE:\=/%"\" set MNESIA_DIR=%MNESIA_BASE%/%NODENAME%-mnesia "%ERLANG_HOME%\bin\erl.exe" ^ --pa ..\ebin ^ +-pa "%~dp0..\ebin" ^ -noinput ^ -boot start_sasl ^ -sname %NODENAME% ^ diff --git a/scripts/rabbitmqctl.bat b/scripts/rabbitmqctl.bat index b34adebe..1ee7e825 100644 --- a/scripts/rabbitmqctl.bat +++ b/scripts/rabbitmqctl.bat @@ -40,4 +40,4 @@ if not exist "%ERLANG_HOME%\bin\erl.exe" ( exit /B ) -"%ERLANG_HOME%\bin\erl.exe" -pa ..\ebin -noinput -hidden -sname rabbitmqctl -s rabbit_control -extra %* +"%ERLANG_HOME%\bin\erl.exe" -pa "%~dp0..\ebin" -noinput -hidden -sname rabbitmqctl -s rabbit_control -extra %* -- cgit v1.2.1 From e01ce66f5ce26257e16a234bdb6131110675b2e0 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 29 Jul 2008 17:12:42 +0100 Subject: Propagate GNUPG_PATH properly; remove tag --- packaging/debs/Debian/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/debs/Debian/Makefile b/packaging/debs/Debian/Makefile index b49094e2..aeb958a7 100644 --- a/packaging/debs/Debian/Makefile +++ b/packaging/debs/Debian/Makefile @@ -20,7 +20,7 @@ package: clean cp -r debian $(UNPACKED_DIR) chmod -R a+x $(UNPACKED_DIR)/debian UNOFFICIAL_RELEASE=$(UNOFFICIAL_RELEASE) VERSION=$(VERSION) ./check-changelog.sh rabbitmq-server $(UNPACKED_DIR) - cd $(UNPACKED_DIR); dpkg-buildpackage -rfakeroot $(SIGNING) + cd $(UNPACKED_DIR); GNUPGHOME=$(GNUPG_PATH)/.gnupg dpkg-buildpackage -rfakeroot $(SIGNING) rm -rf $(UNPACKED_DIR) clean: -- cgit v1.2.1 -- cgit v1.2.1 From 5d4aa65215de155534782159d9a343ffae9f1cd6 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Mon, 4 Aug 2008 16:04:10 +0100 Subject: Removed some references to realms --- src/rabbit_channel.erl | 10 ++++------ src/rabbit_control.erl | 7 ------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index b02a3c0a..426cbd78 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -93,7 +93,7 @@ init(ProxyPid, [ReaderPid, WriterPid, Username, VHost]) -> unacked_message_q = queue:new(), username = Username, virtual_host = VHost, - most_recently_declared_queue = <<>>, + most_recently_declared_queue = none, consumer_mapping = dict:new()}. handle_message({method, Method, Content}, State) -> @@ -168,7 +168,7 @@ return_queue_declare_ok(State, NoWait, Q) -> {reply, Reply, NewState} end. -expand_queue_name_shortcut(<<>>, #ch{ most_recently_declared_queue = <<>> }) -> +expand_queue_name_shortcut(<<>>, #ch{ most_recently_declared_queue = none }) -> rabbit_misc:protocol_error( not_allowed, "no previously declared queue", []); expand_queue_name_shortcut(<<>>, #ch{ most_recently_declared_queue = MRDQ }) -> MRDQ; @@ -176,7 +176,7 @@ expand_queue_name_shortcut(QueueNameBin, #ch{ virtual_host = VHostPath }) -> rabbit_misc:r(VHostPath, queue, QueueNameBin). expand_routing_key_shortcut(<<>>, <<>>, - #ch{ most_recently_declared_queue = <<>> }) -> + #ch{ most_recently_declared_queue = none }) -> rabbit_misc:protocol_error( not_allowed, "no previously declared queue", []); expand_routing_key_shortcut(<<>>, <<>>, @@ -336,7 +336,7 @@ handle_method(#'basic.consume'{queue = QueueNameBin, ConsumerMapping)}}; {error, queue_owned_by_another_connection} -> %% The spec is silent on which exception to use - %% here. This seems reasonable? + %% here. This seems reasonable? %% FIXME: check this rabbit_misc:protocol_error( @@ -450,7 +450,6 @@ handle_method(#'exchange.declare'{exchange = ExchangeNameBin, arguments = Args}, _, State = #ch{ virtual_host = VHostPath }) -> CheckedType = rabbit_exchange:check_type(TypeNameBin), - %% FIXME: clarify spec as per declare wrt differing realms ExchangeName = rabbit_misc:r(VHostPath, exchange, ExchangeNameBin), X = case rabbit_exchange:lookup(ExchangeName) of {ok, FoundX} -> FoundX; @@ -520,7 +519,6 @@ handle_method(#'queue.declare'{queue = QueueNameBin, end, Q end, - %% FIXME: clarify spec as per declare wrt differing realms Q = case rabbit_amqqueue:with( rabbit_misc:r(VHostPath, queue, QueueNameBin), Finish) of diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 12040725..eb24b782 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -88,13 +88,6 @@ Available commands: list_user_vhosts list_vhost_users - set_permissions [ ...] - Permissions management. The available permissions are 'passive', - 'active', 'write' and 'read', corresponding to the permissions - referred to in AMQP's \"access.request\" message, or 'all' as an - abbreviation for all defined permission flags. - list_permissions - should be the name of the master node of the RabbitMQ cluster. It defaults to the node named \"rabbit\" on the local host. On a host named \"server.example.com\", the master node will usually be rabbit@server (unless -- cgit v1.2.1 From 23eaa6734af7958159acedbddeb29adc4fe85beb Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Mon, 4 Aug 2008 18:18:13 +0100 Subject: Create build file only with server build instructions. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a32a89ea..48214605 100644 --- a/Makefile +++ b/Makefile @@ -106,7 +106,7 @@ generic_stage: elinks -dump -no-references -no-numbering $(WEB_URL)install.html \ >> $(GENERIC_STAGE_DIR)/INSTALL; \ cp BUILD.in $(GENERIC_STAGE_DIR)/BUILD; \ - elinks -dump -no-references -no-numbering $(WEB_URL)build.html \ + elinks -dump -no-references -no-numbering $(WEB_URL)build-server.html \ >> $(GENERIC_STAGE_DIR)/BUILD; \ else \ cp INSTALL $(GENERIC_STAGE_DIR); \ -- cgit v1.2.1 From 3656f974861d8d71112472614ae507632d4c2e33 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Mon, 4 Aug 2008 18:24:45 +0100 Subject: Changed url for server's build page. --- BUILD.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD.in b/BUILD.in index b013bc3c..0e70d0e7 100644 --- a/BUILD.in +++ b/BUILD.in @@ -1,4 +1,4 @@ -Please see http://www.rabbitmq.com/build.html for build +Please see http://www.rabbitmq.com/build-server.html for build instructions. For your convenience, a text copy of these instructions is available -- cgit v1.2.1 From a0986afcf94474c3860d2773c5f82039887b3595 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Tue, 5 Aug 2008 11:56:57 +0100 Subject: drop incremental dialysis it never worked particularly well and the dialyzer command line has changed in R12B-3 to break it completely. --- Makefile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index a32a89ea..83c8454d 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,6 @@ EBIN_DIR=ebin INCLUDE_DIR=include SOURCES=$(wildcard $(SOURCE_DIR)/*.erl) TARGETS=$(EBIN_DIR)/rabbit_framing.beam $(patsubst $(SOURCE_DIR)/%.erl, $(EBIN_DIR)/%.beam,$(SOURCES)) -PLT=rabbit.plt WEB_URL=http://stage.rabbitmq.com/ ifndef USE_SPECS @@ -47,16 +46,13 @@ $(INCLUDE_DIR)/rabbit_framing.hrl $(SOURCE_DIR)/rabbit_framing.erl: codegen.py $ $(EBIN_DIR)/rabbit.boot $(EBIN_DIR)/rabbit.script: $(EBIN_DIR)/rabbit.app $(EBIN_DIR)/rabbit.rel $(TARGETS) erl -noshell -eval 'systools:make_script("ebin/rabbit", [{path, ["ebin"]}]), halt().' -$(PLT): $(TARGETS) - dialyzer -c $? --output_plt $@ $(shell if [ -f $@ ] ; then echo "--plt $@"; fi) - -dialyze: $(PLT) +dialyze: $(TARGETS) + dialyzer -c $? clean: cleandb rm -f $(EBIN_DIR)/*.beam rm -f $(EBIN_DIR)/rabbit.boot $(EBIN_DIR)/rabbit.script rm -f $(INCLUDE_DIR)/rabbit_framing.hrl $(SOURCE_DIR)/rabbit_framing.erl codegen.pyc - rm -f $(PLT) cleandb: stop-node erl -mnesia dir '"$(MNESIA_DIR)"' -noshell -eval 'lists:foreach(fun file:delete/1, filelib:wildcard(mnesia:system_info(directory) ++ "/*")), halt().' -- cgit v1.2.1 From 837b2f545158dc07cbf855ed7782468839240db5 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Tue, 5 Aug 2008 13:07:26 +0100 Subject: Fixed specification for declare --- src/rabbit_amqqueue.erl | 8 ++++---- src/rabbit_exchange.erl | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index c3fac998..f19249f6 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -55,7 +55,7 @@ {'error', 'queue_not_found' | 'exchange_not_found'}). -spec(start/0 :: () -> 'ok'). -spec(recover/0 :: () -> 'ok'). --spec(declare/4 :: (name(), bool(), bool(), amqp_table()) -> +-spec(declare/4 :: (r(amqqueue), bool(), bool(), amqp_table()) -> amqqueue()). -spec(add_binding/4 :: (queue_name(), exchange_name(), routing_key(), amqp_table()) -> @@ -249,7 +249,7 @@ with(Name, F, E) -> end. with(Name, F) -> - with(Name, F, fun () -> {error, not_found} end). + with(Name, F, fun () -> {error, not_found} end). with_or_die(Name, F) -> with(Name, F, fun () -> rabbit_misc:protocol_error( not_found, "no ~s", [rabbit_misc:rs(Name)]) @@ -351,8 +351,8 @@ delete_temp(Q = #amqqueue{name = QueueName}) -> delete_queue(Q = #amqqueue{}) -> ok = delete_temp(Q). - -on_node_down(Node) -> + +on_node_down(Node) -> rabbit_misc:execute_mnesia_transaction( fun () -> qlc:fold( diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index 17d9fd97..ccda0d36 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -50,21 +50,21 @@ not_found() | {'error', 'unroutable' | 'not_delivered'}). -spec(recover/0 :: () -> 'ok'). --spec(declare/5 :: (name(), exchange_type(), bool(), bool(), +-spec(declare/5 :: (r(exchange), exchange_type(), bool(), bool(), amqp_table()) -> exchange()). -spec(check_type/1 :: (binary()) -> atom()). --spec(assert_type/2 :: (exchange(), atom()) -> 'ok'). +-spec(assert_type/2 :: (exchange(), atom()) -> 'ok'). -spec(lookup/1 :: (exchange_name()) -> {'ok', exchange()} | not_found()). -spec(lookup_or_die/1 :: (exchange_name()) -> exchange()). -spec(list_vhost_exchanges/1 :: (vhost()) -> [exchange()]). --spec(list_exchange_bindings/1 :: (exchange_name()) -> +-spec(list_exchange_bindings/1 :: (exchange_name()) -> [{queue_name(), routing_key(), amqp_table()}]). -spec(simple_publish/6 :: (bool(), bool(), exchange_name(), routing_key(), binary(), binary()) -> publish_res()). -spec(simple_publish/3 :: (bool(), bool(), message()) -> publish_res()). -spec(route/2 :: (exchange(), routing_key()) -> [pid()]). --spec(add_binding/2 :: (binding_spec(), amqqueue()) -> +-spec(add_binding/2 :: (binding_spec(), amqqueue()) -> 'ok' | not_found() | {'error', 'durability_settings_incompatible'}). -spec(delete_binding/2 :: (binding_spec(), amqqueue()) -> @@ -184,7 +184,7 @@ simple_publish(Mandatory, Immediate, %% return the list of qpids to which a message with a given routing %% key, sent to a particular exchange, should be delivered. -%% +%% %% The function ensures that a qpid appears in the return list exactly %% as many times as a message should be delivered to it. With the %% current exchange types that is at most once. @@ -194,7 +194,7 @@ route(#exchange{name = Name, type = topic}, RoutingKey) -> mnesia:activity( async_dirty, fun () -> - qlc:e(qlc:q([handler_qpids(H) || + qlc:e(qlc:q([handler_qpids(H) || #binding{key = {Name1, PatternKey}, handlers = H} <- mnesia:table(binding), @@ -287,7 +287,7 @@ add_handler_to_binding(BindingKey, Handler) -> ok = mnesia:write( B#binding{handlers = extend_handlers(H, Handler)}) end. - + %% Must run within a transaction. remove_handler_from_binding(BindingKey, Handler) -> case mnesia:wread({binding, BindingKey}) of -- cgit v1.2.1 From 881276ca179878cd50f994941b1a93398e5dbdbb Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Tue, 5 Aug 2008 13:55:31 +0100 Subject: Put some spaces between the commas, left stuff that didnt get changed on this branch --- src/rabbit.erl | 14 +++++++------- src/rabbit_access_control.erl | 10 +++++----- src/rabbit_amqqueue.erl | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index 2cd04d0a..f11e87bc 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -98,7 +98,7 @@ manage_applications(Iterate, Do, Undo, SkipError, ErrorTag, Apps) -> end end, [], Apps), ok. - + start_applications(Apps) -> manage_applications(fun lists:foldl/3, fun application:start/1, @@ -128,9 +128,9 @@ start(normal, []) -> io:format("starting ~-20s ...", [Msg]), Thunk(), io:format("done~n"); - ({Msg, M, F, A}) -> + ({Msg, M, F, A}) -> io:format("starting ~-20s ...", [Msg]), - apply(M, F, A), + apply(M, F, A), io:format("done~n") end, [{"database", @@ -154,8 +154,8 @@ start(normal, []) -> ok = rabbit_amqqueue:recover() end}, {"persister", - fun () -> - ok = start_child(rabbit_persister) + fun () -> + ok = start_child(rabbit_persister) end}, {"builtin applications", fun () -> @@ -213,7 +213,7 @@ insert_default_data() -> {ok, DefaultPass} = application:get_env(default_pass), {ok, DefaultVHost} = application:get_env(default_vhost), ok = rabbit_access_control:add_vhost(DefaultVHost), - ok = insert_default_user(DefaultUser, DefaultPass,DefaultVHost), + ok = insert_default_user(DefaultUser, DefaultPass, DefaultVHost), ok. insert_default_user(Username, Password, VHostPath) -> @@ -257,7 +257,7 @@ error_log_location() -> end. sasl_log_location() -> - case application:get_env(sasl, sasl_error_logger) of + case application:get_env(sasl, sasl_error_logger) of {ok, {file, File}} -> File; {ok, false} -> undefined; {ok, tty} -> tty; diff --git a/src/rabbit_access_control.erl b/src/rabbit_access_control.erl index a53ea307..c926eacb 100644 --- a/src/rabbit_access_control.erl +++ b/src/rabbit_access_control.erl @@ -82,7 +82,7 @@ check_login(<<"AMQPLAIN">>, Response) -> [LoginTable]) end; -check_login(Mechanism, _Response) -> +check_login(Mechanism, _Response) -> rabbit_misc:protocol_error( access_refused, "unsupported authentication mechanism '~s'", [Mechanism]). @@ -173,10 +173,10 @@ add_vhost(VHostPath) -> case mnesia:read({vhost, VHostPath}) of [] -> ok = mnesia:write(#vhost{virtual_host = VHostPath}), - #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath,exchange,<<"">>), direct, true, false, []), - #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath,exchange,<<"amq.direct">>), direct, true, false, []), - #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath,exchange,<<"amq.topic">>), topic, true, false, []), - #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath,exchange,<<"amq.fanout">>), fanout, true, false, []), + #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath, exchange, <<"">>), direct, true, false, []), + #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath, exchange, <<"amq.direct">>), direct, true, false, []), + #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath, exchange, <<"amq.topic">>), topic, true, false, []), + #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath, exchange, <<"amq.fanout">>), fanout, true, false, []), ok; [_] -> mnesia:abort({vhost_already_exists, VHostPath}) diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index f19249f6..c7db492c 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -168,7 +168,7 @@ recover_queue(Q) -> ok. default_binding_spec(#resource{virtual_host = VHostPath, name = Name}) -> - #binding_spec{exchange_name = rabbit_misc:r(VHostPath,exchange,<<"">>), + #binding_spec{exchange_name = rabbit_misc:r(VHostPath, exchange, <<"">>), routing_key = Name, arguments = []}. -- cgit v1.2.1 From 95ccf2322e7056bb118dc21a611dea170a8b7df0 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 5 Aug 2008 14:20:33 +0100 Subject: Linda is obselete now, Homepage is now regular field. --- packaging/debs/Debian/debian/control | 2 +- packaging/debs/Debian/debian/dirs | 1 - packaging/debs/Debian/debian/rules | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packaging/debs/Debian/debian/control b/packaging/debs/Debian/debian/control index ae698e1e..df9a330b 100644 --- a/packaging/debs/Debian/debian/control +++ b/packaging/debs/Debian/debian/control @@ -12,4 +12,4 @@ Description: An AMQP server written in Erlang RabbitMQ is an implementation of AMQP, the emerging standard for high performance enterprise messaging. The RabbitMQ server is a robust and scalable implementation of an AMQP broker. - Homepage: http://www.rabbitmq.com/ +Homepage: http://www.rabbitmq.com/ diff --git a/packaging/debs/Debian/debian/dirs b/packaging/debs/Debian/debian/dirs index 74ff60e2..43cb0443 100644 --- a/packaging/debs/Debian/debian/dirs +++ b/packaging/debs/Debian/debian/dirs @@ -1,6 +1,5 @@ usr/lib/erlang/lib usr/sbin -usr/share/linda/overrides var/lib/rabbitmq/mnesia var/log/rabbitmq diff --git a/packaging/debs/Debian/debian/rules b/packaging/debs/Debian/debian/rules index 15b0d50a..815deaff 100644 --- a/packaging/debs/Debian/debian/rules +++ b/packaging/debs/Debian/debian/rules @@ -15,4 +15,3 @@ install/rabbitmq-server:: mv $(DEB_DESTDIR)usr/sbin/rabbitmqctl $(DEB_DESTDIR)usr/sbin/rabbitmqctl_real cp debian/rabbitmqctl_wrapper $(DEB_DESTDIR)usr/sbin/rabbitmqctl chmod a+x $(DEB_DESTDIR)usr/sbin/rabbitmqctl - echo "Tag: usr-lib-in-arch-all" > $(DEB_DESTDIR)usr/share/linda/overrides/rabbitmq-server -- cgit v1.2.1 From 29a9c29ea58aeee65290beaeb4eaceebc7eff563 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Tue, 5 Aug 2008 16:05:01 +0100 Subject: Fixed another error in the specs --- src/rabbit_amqqueue.erl | 2 +- src/rabbit_exchange.erl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index c7db492c..ba651358 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -55,7 +55,7 @@ {'error', 'queue_not_found' | 'exchange_not_found'}). -spec(start/0 :: () -> 'ok'). -spec(recover/0 :: () -> 'ok'). --spec(declare/4 :: (r(amqqueue), bool(), bool(), amqp_table()) -> +-spec(declare/4 :: (queue_name(), bool(), bool(), amqp_table()) -> amqqueue()). -spec(add_binding/4 :: (queue_name(), exchange_name(), routing_key(), amqp_table()) -> diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index ccda0d36..c1a40394 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -50,7 +50,7 @@ not_found() | {'error', 'unroutable' | 'not_delivered'}). -spec(recover/0 :: () -> 'ok'). --spec(declare/5 :: (r(exchange), exchange_type(), bool(), bool(), +-spec(declare/5 :: (exchange_name(), exchange_type(), bool(), bool(), amqp_table()) -> exchange()). -spec(check_type/1 :: (binary()) -> atom()). -spec(assert_type/2 :: (exchange(), atom()) -> 'ok'). -- cgit v1.2.1 From c2659a9444f11ba65ab33e32dad9550c243939d2 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Tue, 5 Aug 2008 16:37:29 +0100 Subject: Most recently declared queue was returning the entire resource --- src/rabbit_channel.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 426cbd78..6719a974 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -181,7 +181,7 @@ expand_routing_key_shortcut(<<>>, <<>>, not_allowed, "no previously declared queue", []); expand_routing_key_shortcut(<<>>, <<>>, #ch{ most_recently_declared_queue = MRDQ }) -> - MRDQ; + MRDQ#resource.name; expand_routing_key_shortcut(_QueueNameBin, RoutingKey, _State) -> RoutingKey. -- cgit v1.2.1 From fea633b993702f4c74f9289194707dfb5ef3ebe1 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Tue, 5 Aug 2008 17:19:05 +0100 Subject: Deleted spec reference to permission type --- include/rabbit.hrl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/include/rabbit.hrl b/include/rabbit.hrl index f153e7c4..a83c0971 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -31,11 +31,11 @@ -record(connection, {user, timeout_sec, frame_max, vhost}). -record(content, {class_id, - properties, %% either 'none', or a decoded record/tuple - properties_bin, %% either 'none', or an encoded properties binary - %% Note: at most one of properties and properties_bin can be 'none' at once. - payload_fragments_rev %% list of binaries, in reverse order (!) - }). + properties, %% either 'none', or a decoded record/tuple + properties_bin, %% either 'none', or an encoded properties binary + %% Note: at most one of properties and properties_bin can be 'none' at once. + payload_fragments_rev %% list of binaries, in reverse order (!) + }). -record(resource, {virtual_host, kind, name}). @@ -75,7 +75,6 @@ -type(user() :: #user{username :: username(), password :: password()}). --type(permission() :: 'passive' | 'active' | 'write' | 'read'). -type(binding_spec() :: #binding_spec{exchange_name :: exchange_name(), routing_key :: routing_key(), -- cgit v1.2.1 From 87ebbed5c8315419ce0367e9fcab9fbbd403d767 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Wed, 6 Aug 2008 15:23:36 +0100 Subject: Fixing some QA remarks --- src/rabbit_amqqueue.erl | 4 ++-- src/rabbit_exchange.erl | 6 +++--- src/rabbit_misc.erl | 18 +++++++++++------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index ba651358..d4810105 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -363,8 +363,8 @@ on_node_down(Node) -> node(Pid) == Node])) end). -pseudo_queue(NameBin, Pid) -> - #amqqueue{name = NameBin, +pseudo_queue(Resource = #resource{}, Pid) -> + #amqqueue{name = Resource, durable = false, auto_delete = false, arguments = [], diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index c1a40394..d0f3f80a 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -131,12 +131,12 @@ assert_type(#exchange{ name = Name, type = ActualType }, RequiredType) -> lookup(Name) -> rabbit_misc:dirty_read({exchange, Name}). -lookup_or_die(Resource = #resource{name = Name}) -> - case lookup(Resource) of +lookup_or_die(Name) -> + case lookup(Name) of {ok, X} -> X; {error, not_found} -> rabbit_misc:protocol_error( - not_found, "no ~s", [rabbit_misc:rs(#resource{virtual_host = <<"/">>, kind = exchange, name = Name})]) + not_found, "no ~s", [rabbit_misc:rs(Name)]) end. list_vhost_exchanges(VHostPath) -> diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index c78a4ec3..6d501fe2 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -66,6 +66,10 @@ -spec(get_config/2 :: (atom(), A) -> A). -spec(set_config/2 :: (atom(), any()) -> 'ok'). -spec(dirty_read/1 :: ({atom(), any()}) -> {'ok', any()} | not_found()). +-spec(r/3 :: (#resource{virtual_host :: vhost(), + kind :: K, + name :: '_' | vhost(), K, name()) -> + r(K) when is_subtype(K, atom())). -spec(r/2 :: (vhost(), K) -> #resource{virtual_host :: vhost(), kind :: K, name :: '_'} @@ -73,16 +77,16 @@ -spec(rs/1 :: (r(atom())) -> string()). -spec(enable_cover/0 :: () -> 'ok' | {'error', any()}). -spec(report_cover/0 :: () -> 'ok'). --spec(with_exit_handler/2 :: (thunk(A), thunk(A)) -> A). --spec(with_user/2 :: (username(), thunk(A)) -> A). +-spec(with_exit_handler/2 :: (thunk(A), thunk(A)) -> A). +-spec(with_user/2 :: (username(), thunk(A)) -> A). -spec(with_vhost/2 :: (vhost(), thunk(A)) -> A). --spec(with_user_and_vhost/3 :: (username(), vhost(), thunk(A)) -> A). +-spec(with_user_and_vhost/3 :: (username(), vhost(), thunk(A)) -> A). -spec(execute_mnesia_transaction/1 :: (thunk(A)) -> A). --spec(ensure_ok/2 :: ('ok' | {'error', any()}, atom()) -> 'ok'). +-spec(ensure_ok/2 :: ('ok' | {'error', any()}, atom()) -> 'ok'). -spec(localnode/1 :: (atom()) -> node()). --spec(tcp_name/3 :: (atom(), ip_address(), ip_port()) -> atom()). +-spec(tcp_name/3 :: (atom(), ip_address(), ip_port()) -> atom()). -spec(intersperse/2 :: (A, [A]) -> [A]). --spec(upmap/2 :: (fun ((A) -> B), [A]) -> [B]). +-spec(upmap/2 :: (fun ((A) -> B), [A]) -> [B]). -spec(map_in_order/2 :: (fun ((A) -> B), [A]) -> [B]). -spec(guid/0 :: () -> guid()). -spec(string_guid/1 :: (any()) -> string()). @@ -213,7 +217,7 @@ with_user(Username, Thunk) -> with_vhost(VHostPath, Thunk) -> fun () -> case mnesia:read({vhost, VHostPath}) of - [] -> + [] -> mnesia:abort({no_such_vhost, VHostPath}); [_V] -> Thunk() -- cgit v1.2.1 From 32b7a831a2833627ed56931164e819f8c50e7f72 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Wed, 6 Aug 2008 15:47:45 +0100 Subject: folded default user into default host --- src/rabbit.erl | 8 ++------ src/rabbit_access_control.erl | 6 ++---- src/rabbit_misc.erl | 4 +--- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index f11e87bc..a45b927b 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -213,12 +213,8 @@ insert_default_data() -> {ok, DefaultPass} = application:get_env(default_pass), {ok, DefaultVHost} = application:get_env(default_vhost), ok = rabbit_access_control:add_vhost(DefaultVHost), - ok = insert_default_user(DefaultUser, DefaultPass, DefaultVHost), - ok. - -insert_default_user(Username, Password, VHostPath) -> - ok = rabbit_access_control:add_user(Username, Password), - ok = rabbit_access_control:map_user_vhost(Username, VHostPath), + ok = rabbit_access_control:add_user(DefaultUser, DefaultPass), + ok = rabbit_access_control:map_user_vhost(DefaultUser, DefaultVHost), ok. start_builtin_amq_applications() -> diff --git a/src/rabbit_access_control.erl b/src/rabbit_access_control.erl index c926eacb..9bc96514 100644 --- a/src/rabbit_access_control.erl +++ b/src/rabbit_access_control.erl @@ -173,10 +173,8 @@ add_vhost(VHostPath) -> case mnesia:read({vhost, VHostPath}) of [] -> ok = mnesia:write(#vhost{virtual_host = VHostPath}), - #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath, exchange, <<"">>), direct, true, false, []), - #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath, exchange, <<"amq.direct">>), direct, true, false, []), - #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath, exchange, <<"amq.topic">>), topic, true, false, []), - #exchange{} = rabbit_exchange:declare(rabbit_misc:r(VHostPath, exchange, <<"amq.fanout">>), fanout, true, false, []), + [ rabbit_exchange:declare(rabbit_misc:r(VHostPath, exchange, Name), Type, true, false, []) || {Name,Type} + <- [{<<"">>, direct}, { <<"amq.direct">>, direct}, {<<"amq.topic">>, topic}, {<<"amq.fanout">>, fanout}]], ok; [_] -> mnesia:abort({vhost_already_exists, VHostPath}) diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 6d501fe2..2c57b16c 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -66,9 +66,7 @@ -spec(get_config/2 :: (atom(), A) -> A). -spec(set_config/2 :: (atom(), any()) -> 'ok'). -spec(dirty_read/1 :: ({atom(), any()}) -> {'ok', any()} | not_found()). --spec(r/3 :: (#resource{virtual_host :: vhost(), - kind :: K, - name :: '_' | vhost(), K, name()) -> +-spec(r/3 :: (#resource{virtual_host :: vhost()} | vhost(), K, name()) -> r(K) when is_subtype(K, atom())). -spec(r/2 :: (vhost(), K) -> #resource{virtual_host :: vhost(), kind :: K, -- cgit v1.2.1 From 7c145bca6c7f43ad3394cd6a5323ed21c96e3b29 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Wed, 6 Aug 2008 15:55:33 +0100 Subject: Reverting unecessary changes in rabbit_amqqueue --- src/rabbit_amqqueue.erl | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index d4810105..1be24761 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -130,8 +130,8 @@ recover_durable_queues() -> ok end). -declare(Resource = #resource{}, Durable, AutoDelete, Args) -> - Q = start_queue_process(#amqqueue{name = Resource, +declare(QueueName = #resource{}, Durable, AutoDelete, Args) -> + Q = start_queue_process(#amqqueue{name = QueueName, durable = Durable, auto_delete = AutoDelete, arguments = Args, @@ -139,7 +139,7 @@ declare(Resource = #resource{}, Durable, AutoDelete, Args) -> pid = none}), case rabbit_misc:execute_mnesia_transaction( fun () -> - case mnesia:wread({amqqueue, Resource}) of + case mnesia:wread({amqqueue, QueueName}) of [] -> ok = recover_queue(Q), Q; [ExistingQ] -> ExistingQ @@ -167,8 +167,8 @@ recover_queue(Q) -> ok = recover_bindings(Q), ok. -default_binding_spec(#resource{virtual_host = VHostPath, name = Name}) -> - #binding_spec{exchange_name = rabbit_misc:r(VHostPath, exchange, <<"">>), +default_binding_spec(#resource{virtual_host = VHost, name = Name}) -> + #binding_spec{exchange_name = rabbit_misc:r(VHost, exchange, <<>>), routing_key = Name, arguments = []}. @@ -179,13 +179,13 @@ recover_bindings(Q = #amqqueue{name = QueueName, binding_specs = Specs}) -> end, Specs), ok. -modify_bindings(Queue = #resource{}, X = #resource{}, RoutingKey, Arguments, +modify_bindings(QueueName, ExchangeName, RoutingKey, Arguments, SpecPresentFun, SpecAbsentFun) -> rabbit_misc:execute_mnesia_transaction( fun () -> - case mnesia:wread({amqqueue, Queue}) of + case mnesia:wread({amqqueue, QueueName}) of [Q = #amqqueue{binding_specs = Specs0}] -> - Spec = #binding_spec{exchange_name = X, + Spec = #binding_spec{exchange_name = ExchangeName, routing_key = RoutingKey, arguments = Arguments}, case (case lists:member(Spec, Specs0) of @@ -336,22 +336,19 @@ internal_delete(QueueName) -> case mnesia:wread({amqqueue, QueueName}) of [] -> {error, not_found}; [Q] -> - ok = delete_temp(Q), + ok = delete_queue(Q), ok = mnesia:delete({durable_queues, QueueName}), ok end end). -delete_temp(Q = #amqqueue{name = QueueName}) -> +delete_queue(Q = #amqqueue{name = QueueName}) -> ok = delete_bindings(Q), ok = rabbit_exchange:delete_binding( default_binding_spec(QueueName), Q), ok = mnesia:delete({amqqueue, QueueName}), ok. -delete_queue(Q = #amqqueue{}) -> - ok = delete_temp(Q). - on_node_down(Node) -> rabbit_misc:execute_mnesia_transaction( fun () -> -- cgit v1.2.1 From 096f2f2dd3626498e31b7885517c3c5bb50a22b8 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Wed, 6 Aug 2008 16:06:52 +0100 Subject: Some more fixes for QA comments --- src/rabbit_channel.erl | 3 ++- src/rabbit_error_logger.erl | 2 +- src/rabbit_exchange.erl | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 6719a974..a116c33d 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -227,7 +227,8 @@ handle_method(#'channel.close'{}, _, State = #ch{writer_pid = WriterPid}) -> ok = rabbit_writer:shutdown(WriterPid), stop; -handle_method(#'access.request'{},_, State) -> {reply, #'access.request_ok'{ticket = 1}, State}; +handle_method(#'access.request'{},_, State) -> + {reply, #'access.request_ok'{ticket = 1}, State}; handle_method(#'basic.publish'{exchange = ExchangeNameBin, routing_key = RoutingKey, diff --git a/src/rabbit_error_logger.erl b/src/rabbit_error_logger.erl index e4ce3aa3..9220d7b4 100644 --- a/src/rabbit_error_logger.erl +++ b/src/rabbit_error_logger.erl @@ -34,7 +34,7 @@ init([DefaultVHost]) -> #exchange{} = rabbit_exchange:declare( - rabbit_misc:r(DefaultVHost,exchange,?LOG_EXCH_NAME), + rabbit_misc:r(DefaultVHost, exchange, ?LOG_EXCH_NAME), topic, true, false, []), {ok, #resource{virtual_host = DefaultVHost, kind = exchange, diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index d0f3f80a..cd5511aa 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -90,15 +90,15 @@ recover_durable_exchanges() -> end, ok, durable_exchanges) end). -declare(Resource = #resource{}, Type, Durable, AutoDelete, Args) -> - Exchange = #exchange{name = Resource, +declare(ExchangeName = #resource{}, Type, Durable, AutoDelete, Args) -> + Exchange = #exchange{name = ExchangeName, type = Type, durable = Durable, auto_delete = AutoDelete, arguments = Args}, rabbit_misc:execute_mnesia_transaction( fun () -> - case mnesia:wread({exchange, Resource}) of + case mnesia:wread({exchange, ExchangeName}) of [] -> ok = mnesia:write(Exchange), if Durable -> ok = mnesia:write( -- cgit v1.2.1 From 1c1055632923824ba1652ed32768bac50640005b Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 7 Aug 2008 13:16:21 +0100 Subject: Added 4 basic man pages. Rabbitmqctl_real does not contain info about realms and permissions since those are to be removed either way. Included pages in debian and rpm packages. --- Makefile | 9 ++ docs/rabbitmq-multi.1.pod | 52 +++++++++++ docs/rabbitmq-server.1.pod | 80 ++++++++++++++++ docs/rabbitmqctl.1.pod | 37 ++++++++ docs/rabbitmqctl_real.1.pod | 141 +++++++++++++++++++++++++++++ packaging/RPMS/Fedora/rabbitmq-server.spec | 11 ++- packaging/debs/Debian/debian/dirs | 1 + packaging/debs/Debian/debian/rules | 2 +- packaging/generic-unix/Makefile | 3 +- 9 files changed, 329 insertions(+), 7 deletions(-) create mode 100644 docs/rabbitmq-multi.1.pod create mode 100644 docs/rabbitmq-server.1.pod create mode 100644 docs/rabbitmqctl.1.pod create mode 100644 docs/rabbitmqctl_real.1.pod diff --git a/Makefile b/Makefile index 83c8454d..0b320905 100644 --- a/Makefile +++ b/Makefile @@ -119,6 +119,7 @@ srcdist: distclean cp codegen.py Makefile dist/$(TARBALL_NAME) cp -r scripts dist/$(TARBALL_NAME) + cp -r docs dist/$(TARBALL_NAME) chmod 0755 dist/$(TARBALL_NAME)/scripts/* (cd dist; tar -zcf $(TARBALL_NAME).tar.gz $(TARBALL_NAME)) @@ -133,12 +134,20 @@ distclean: clean install: all @[ -n "$(TARGET_DIR)" ] || (echo "Please set TARGET_DIR."; false) @[ -n "$(SBIN_DIR)" ] || (echo "Please set SBIN_DIR."; false) + @[ -n "$(MAN_DIR)" ] || (echo "Please set MAN_DIR."; false) $(MAKE) VERSION=$(VERSION) GENERIC_STAGE_DIR=$(TARGET_DIR) generic_stage chmod 0755 scripts/* mkdir -p $(SBIN_DIR) + mkdir -p $(MAN_DIR)/man1 cp scripts/rabbitmq-server $(SBIN_DIR) cp scripts/rabbitmqctl $(SBIN_DIR) cp scripts/rabbitmq-multi $(SBIN_DIR) + for manpage in docs/*.pod ; do \ + pod2man -c "RabbitMQ AMQP Server" -d "" -r "" \ + $$manpage | gzip --best > \ + $(MAN_DIR)/man1/`echo $$manpage | sed -e 's:docs/\(.*\)\.pod:\1\.gz:g'`; \ + done + rm -f $(TARGET_DIR)/BUILD diff --git a/docs/rabbitmq-multi.1.pod b/docs/rabbitmq-multi.1.pod new file mode 100644 index 00000000..0f7aec52 --- /dev/null +++ b/docs/rabbitmq-multi.1.pod @@ -0,0 +1,52 @@ +=head1 NAME + +rabbitmq-multi - start/stop local cluster RabbitMQ nodes + +=head1 SYNOPSIS + +rabbitmq-multi I [command option] + +=head1 DESCRIPTION + +RabbitMQ is an implementation of AMQP, the emerging standard for high +performance enterprise messaging. The RabbitMQ server is a robust and +scalable implementation of an AMQP broker. + +rabbitmq-multi scripts allows for easy set-up of a cluster on a single +machine. + +See also rabbitmq-server(1) for configuration information. + +=head1 COMMANDS + +start_all I + start count nodes with unique names, listening on all IP addresses + and on sequential ports starting from 5672. + +stop_all + stop all local RabbitMQ nodes + +=head1 EXAMPLES + +Start 3 local RabbitMQ nodes with unique, sequential port numbers: + + rabbitmq-multi start_all 3 + +=head1 SEE ALSO + +rabbitmq-server(1), rabbitmqctl(1), rabbitmqctl_real(1) + +=head1 AUTHOR + +Originally written by The RabbitMQ Team + +=head1 COPYRIGHT + +This package, the RabbitMQ server is licensed under the MPL. + +If you have any questions regarding licensing, please contact us at +info@rabbitmq.com. + +=head1 REFERENCES + +RabbitMQ Web Site: http://www.rabbitmq.com diff --git a/docs/rabbitmq-server.1.pod b/docs/rabbitmq-server.1.pod new file mode 100644 index 00000000..bf411bc2 --- /dev/null +++ b/docs/rabbitmq-server.1.pod @@ -0,0 +1,80 @@ +=head1 NAME + +rabbitmq-server - start RabbitMQ AMQP server + +=head1 SYNOPSIS + +rabbitmq-server [-detached] + +=head1 DESCRIPTION + +RabbitMQ is an implementation of AMQP, the emerging standard for high +performance enterprise messaging. The RabbitMQ server is a robust and +scalable implementation of an AMQP broker. + +Running rabbitmq-server in the foreground displays a banner message, +and reports on progress in the startup sequence, concluding with the +message "broker running", indicating that the RabbitMQ broker has been +started successfully. To shut down the server, just terminate the +process or use rabbitmqctl(1). + +=head1 ENVIRONMENT + +B + Defaults to /var/lib/rabbitmq/mnesia. Set this to the directory + where Mnesia database files should be placed. + +B + Defaults to /var/log/rabbitmq. Log files generated by the server + will be placed in this directory. + +B + Defaults to rabbit. This can be useful if you want to run more + than one node per machine - B should be unique per + erlang-node-and-machine combination. See clustering on a single + machine guide + at http://www.rabbitmq.com/clustering.html#single-machine for + details. + +B + Defaults to 0.0.0.0. This can be changed if you only want to bind + to one network interface. + +B + Defaults to 5672. + +B + Defaults to /etc/default/rabbitmq_cluster.config. If this file is + present it is used by the server to auto-configure a RabbitMQ + cluster. + See the clustering guide at http://www.rabbitmq.com/clustering.html + for details. + +=head1 OPTIONS + +B<-detached> start the server process in the background + +=head1 EXAMPLES + +Run RabbitMQ AMQP server in the background: + + rabbitmq-server -detached + +=head1 SEE ALSO + +rabbitmq-multi(1), rabbitmqctl(1), rabbitmqctl_real(1) + +=head1 AUTHOR + +Originally written by The RabbitMQ Team + +=head1 COPYRIGHT + +This package, the RabbitMQ server is licensed under the MPL. + +If you have any questions regarding licensing, please contact us at +info@rabbitmq.com. + +=head1 REFERENCES + +RabbitMQ Web Site: http://www.rabbitmq.com diff --git a/docs/rabbitmqctl.1.pod b/docs/rabbitmqctl.1.pod new file mode 100644 index 00000000..602cf751 --- /dev/null +++ b/docs/rabbitmqctl.1.pod @@ -0,0 +1,37 @@ +=head1 NAME + +rabbitmqctl - wrapper for the command line tool for managing a RabbitMQ broker + +=head1 SYNOPSIS + +rabbitmqctl I [command options] + +=head1 DESCRIPTION + +RabbitMQ is an implementation of AMQP, the emerging standard for high +performance enterprise messaging. The RabbitMQ server is a robust and +scalable implementation of an AMQP broker. + +rabbitmqctl is a wrapper around rabbitmqctl_real(1) tool and performs +all commands properly with I user permissions. + +See rabbitmqctl_real(1) for the list of available commands. + +=head1 SEE ALSO + +rabbitmq-server(1), rabbitmqctl_real(1), rabbitmq-multi(1) + +=head1 AUTHOR + +Originally written by The RabbitMQ Team + +=head1 COPYRIGHT + +This package, the RabbitMQ server is licensed under the MPL. + +If you have any questions regarding licensing, please contact us at +info@rabbitmq.com. + +=head1 REFERENCES + +RabbitMQ Web Site: http://www.rabbitmq.com diff --git a/docs/rabbitmqctl_real.1.pod b/docs/rabbitmqctl_real.1.pod new file mode 100644 index 00000000..f52eb394 --- /dev/null +++ b/docs/rabbitmqctl_real.1.pod @@ -0,0 +1,141 @@ +=head1 NAME + +rabbitmqctl_real - command line tool for managing a RabbitMQ broker + +=head1 SYNOPSIS + +rabbitmqctl_real [-n I] I<> [command options] + +=head1 DESCRIPTION + +RabbitMQ is an implementation of AMQP, the emerging standard for high +performance enterprise messaging. The RabbitMQ server is a robust and +scalable implementation of an AMQP broker. + +rabbitmqctl_real is a command line tool for managing a RabbitMQ broker. +It performs all actions by connecting to one of the broker's node. +rabbitmqctl_real is called by the rabbitmqctl(1) wrapper to be +correctly executed with I user permissions. + + +=head1 OPTIONS + +B<-n> I + default node is C, where server is the local host. + On a host named C, the node name of the RabbitMQ + Erlang node will usually be rabbit@server (unless NODENAME has been + set to some non-default value at broker startup time). + The output of hostname -s is usually the correct suffix to use + after the "@" sign. See rabbitmq-server(1) for details of configur- + ing the RabbitMQ broker. + + +=head1 COMMANDS + +=head2 APPLICATION AND CLUSTER MANAGEMENT + +stop + stop the Erlang node on which RabbitMQ broker is running. + +stop_app + stop the RabbitMQ application, leaving the Erlang node running. + This command is typically run prior to performing other management + actions that require the RabbitMQ application to be stopped, + e.g. I. + +start_app + start the RabbitMQ application. + This command is typically run prior to performing other management + actions that require the RabbitMQ application to be stopped, + e.g. I. + +status + display various information about the RabbitMQ broker, such as + whether the RabbitMQ application on the current node, its version + number, what nodes are part of the broker, which of these are + running. + +force + return a RabbitMQ node to its virgin state. + Removes the node from any cluster it belongs to, removes all data + from the management database, such as configured users, vhosts and + realms, and deletes all persistent messages. + +force_reset + the same as I command, but resets the node unconditionally, + regardless of the current management database state and cluster + configuration. + It should only be used as a last resort if the database or cluster + configuration has been corrupted. + +cluster I ... + instruct the node to become member of a cluster with the specified + nodes determined by I option(s). + See http://www.rabbitmq.com/clustering.html for more information + about clustering. + +=head2 USER MANAGEMENT + +add_user I I + create a user named I with (initial) password I. + +change_password I I + change the password for the user named I to I. + +list_users + list all users. + +=head2 ACCESS CONTROL + +add_vhost I + create a new virtual host called I. + +delete_vhost I + delete a virtual host I. + That command deletes also all its exchanges, queues and user mappings. + +list_vhosts + list all virtual hosts. + +map_user_vhost I I + grant the user named I access to the virtual host called + I. + +unmap_user_vhost I I + deny the user named I access to the virtual host called + I. + +list_user_vhost I + list all the virtual hosts to which the user named I has + been granted access. + +=head1 EXAMPLES + +Create a user named foo with (initial) password bar at the Erlang node +rabbit@test: + + rabbitmqctl -n rabbit@test add_user foo bar + +Grant user named foo access to the virtual host called test at the +default Erlang node: + + rabbitmqctl map_user_vhost foo test + +=head1 SEE ALSO + +rabbitmq-server(1), rabbitmqctl(1), rabbitmqctl_real(1) + +=head1 AUTHOR + +Originally written by The RabbitMQ Team + +=head1 COPYRIGHT + +This package, the RabbitMQ server is licensed under the MPL. + +If you have any questions regarding licensing, please contact us at +info@rabbitmq.com. + +=head1 REFERENCES + +RabbitMQ Web Site: http://www.rabbitmq.com diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec index dd12e1e5..038f6d2d 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.spec +++ b/packaging/RPMS/Fedora/rabbitmq-server.spec @@ -20,6 +20,7 @@ scalable implementation of an AMQP broker. %define _libdir /usr/lib/erlang %define _docdir /usr/share/doc +%define _mandir /usr/share/man %define _maindir $RPM_BUILD_ROOT%{_libdir}/lib/rabbitmq_server-%{main_version} %define package_name rabbitmq-server-dist @@ -36,8 +37,10 @@ fi %build mkdir %{package_name} mkdir %{package_name}/sbin +mkdir %{package_name}/man make install TARGET_DIR=`pwd`/%{package_name} \ SBIN_DIR=`pwd`/%{package_name}/sbin \ + MAN_DIR=`pwd`/%{package_name}/man VERSION=%{main_version} %install @@ -45,6 +48,7 @@ mkdir -p %{_maindir} mkdir -p $RPM_BUILD_ROOT%{_docdir}/rabbitmq-server mkdir -p $RPM_BUILD_ROOT/etc/init.d mkdir -p $RPM_BUILD_ROOT/usr/sbin +mkdir -p $RPM_BUILD_ROOT%{_mandir} mkdir -p $RPM_BUILD_ROOT/var/lib/rabbitmq/mnesia mkdir -p $RPM_BUILD_ROOT/var/log/rabbitmq @@ -55,6 +59,7 @@ cp -r %{package_name}/src %{_maindir} cp -r %{package_name}/include %{_maindir} chmod 755 %{package_name}/sbin/* cp %{package_name}/sbin/* $RPM_BUILD_ROOT/usr/sbin/ +cp -r %{package_name}/man/* $RPM_BUILD_ROOT%{_mandir}/ cp ../init.d $RPM_BUILD_ROOT/etc/init.d/rabbitmq-server chmod 775 $RPM_BUILD_ROOT/etc/init.d/rabbitmq-server @@ -107,10 +112,8 @@ fi %defattr(-,root,root) %{_libdir}/lib/rabbitmq_server-%{main_version}/ %{_docdir}/rabbitmq-server/ -/usr/sbin/rabbitmq-server -/usr/sbin/rabbitmq-multi -/usr/sbin/rabbitmqctl -/usr/sbin/rabbitmqctl_real +%{_mandir} +/usr/sbin /var/lib/rabbitmq /var/log/rabbitmq /etc/init.d/rabbitmq-server diff --git a/packaging/debs/Debian/debian/dirs b/packaging/debs/Debian/debian/dirs index 74ff60e2..48db317f 100644 --- a/packaging/debs/Debian/debian/dirs +++ b/packaging/debs/Debian/debian/dirs @@ -1,5 +1,6 @@ usr/lib/erlang/lib usr/sbin +usr/share/man usr/share/linda/overrides var/lib/rabbitmq/mnesia var/log/rabbitmq diff --git a/packaging/debs/Debian/debian/rules b/packaging/debs/Debian/debian/rules index 15b0d50a..3e05863a 100644 --- a/packaging/debs/Debian/debian/rules +++ b/packaging/debs/Debian/debian/rules @@ -5,7 +5,7 @@ include /usr/share/cdbs/1/class/makefile.mk RABBIT_LIB=$(DEB_DESTDIR)usr/lib/erlang/lib/rabbitmq_server-$(DEB_UPSTREAM_VERSION) -DEB_MAKE_INSTALL_TARGET := install TARGET_DIR=$(RABBIT_LIB)/ SBIN_DIR=$(DEB_DESTDIR)usr/sbin +DEB_MAKE_INSTALL_TARGET := install TARGET_DIR=$(RABBIT_LIB)/ SBIN_DIR=$(DEB_DESTDIR)usr/sbin MAN_DIR=$(DEB_DESTDIR)usr/share/man DOCDIR=$(DEB_DESTDIR)usr/share/doc/rabbitmq-server/ diff --git a/packaging/generic-unix/Makefile b/packaging/generic-unix/Makefile index 13257522..b3988696 100644 --- a/packaging/generic-unix/Makefile +++ b/packaging/generic-unix/Makefile @@ -7,11 +7,10 @@ dist: make -C ../.. VERSION=$(VERSION) srcdist tar -zxvf ../../dist/$(SOURCE_DIR).tar.gz - mkdir $(TARGET_DIR) - mkdir $(TARGET_DIR)/sbin make -C $(SOURCE_DIR) \ TARGET_DIR=`pwd`/$(TARGET_DIR) \ SBIN_DIR=`pwd`/$(TARGET_DIR)/sbin \ + MAN_DIR=`pwd`/$(TARGET_DIR)/share/man \ install tar -zcf $(TARGET_TARBALL).tar.gz $(TARGET_DIR) -- cgit v1.2.1 From 584cd3d1abaff96c8d1b683e34973983e883c414 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 7 Aug 2008 14:22:07 +0100 Subject: Renamed the pod pages slightly. --- Makefile | 2 +- docs/rabbitmq-multi.1.pod | 52 ---------------- docs/rabbitmq-multi.pod | 52 ++++++++++++++++ docs/rabbitmq-server.1.pod | 80 ------------------------- docs/rabbitmq-server.pod | 80 +++++++++++++++++++++++++ docs/rabbitmqctl.1.pod | 37 ------------ docs/rabbitmqctl.pod | 37 ++++++++++++ docs/rabbitmqctl_real.1.pod | 141 -------------------------------------------- docs/rabbitmqctl_real.pod | 141 ++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 311 insertions(+), 311 deletions(-) delete mode 100644 docs/rabbitmq-multi.1.pod create mode 100644 docs/rabbitmq-multi.pod delete mode 100644 docs/rabbitmq-server.1.pod create mode 100644 docs/rabbitmq-server.pod delete mode 100644 docs/rabbitmqctl.1.pod create mode 100644 docs/rabbitmqctl.pod delete mode 100644 docs/rabbitmqctl_real.1.pod create mode 100644 docs/rabbitmqctl_real.pod diff --git a/Makefile b/Makefile index 0b320905..471c32f9 100644 --- a/Makefile +++ b/Makefile @@ -147,7 +147,7 @@ install: all for manpage in docs/*.pod ; do \ pod2man -c "RabbitMQ AMQP Server" -d "" -r "" \ $$manpage | gzip --best > \ - $(MAN_DIR)/man1/`echo $$manpage | sed -e 's:docs/\(.*\)\.pod:\1\.gz:g'`; \ + $(MAN_DIR)/man1/`echo $$manpage | sed -e 's:docs/\(.*\)\.pod:\1\.1\.gz:g'`; \ done rm -f $(TARGET_DIR)/BUILD diff --git a/docs/rabbitmq-multi.1.pod b/docs/rabbitmq-multi.1.pod deleted file mode 100644 index 0f7aec52..00000000 --- a/docs/rabbitmq-multi.1.pod +++ /dev/null @@ -1,52 +0,0 @@ -=head1 NAME - -rabbitmq-multi - start/stop local cluster RabbitMQ nodes - -=head1 SYNOPSIS - -rabbitmq-multi I [command option] - -=head1 DESCRIPTION - -RabbitMQ is an implementation of AMQP, the emerging standard for high -performance enterprise messaging. The RabbitMQ server is a robust and -scalable implementation of an AMQP broker. - -rabbitmq-multi scripts allows for easy set-up of a cluster on a single -machine. - -See also rabbitmq-server(1) for configuration information. - -=head1 COMMANDS - -start_all I - start count nodes with unique names, listening on all IP addresses - and on sequential ports starting from 5672. - -stop_all - stop all local RabbitMQ nodes - -=head1 EXAMPLES - -Start 3 local RabbitMQ nodes with unique, sequential port numbers: - - rabbitmq-multi start_all 3 - -=head1 SEE ALSO - -rabbitmq-server(1), rabbitmqctl(1), rabbitmqctl_real(1) - -=head1 AUTHOR - -Originally written by The RabbitMQ Team - -=head1 COPYRIGHT - -This package, the RabbitMQ server is licensed under the MPL. - -If you have any questions regarding licensing, please contact us at -info@rabbitmq.com. - -=head1 REFERENCES - -RabbitMQ Web Site: http://www.rabbitmq.com diff --git a/docs/rabbitmq-multi.pod b/docs/rabbitmq-multi.pod new file mode 100644 index 00000000..0f7aec52 --- /dev/null +++ b/docs/rabbitmq-multi.pod @@ -0,0 +1,52 @@ +=head1 NAME + +rabbitmq-multi - start/stop local cluster RabbitMQ nodes + +=head1 SYNOPSIS + +rabbitmq-multi I [command option] + +=head1 DESCRIPTION + +RabbitMQ is an implementation of AMQP, the emerging standard for high +performance enterprise messaging. The RabbitMQ server is a robust and +scalable implementation of an AMQP broker. + +rabbitmq-multi scripts allows for easy set-up of a cluster on a single +machine. + +See also rabbitmq-server(1) for configuration information. + +=head1 COMMANDS + +start_all I + start count nodes with unique names, listening on all IP addresses + and on sequential ports starting from 5672. + +stop_all + stop all local RabbitMQ nodes + +=head1 EXAMPLES + +Start 3 local RabbitMQ nodes with unique, sequential port numbers: + + rabbitmq-multi start_all 3 + +=head1 SEE ALSO + +rabbitmq-server(1), rabbitmqctl(1), rabbitmqctl_real(1) + +=head1 AUTHOR + +Originally written by The RabbitMQ Team + +=head1 COPYRIGHT + +This package, the RabbitMQ server is licensed under the MPL. + +If you have any questions regarding licensing, please contact us at +info@rabbitmq.com. + +=head1 REFERENCES + +RabbitMQ Web Site: http://www.rabbitmq.com diff --git a/docs/rabbitmq-server.1.pod b/docs/rabbitmq-server.1.pod deleted file mode 100644 index bf411bc2..00000000 --- a/docs/rabbitmq-server.1.pod +++ /dev/null @@ -1,80 +0,0 @@ -=head1 NAME - -rabbitmq-server - start RabbitMQ AMQP server - -=head1 SYNOPSIS - -rabbitmq-server [-detached] - -=head1 DESCRIPTION - -RabbitMQ is an implementation of AMQP, the emerging standard for high -performance enterprise messaging. The RabbitMQ server is a robust and -scalable implementation of an AMQP broker. - -Running rabbitmq-server in the foreground displays a banner message, -and reports on progress in the startup sequence, concluding with the -message "broker running", indicating that the RabbitMQ broker has been -started successfully. To shut down the server, just terminate the -process or use rabbitmqctl(1). - -=head1 ENVIRONMENT - -B - Defaults to /var/lib/rabbitmq/mnesia. Set this to the directory - where Mnesia database files should be placed. - -B - Defaults to /var/log/rabbitmq. Log files generated by the server - will be placed in this directory. - -B - Defaults to rabbit. This can be useful if you want to run more - than one node per machine - B should be unique per - erlang-node-and-machine combination. See clustering on a single - machine guide - at http://www.rabbitmq.com/clustering.html#single-machine for - details. - -B - Defaults to 0.0.0.0. This can be changed if you only want to bind - to one network interface. - -B - Defaults to 5672. - -B - Defaults to /etc/default/rabbitmq_cluster.config. If this file is - present it is used by the server to auto-configure a RabbitMQ - cluster. - See the clustering guide at http://www.rabbitmq.com/clustering.html - for details. - -=head1 OPTIONS - -B<-detached> start the server process in the background - -=head1 EXAMPLES - -Run RabbitMQ AMQP server in the background: - - rabbitmq-server -detached - -=head1 SEE ALSO - -rabbitmq-multi(1), rabbitmqctl(1), rabbitmqctl_real(1) - -=head1 AUTHOR - -Originally written by The RabbitMQ Team - -=head1 COPYRIGHT - -This package, the RabbitMQ server is licensed under the MPL. - -If you have any questions regarding licensing, please contact us at -info@rabbitmq.com. - -=head1 REFERENCES - -RabbitMQ Web Site: http://www.rabbitmq.com diff --git a/docs/rabbitmq-server.pod b/docs/rabbitmq-server.pod new file mode 100644 index 00000000..bf411bc2 --- /dev/null +++ b/docs/rabbitmq-server.pod @@ -0,0 +1,80 @@ +=head1 NAME + +rabbitmq-server - start RabbitMQ AMQP server + +=head1 SYNOPSIS + +rabbitmq-server [-detached] + +=head1 DESCRIPTION + +RabbitMQ is an implementation of AMQP, the emerging standard for high +performance enterprise messaging. The RabbitMQ server is a robust and +scalable implementation of an AMQP broker. + +Running rabbitmq-server in the foreground displays a banner message, +and reports on progress in the startup sequence, concluding with the +message "broker running", indicating that the RabbitMQ broker has been +started successfully. To shut down the server, just terminate the +process or use rabbitmqctl(1). + +=head1 ENVIRONMENT + +B + Defaults to /var/lib/rabbitmq/mnesia. Set this to the directory + where Mnesia database files should be placed. + +B + Defaults to /var/log/rabbitmq. Log files generated by the server + will be placed in this directory. + +B + Defaults to rabbit. This can be useful if you want to run more + than one node per machine - B should be unique per + erlang-node-and-machine combination. See clustering on a single + machine guide + at http://www.rabbitmq.com/clustering.html#single-machine for + details. + +B + Defaults to 0.0.0.0. This can be changed if you only want to bind + to one network interface. + +B + Defaults to 5672. + +B + Defaults to /etc/default/rabbitmq_cluster.config. If this file is + present it is used by the server to auto-configure a RabbitMQ + cluster. + See the clustering guide at http://www.rabbitmq.com/clustering.html + for details. + +=head1 OPTIONS + +B<-detached> start the server process in the background + +=head1 EXAMPLES + +Run RabbitMQ AMQP server in the background: + + rabbitmq-server -detached + +=head1 SEE ALSO + +rabbitmq-multi(1), rabbitmqctl(1), rabbitmqctl_real(1) + +=head1 AUTHOR + +Originally written by The RabbitMQ Team + +=head1 COPYRIGHT + +This package, the RabbitMQ server is licensed under the MPL. + +If you have any questions regarding licensing, please contact us at +info@rabbitmq.com. + +=head1 REFERENCES + +RabbitMQ Web Site: http://www.rabbitmq.com diff --git a/docs/rabbitmqctl.1.pod b/docs/rabbitmqctl.1.pod deleted file mode 100644 index 602cf751..00000000 --- a/docs/rabbitmqctl.1.pod +++ /dev/null @@ -1,37 +0,0 @@ -=head1 NAME - -rabbitmqctl - wrapper for the command line tool for managing a RabbitMQ broker - -=head1 SYNOPSIS - -rabbitmqctl I [command options] - -=head1 DESCRIPTION - -RabbitMQ is an implementation of AMQP, the emerging standard for high -performance enterprise messaging. The RabbitMQ server is a robust and -scalable implementation of an AMQP broker. - -rabbitmqctl is a wrapper around rabbitmqctl_real(1) tool and performs -all commands properly with I user permissions. - -See rabbitmqctl_real(1) for the list of available commands. - -=head1 SEE ALSO - -rabbitmq-server(1), rabbitmqctl_real(1), rabbitmq-multi(1) - -=head1 AUTHOR - -Originally written by The RabbitMQ Team - -=head1 COPYRIGHT - -This package, the RabbitMQ server is licensed under the MPL. - -If you have any questions regarding licensing, please contact us at -info@rabbitmq.com. - -=head1 REFERENCES - -RabbitMQ Web Site: http://www.rabbitmq.com diff --git a/docs/rabbitmqctl.pod b/docs/rabbitmqctl.pod new file mode 100644 index 00000000..602cf751 --- /dev/null +++ b/docs/rabbitmqctl.pod @@ -0,0 +1,37 @@ +=head1 NAME + +rabbitmqctl - wrapper for the command line tool for managing a RabbitMQ broker + +=head1 SYNOPSIS + +rabbitmqctl I [command options] + +=head1 DESCRIPTION + +RabbitMQ is an implementation of AMQP, the emerging standard for high +performance enterprise messaging. The RabbitMQ server is a robust and +scalable implementation of an AMQP broker. + +rabbitmqctl is a wrapper around rabbitmqctl_real(1) tool and performs +all commands properly with I user permissions. + +See rabbitmqctl_real(1) for the list of available commands. + +=head1 SEE ALSO + +rabbitmq-server(1), rabbitmqctl_real(1), rabbitmq-multi(1) + +=head1 AUTHOR + +Originally written by The RabbitMQ Team + +=head1 COPYRIGHT + +This package, the RabbitMQ server is licensed under the MPL. + +If you have any questions regarding licensing, please contact us at +info@rabbitmq.com. + +=head1 REFERENCES + +RabbitMQ Web Site: http://www.rabbitmq.com diff --git a/docs/rabbitmqctl_real.1.pod b/docs/rabbitmqctl_real.1.pod deleted file mode 100644 index f52eb394..00000000 --- a/docs/rabbitmqctl_real.1.pod +++ /dev/null @@ -1,141 +0,0 @@ -=head1 NAME - -rabbitmqctl_real - command line tool for managing a RabbitMQ broker - -=head1 SYNOPSIS - -rabbitmqctl_real [-n I] I<> [command options] - -=head1 DESCRIPTION - -RabbitMQ is an implementation of AMQP, the emerging standard for high -performance enterprise messaging. The RabbitMQ server is a robust and -scalable implementation of an AMQP broker. - -rabbitmqctl_real is a command line tool for managing a RabbitMQ broker. -It performs all actions by connecting to one of the broker's node. -rabbitmqctl_real is called by the rabbitmqctl(1) wrapper to be -correctly executed with I user permissions. - - -=head1 OPTIONS - -B<-n> I - default node is C, where server is the local host. - On a host named C, the node name of the RabbitMQ - Erlang node will usually be rabbit@server (unless NODENAME has been - set to some non-default value at broker startup time). - The output of hostname -s is usually the correct suffix to use - after the "@" sign. See rabbitmq-server(1) for details of configur- - ing the RabbitMQ broker. - - -=head1 COMMANDS - -=head2 APPLICATION AND CLUSTER MANAGEMENT - -stop - stop the Erlang node on which RabbitMQ broker is running. - -stop_app - stop the RabbitMQ application, leaving the Erlang node running. - This command is typically run prior to performing other management - actions that require the RabbitMQ application to be stopped, - e.g. I. - -start_app - start the RabbitMQ application. - This command is typically run prior to performing other management - actions that require the RabbitMQ application to be stopped, - e.g. I. - -status - display various information about the RabbitMQ broker, such as - whether the RabbitMQ application on the current node, its version - number, what nodes are part of the broker, which of these are - running. - -force - return a RabbitMQ node to its virgin state. - Removes the node from any cluster it belongs to, removes all data - from the management database, such as configured users, vhosts and - realms, and deletes all persistent messages. - -force_reset - the same as I command, but resets the node unconditionally, - regardless of the current management database state and cluster - configuration. - It should only be used as a last resort if the database or cluster - configuration has been corrupted. - -cluster I ... - instruct the node to become member of a cluster with the specified - nodes determined by I option(s). - See http://www.rabbitmq.com/clustering.html for more information - about clustering. - -=head2 USER MANAGEMENT - -add_user I I - create a user named I with (initial) password I. - -change_password I I - change the password for the user named I to I. - -list_users - list all users. - -=head2 ACCESS CONTROL - -add_vhost I - create a new virtual host called I. - -delete_vhost I - delete a virtual host I. - That command deletes also all its exchanges, queues and user mappings. - -list_vhosts - list all virtual hosts. - -map_user_vhost I I - grant the user named I access to the virtual host called - I. - -unmap_user_vhost I I - deny the user named I access to the virtual host called - I. - -list_user_vhost I - list all the virtual hosts to which the user named I has - been granted access. - -=head1 EXAMPLES - -Create a user named foo with (initial) password bar at the Erlang node -rabbit@test: - - rabbitmqctl -n rabbit@test add_user foo bar - -Grant user named foo access to the virtual host called test at the -default Erlang node: - - rabbitmqctl map_user_vhost foo test - -=head1 SEE ALSO - -rabbitmq-server(1), rabbitmqctl(1), rabbitmqctl_real(1) - -=head1 AUTHOR - -Originally written by The RabbitMQ Team - -=head1 COPYRIGHT - -This package, the RabbitMQ server is licensed under the MPL. - -If you have any questions regarding licensing, please contact us at -info@rabbitmq.com. - -=head1 REFERENCES - -RabbitMQ Web Site: http://www.rabbitmq.com diff --git a/docs/rabbitmqctl_real.pod b/docs/rabbitmqctl_real.pod new file mode 100644 index 00000000..f52eb394 --- /dev/null +++ b/docs/rabbitmqctl_real.pod @@ -0,0 +1,141 @@ +=head1 NAME + +rabbitmqctl_real - command line tool for managing a RabbitMQ broker + +=head1 SYNOPSIS + +rabbitmqctl_real [-n I] I<> [command options] + +=head1 DESCRIPTION + +RabbitMQ is an implementation of AMQP, the emerging standard for high +performance enterprise messaging. The RabbitMQ server is a robust and +scalable implementation of an AMQP broker. + +rabbitmqctl_real is a command line tool for managing a RabbitMQ broker. +It performs all actions by connecting to one of the broker's node. +rabbitmqctl_real is called by the rabbitmqctl(1) wrapper to be +correctly executed with I user permissions. + + +=head1 OPTIONS + +B<-n> I + default node is C, where server is the local host. + On a host named C, the node name of the RabbitMQ + Erlang node will usually be rabbit@server (unless NODENAME has been + set to some non-default value at broker startup time). + The output of hostname -s is usually the correct suffix to use + after the "@" sign. See rabbitmq-server(1) for details of configur- + ing the RabbitMQ broker. + + +=head1 COMMANDS + +=head2 APPLICATION AND CLUSTER MANAGEMENT + +stop + stop the Erlang node on which RabbitMQ broker is running. + +stop_app + stop the RabbitMQ application, leaving the Erlang node running. + This command is typically run prior to performing other management + actions that require the RabbitMQ application to be stopped, + e.g. I. + +start_app + start the RabbitMQ application. + This command is typically run prior to performing other management + actions that require the RabbitMQ application to be stopped, + e.g. I. + +status + display various information about the RabbitMQ broker, such as + whether the RabbitMQ application on the current node, its version + number, what nodes are part of the broker, which of these are + running. + +force + return a RabbitMQ node to its virgin state. + Removes the node from any cluster it belongs to, removes all data + from the management database, such as configured users, vhosts and + realms, and deletes all persistent messages. + +force_reset + the same as I command, but resets the node unconditionally, + regardless of the current management database state and cluster + configuration. + It should only be used as a last resort if the database or cluster + configuration has been corrupted. + +cluster I ... + instruct the node to become member of a cluster with the specified + nodes determined by I option(s). + See http://www.rabbitmq.com/clustering.html for more information + about clustering. + +=head2 USER MANAGEMENT + +add_user I I + create a user named I with (initial) password I. + +change_password I I + change the password for the user named I to I. + +list_users + list all users. + +=head2 ACCESS CONTROL + +add_vhost I + create a new virtual host called I. + +delete_vhost I + delete a virtual host I. + That command deletes also all its exchanges, queues and user mappings. + +list_vhosts + list all virtual hosts. + +map_user_vhost I I + grant the user named I access to the virtual host called + I. + +unmap_user_vhost I I + deny the user named I access to the virtual host called + I. + +list_user_vhost I + list all the virtual hosts to which the user named I has + been granted access. + +=head1 EXAMPLES + +Create a user named foo with (initial) password bar at the Erlang node +rabbit@test: + + rabbitmqctl -n rabbit@test add_user foo bar + +Grant user named foo access to the virtual host called test at the +default Erlang node: + + rabbitmqctl map_user_vhost foo test + +=head1 SEE ALSO + +rabbitmq-server(1), rabbitmqctl(1), rabbitmqctl_real(1) + +=head1 AUTHOR + +Originally written by The RabbitMQ Team + +=head1 COPYRIGHT + +This package, the RabbitMQ server is licensed under the MPL. + +If you have any questions regarding licensing, please contact us at +info@rabbitmq.com. + +=head1 REFERENCES + +RabbitMQ Web Site: http://www.rabbitmq.com -- cgit v1.2.1 From 6d1aafed2a92f715954001a96d4dba967350caa1 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 7 Aug 2008 14:47:58 +0100 Subject: Updated rpm notes on building packages --- packaging/RPMS/Fedora/README.txt | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/packaging/RPMS/Fedora/README.txt b/packaging/RPMS/Fedora/README.txt index a7db530b..6f313259 100644 --- a/packaging/RPMS/Fedora/README.txt +++ b/packaging/RPMS/Fedora/README.txt @@ -1,8 +1,7 @@ Notes on creating rpms for rabbitmq -Assuming that rpm will be built under $TOP_DIR/rpm -directory the rpm macros configuration file -would look like: +Assuming that rpm will be built under $TOP_DIR/rpm, +the main configuration variables would look like: %_topdir $TOP_DIR/rpm %_tmppath $TOP_DIR/rpm/tmp @@ -11,11 +10,7 @@ would look like: %_includedir /usr/include %_mandir /usr/share/man -Where $TOP_DIR can be any directory (usually $HOME) -However this configuration has to be under the following -path: -$HOME/.rpmmacros -since this is a fixed place where rpmbuild looks for macros. +Where $TOP_DIR can be any directory (default is $HOME). The $TOP_DIR/rpm directory has following structure: @@ -24,14 +19,14 @@ rpm +---- SOURCES // where source tarballs are put +---- SPECS // directory containing specs +---- SRPMS // rpmbuild puts here srpms - +---- RPMS // rpmbuils puts here rpms - +---- tmp // where rpm packages are built + +---- RPMS // rpmbuils puts here rpms + +---- tmp // where rpm packages are built Makefile will copy the source tarball from fixed directory specified by $TARBALL_DIR to SOURCES directory and similarly specs from $SPEC_DIR to SPECS directory. -'make rpms' should create both client and server rabbitmq. +'make rpms' should create rabbitmq-server package. If there are any errors reported by rpmbuild this is possibly due to incorrect name of the packages (if all dependencies are satisifed) - different distros @@ -39,15 +34,16 @@ can have slightly different names. rpms and srpms are placed in their respective directories. -'make prepare' will create the necessary structure and -create the rpmmacros file. Change top variables to adjust -it to your system. Note that it will *overwrite* any current -rpmmacros configuration file. +'make prepare' will create the necessary structure. +Change main configuration variables specified in the 'DEFINES' +variable in the Makefile to adjust it to your system. +Note that it will *overwrite* any current rpmmacros +configurations. The first thing to do for building rpms is to create you own source tarball of AMQ. In the spec files two top variables determine the name of the tarball. Adjust it to you needs. -The final name has to match the *Source* tag in specs' headers. +The final name has to match the *Source* tag in spec's headers. For information on how to sign the package see: http://fedoranews.org/tchung/gpg/ -- cgit v1.2.1 From 3977f113790eb941acd9ec3ae042bc463c246852 Mon Sep 17 00:00:00 2001 From: Karol Skocik Date: Fri, 8 Aug 2008 15:40:35 +0100 Subject: added mapping which decides how to convert Python value to Erlang default value --- codegen.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/codegen.py b/codegen.py index 1cad996a..7d830efa 100644 --- a/codegen.py +++ b/codegen.py @@ -45,6 +45,13 @@ erlangTypeMap = { 'timestamp': 'timestamp', } +erlangDefaultValueTypeConvMap = { + bool : lambda x: str(x).lower(), + str : lambda x: "<<" + x + ">>", + int : lambda x: str(x), + float : lambda x: str(x) +} + def erlangize(s): s = s.replace('-', '_') s = s.replace(' ', '_') @@ -276,7 +283,8 @@ def genHrl(spec): def fillField(field): result = erlangize(f.name) if field.defaultvalue != None: - result += ' = ' + field.defaultvalue + conv_fn = erlangDefaultValueTypeConvMap[type(field.defaultvalue)] + result += ' = ' + conv_fn(field.defaultvalue) return result return ', '.join([fillField(f) for f in fields]) -- cgit v1.2.1 From 17770414ef76eb4c94dd5ea4d35bb8b3f3757494 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 8 Aug 2008 18:25:11 +0100 Subject: Added required commands to the init.d script for rpm packages. Fixed various things in the spec file for rpm and made it more consistent with approved packaging guidelines. --- packaging/RPMS/Fedora/init.d | 73 +++++++++++++----- packaging/RPMS/Fedora/rabbitmq-server.spec | 120 ++++++++++++----------------- packaging/debs/Debian/debian/init.d | 10 +-- 3 files changed, 110 insertions(+), 93 deletions(-) diff --git a/packaging/RPMS/Fedora/init.d b/packaging/RPMS/Fedora/init.d index 09ca02c9..a7e6b98c 100644 --- a/packaging/RPMS/Fedora/init.d +++ b/packaging/RPMS/Fedora/init.d @@ -1,57 +1,87 @@ #!/bin/sh +# +# rabbitmq-server RabbitMQ broker +# +#chkconfig: 2345 80 05 +#description: Enable AMQP service provided by RabbitMQ +# + ### BEGIN INIT INFO # Provides: rabbitmq # Required-Start: $remote_fs $network # Required-Stop: $remote_fs $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 +# Description: RabbitMQ broker +# Short-Description: Enable AMQP service provided by RabbitMQ broker ### END INIT INFO -#chkconfig: 2345 80 05 -#description: RabbitMQ Server - PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -DAEMON=/usr/sbin/rabbitmq-multi +DAEMON_NAME=rabbitmq-multi +DAEMON=/usr/sbin/$DAEMON_NAME NAME=rabbitmq-server DESC=rabbitmq-server USER=rabbitmq NODE_COUNT=1 +LOCK_FILE=/var/lock/subsys/$NAME + test -x $DAEMON || exit 0 +# source function library +. /etc/rc.d/init.d/functions + # Include rabbitmq defaults if available if [ -f /etc/default/rabbitmq ] ; then . /etc/default/rabbitmq fi +RETVAL=0 set -e cd / start_rabbitmq () { set +e - su rabbitmq -s /bin/sh -c "$DAEMON start_all ${NODE_COUNT}" > /var/log/rabbitmq/startup.log 2> /var/log/rabbitmq/startup.err + su $USER -s /bin/sh -c "$DAEMON start_all ${NODE_COUNT}" > /var/log/rabbitmq/startup.log 2> /var/log/rabbitmq/startup.err case "$?" in 0) - echo SUCCESS;; + echo SUCCESS && touch $LOCK_FILE + ;; 1) - echo TIMEOUT - check /var/log/rabbitmq/startup.\{log,err\};; + echo TIMEOUT - check /var/log/rabbitmq/startup.\{log,err\} + ;; *) echo FAILED - check /var/log/rabbitmq/startup.log, .err - exit 1;; + RETVAL=1;; esac set -e } stop_rabbitmq () { set +e - su rabbitmq -s /bin/sh -c "$DAEMON stop_all" > /var/log/rabbitmq/shutdown.log 2> /var/log/rabbitmq/shutdown.err + su $USER -s /bin/sh -c "$DAEMON stop_all" > /var/log/rabbitmq/shutdown.log 2> /var/log/rabbitmq/shutdown.err + if [ $? != 0 ] ; then echo FAILED - check /var/log/rabbitmq/shutdown.log, .err - exit 0 + RETVAL=$? + else + rm -rf $LOCK_FILE + RETVAL=0 fi set -e } +status_rabbitmq () { + status $NAME +} + +restart_rabbitmq () { + echo -n "Restarting $DESC: " + stop_rabbitmq + start_rabbitmq + echo "$NAME." +} + case "$1" in start) echo -n "Starting $DESC: " @@ -63,17 +93,22 @@ case "$1" in stop_rabbitmq echo "$NAME." ;; - force-reload|restart) - echo -n "Restarting $DESC: " - stop_rabbitmq - start_rabbitmq - echo "$NAME." + force-reload|reload|restart) + restart_rabbitmq + ;; + status) + echo "Status of $DESC: " + status_rabbitmq + RETVAL=$? ;; + condrestart|try-restart) + status_rabbitmq >/dev/null 2>&1 || exit 0 + restart_rabbitmq + ;; *) - N=/etc/init.d/$NAME - echo "Usage: $N {start|stop|restart|force-reload}" >&2 - exit 1 + echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" >&2 + RETVAL=1 ;; esac -exit 0 +exit $RETVAL diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec index 038f6d2d..87530f6e 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.spec +++ b/packaging/RPMS/Fedora/rabbitmq-server.spec @@ -1,72 +1,62 @@ -%define source_name rabbitmq-server - Name: rabbitmq-server Version: %{rpm_version} Release: 1 -License: Mozilla Public License +License: MPLv1.1 Group: Development/Libraries -Source: http://www.rabbitmq.com/releases/%{source_name}-%{main_version}.tar.gz +Source: http://www.rabbitmq.com/releases/rabbitmq-server/v%{main_version}/%{name}-%{main_version}.tar.gz URL: http://www.rabbitmq.com/ Vendor: LShift Ltd., Cohesive Financial Technologies LLC., Rabbit Technlogies Ltd. Requires: erlang Packager: Hubert Plociniczak BuildRoot: %{_tmppath}/%{name}-%{main_version}-%{release}-root Summary: The RabbitMQ server +Requires(post): chkconfig +Requires(pre): chkconfig initscripts %description RabbitMQ is an implementation of AMQP, the emerging standard for high performance enterprise messaging. The RabbitMQ server is a robust and scalable implementation of an AMQP broker. -%define _libdir /usr/lib/erlang -%define _docdir /usr/share/doc + %define _mandir /usr/share/man -%define _maindir $RPM_BUILD_ROOT%{_libdir}/lib/rabbitmq_server-%{main_version} -%define package_name rabbitmq-server-dist +%define _sbindir /usr/sbin +%define _libdir %(erl -noshell -eval "io:format('~s~n', [code:lib_dir()]), halt().") +%define _maindir %{buildroot}%{_libdir}/rabbitmq_server-%{main_version} + %pre if [ $1 -gt 1 ]; then - #Upgrade - stop and remove previous instance of rabbitmq init.d script - /etc/init.d/rabbitmq-server stop + #Upgrade - stop and remove previous instance of rabbitmq-server init.d script + /sbin/service rabbitmq-server stop /sbin/chkconfig --del rabbitmq-server fi %prep -%setup -n %{source_name}-%{main_version} +%setup -n %{name}-%{main_version} %build -mkdir %{package_name} -mkdir %{package_name}/sbin -mkdir %{package_name}/man -make install TARGET_DIR=`pwd`/%{package_name} \ - SBIN_DIR=`pwd`/%{package_name}/sbin \ - MAN_DIR=`pwd`/%{package_name}/man - VERSION=%{main_version} +make %install -mkdir -p %{_maindir} -mkdir -p $RPM_BUILD_ROOT%{_docdir}/rabbitmq-server -mkdir -p $RPM_BUILD_ROOT/etc/init.d -mkdir -p $RPM_BUILD_ROOT/usr/sbin -mkdir -p $RPM_BUILD_ROOT%{_mandir} +rm -rf %{buildroot} + +make install TARGET_DIR=%{_maindir} \ + SBIN_DIR=%{buildroot}%{_sbindir} \ + MAN_DIR=%{buildroot}%{_mandir} + VERSION=%{main_version} -mkdir -p $RPM_BUILD_ROOT/var/lib/rabbitmq/mnesia -mkdir -p $RPM_BUILD_ROOT/var/log/rabbitmq +mkdir -p %{buildroot}/var/lib/rabbitmq/mnesia +mkdir -p %{buildroot}/var/log/rabbitmq +mkdir -p %{buildroot}/etc/rc.d/init.d/ #Copy all necessary lib files etc. -cp -r %{package_name}/ebin %{_maindir} -cp -r %{package_name}/src %{_maindir} -cp -r %{package_name}/include %{_maindir} -chmod 755 %{package_name}/sbin/* -cp %{package_name}/sbin/* $RPM_BUILD_ROOT/usr/sbin/ -cp -r %{package_name}/man/* $RPM_BUILD_ROOT%{_mandir}/ - -cp ../init.d $RPM_BUILD_ROOT/etc/init.d/rabbitmq-server -chmod 775 $RPM_BUILD_ROOT/etc/init.d/rabbitmq-server +cp ../init.d %{buildroot}/etc/rc.d/init.d/rabbitmq-server +chmod 0755 %{buildroot}/etc/rc.d/init.d/rabbitmq-server -mv $RPM_BUILD_ROOT/usr/sbin/rabbitmqctl $RPM_BUILD_ROOT/usr/sbin/rabbitmqctl_real -cp ../rabbitmqctl_wrapper $RPM_BUILD_ROOT/usr/sbin/rabbitmqctl -chmod 755 $RPM_BUILD_ROOT/usr/sbin/rabbitmqctl +mv %{buildroot}/usr/sbin/rabbitmqctl %{buildroot}/usr/sbin/rabbitmqctl_real +cp ../rabbitmqctl_wrapper %{buildroot}/usr/sbin/rabbitmqctl +chmod 0755 %{buildroot}/usr/sbin/rabbitmqctl %post # create rabbitmq group @@ -80,65 +70,57 @@ if ! getent passwd rabbitmq >/dev/null; then usermod -c "Rabbit AMQP Messaging Server" rabbitmq fi -# On 64bit /usr/lib64 contains Erlang, not /usr/lib. Fix with a symlink -ERL_LIB_DIR=$(erl -noshell -eval "io:format(\"~s~n\", [code:lib_dir()]), halt().") -if [ ! ${ERL_LIB_DIR} = "/usr/lib/erlang/lib" ] ; then - ln -s /usr/lib/erlang/lib/rabbitmq_server-%{main_version} ${ERL_LIB_DIR} -fi - chown -R rabbitmq:rabbitmq /var/lib/rabbitmq chown -R rabbitmq:rabbitmq /var/log/rabbitmq -/sbin/chkconfig --add rabbitmq-server -/etc/init.d/rabbitmq-server start +/sbin/chkconfig --add %{name} %preun if [ $1 = 0 ]; then #Complete uninstall - /etc/init.d/rabbitmq-server stop + /sbin/service rabbitmq-server stop /sbin/chkconfig --del rabbitmq-server - - # Remove symlink we added above - ERL_LIB_DIR=$(erl -noshell -eval "io:format(\"~s~n\", [code:lib_dir()]), halt().") - if [ ! ${ERL_LIB_DIR} = "/usr/lib/erlang/lib" ] ; then - rm ${ERL_LIB_DIR}/rabbitmq_server-%{main_version} - fi - # We do not remove log and lib directories + # We do not remove /var/log and /var/lib directories # Leave rabbitmq user and group fi %files -%defattr(-,root,root) -%{_libdir}/lib/rabbitmq_server-%{main_version}/ -%{_docdir}/rabbitmq-server/ -%{_mandir} -/usr/sbin -/var/lib/rabbitmq -/var/log/rabbitmq -/etc/init.d/rabbitmq-server +%defattr(-,root,root,-) +%{_libdir}/rabbitmq_server-%{main_version}/ +%{_mandir}/man1/rabbitmq-multi.1.gz +%{_mandir}/man1/rabbitmq-server.1.gz +%{_mandir}/man1/rabbitmqctl.1.gz +%{_mandir}/man1/rabbitmqctl_real.1.gz +%{_sbindir}/rabbitmq-multi +%{_sbindir}/rabbitmq-server +%{_sbindir}/rabbitmqctl +%{_sbindir}/rabbitmqctl_real +/var/lib/rabbitmq/ +/var/log/rabbitmq/ +/etc/rc.d/init.d/rabbitmq-server %clean -rm -rf $RPM_BUILD_ROOT +rm -rf %{buildroot} %changelog -* Thu Jul 24 2008 Tony Garnock-Jones 1.4.0 +* Thu Jul 24 2008 Tony Garnock-Jones 1.4.0-1 - New upstream release -* Mon Mar 3 2008 Adrien Pierard 1.3.0 +* Mon Mar 3 2008 Adrien Pierard 1.3.0-1 - New upstream release -* Wed Sep 26 2007 Simon MacMullen 1.2.0 +* Wed Sep 26 2007 Simon MacMullen 1.2.0-1 - New upstream release -* Wed Aug 29 2007 Simon MacMullen 1.1.1 +* Wed Aug 29 2007 Simon MacMullen 1.1.1-1 - New upstream release -* Mon Jul 30 2007 Simon MacMullen 1.1.0-alpha +* Mon Jul 30 2007 Simon MacMullen 1.1.0-1.alpha - New upstream release -* Tue Jun 12 2007 Hubert Plociniczak hubert-20070607 +* Tue Jun 12 2007 Hubert Plociniczak 1.0.0-1.20070607 - Building from source tarball, added starting script, stopping -* Mon May 21 2007 Hubert Plociniczak 1.0.0-alpha +* Mon May 21 2007 Hubert Plociniczak 1.0.0-1.alpha - Initial build of server library of RabbitMQ package diff --git a/packaging/debs/Debian/debian/init.d b/packaging/debs/Debian/debian/init.d index f3999888..ae82dd5c 100644 --- a/packaging/debs/Debian/debian/init.d +++ b/packaging/debs/Debian/debian/init.d @@ -5,7 +5,8 @@ # Required-Stop: $remote_fs $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 -# Short-Description: Enable AMQP service provided by RabbitMQ. +# Description: RabbitMQ broker +# Short-Description: Enable AMQP service provided by RabbitMQ broker ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin @@ -27,7 +28,7 @@ cd / start_rabbitmq () { set +e - su rabbitmq -s /bin/sh -c "$DAEMON start_all ${NODE_COUNT}" > /var/log/rabbitmq/startup.log 2> /var/log/rabbitmq/startup.err + su $USER -s /bin/sh -c "$DAEMON start_all ${NODE_COUNT}" > /var/log/rabbitmq/startup.log 2> /var/log/rabbitmq/startup.err case "$?" in 0) echo SUCCESS;; @@ -42,7 +43,7 @@ start_rabbitmq () { stop_rabbitmq () { set +e - su rabbitmq -s /bin/sh -c "$DAEMON stop_all" > /var/log/rabbitmq/shutdown.log 2> /var/log/rabbitmq/shutdown.err + su $USER -s /bin/sh -c "$DAEMON stop_all" > /var/log/rabbitmq/shutdown.log 2> /var/log/rabbitmq/shutdown.err if [ $? != 0 ] ; then echo FAILED - check /var/log/rabbitmq/shutdown.log, .err exit 0 @@ -68,8 +69,7 @@ case "$1" in echo "$NAME." ;; *) - N=/etc/init.d/$NAME - echo "Usage: $N {start|stop|restart|force-reload}" >&2 + echo "Usage: $0 {start|stop|restart|force-reload}" >&2 exit 1 ;; esac -- cgit v1.2.1 From 42f44c9764fc188c1bdf7b03fc45221300bac865 Mon Sep 17 00:00:00 2001 From: Ben Hood <0x6e6562@gmail.com> Date: Mon, 11 Aug 2008 18:49:54 +0100 Subject: Incorporated QA comments --- src/rabbit_channel.erl | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index a116c33d..15e2879b 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -93,7 +93,7 @@ init(ProxyPid, [ReaderPid, WriterPid, Username, VHost]) -> unacked_message_q = queue:new(), username = Username, virtual_host = VHost, - most_recently_declared_queue = none, + most_recently_declared_queue = <<>>, consumer_mapping = dict:new()}. handle_message({method, Method, Content}, State) -> @@ -153,7 +153,8 @@ ok_msg(true, _Msg) -> undefined; ok_msg(false, Msg) -> Msg. return_queue_declare_ok(State, NoWait, Q) -> - NewState = State#ch{most_recently_declared_queue = Q#amqqueue.name}, + NewState = State#ch{most_recently_declared_queue = + (Q#amqqueue.name)#resource.name}, case NoWait of true -> {noreply, NewState}; false -> @@ -161,27 +162,28 @@ return_queue_declare_ok(State, NoWait, Q) -> rabbit_misc:with_exit_handler( fun () -> {ok, Q#amqqueue.name, 0, 0} end, fun () -> rabbit_amqqueue:stat(Q) end), - QueueName = ActualName#resource.name, - Reply = #'queue.declare_ok'{queue = QueueName, + Reply = #'queue.declare_ok'{queue = ActualName#resource.name, message_count = MessageCount, consumer_count = ConsumerCount}, {reply, Reply, NewState} end. -expand_queue_name_shortcut(<<>>, #ch{ most_recently_declared_queue = none }) -> +expand_queue_name_shortcut(<<>>, #ch{ most_recently_declared_queue = <<>> }) -> rabbit_misc:protocol_error( not_allowed, "no previously declared queue", []); -expand_queue_name_shortcut(<<>>, #ch{ most_recently_declared_queue = MRDQ }) -> MRDQ; +expand_queue_name_shortcut(<<>>, #ch{ virtual_host = VHostPath, + most_recently_declared_queue = MRDQ }) -> + rabbit_misc:r(VHostPath, queue, MRDQ); expand_queue_name_shortcut(QueueNameBin, #ch{ virtual_host = VHostPath }) -> rabbit_misc:r(VHostPath, queue, QueueNameBin). expand_routing_key_shortcut(<<>>, <<>>, - #ch{ most_recently_declared_queue = none }) -> + #ch{ most_recently_declared_queue = <<>> }) -> rabbit_misc:protocol_error( not_allowed, "no previously declared queue", []); expand_routing_key_shortcut(<<>>, <<>>, #ch{ most_recently_declared_queue = MRDQ }) -> - MRDQ#resource.name; + MRDQ; expand_routing_key_shortcut(_QueueNameBin, RoutingKey, _State) -> RoutingKey. @@ -529,10 +531,8 @@ handle_method(#'queue.declare'{queue = QueueNameBin, <<>> -> rabbit_misc:binstring_guid("amq.gen"); Other -> check_name('queue', Other) end, - Finish(rabbit_amqqueue:declare(rabbit_misc:r(VHostPath, queue, ActualNameBin), - Durable, - AutoDelete, - Args)); + QueueName = rabbit_misc:r(VHostPath, queue, ActualNameBin), + Finish(rabbit_amqqueue:declare(QueueName, Durable, AutoDelete, Args)); Other -> Other end, return_queue_declare_ok(State, NoWait, Q); -- cgit v1.2.1 From ad7b82ce31bd67cf65e22d17f72680c204a464ab Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 12 Aug 2008 16:38:46 +0100 Subject: Remove man page for wrapper and use the same page as for rabbitmqctl_real. Update debina and rpm packaging to reflect this change. --- docs/rabbitmq-multi.pod | 2 +- docs/rabbitmq-server.pod | 2 +- docs/rabbitmqctl.pod | 37 ------------------------------ docs/rabbitmqctl_real.pod | 14 +++++------ packaging/RPMS/Fedora/rabbitmq-server.spec | 2 ++ packaging/debs/Debian/debian/rules | 1 + 6 files changed, 11 insertions(+), 47 deletions(-) delete mode 100644 docs/rabbitmqctl.pod diff --git a/docs/rabbitmq-multi.pod b/docs/rabbitmq-multi.pod index 0f7aec52..2e3f28c8 100644 --- a/docs/rabbitmq-multi.pod +++ b/docs/rabbitmq-multi.pod @@ -34,7 +34,7 @@ Start 3 local RabbitMQ nodes with unique, sequential port numbers: =head1 SEE ALSO -rabbitmq-server(1), rabbitmqctl(1), rabbitmqctl_real(1) +rabbitmq-server(1), rabbitmqctl(1) =head1 AUTHOR diff --git a/docs/rabbitmq-server.pod b/docs/rabbitmq-server.pod index bf411bc2..1eaf2dfd 100644 --- a/docs/rabbitmq-server.pod +++ b/docs/rabbitmq-server.pod @@ -62,7 +62,7 @@ Run RabbitMQ AMQP server in the background: =head1 SEE ALSO -rabbitmq-multi(1), rabbitmqctl(1), rabbitmqctl_real(1) +rabbitmq-multi(1), rabbitmqctl(1) =head1 AUTHOR diff --git a/docs/rabbitmqctl.pod b/docs/rabbitmqctl.pod deleted file mode 100644 index 602cf751..00000000 --- a/docs/rabbitmqctl.pod +++ /dev/null @@ -1,37 +0,0 @@ -=head1 NAME - -rabbitmqctl - wrapper for the command line tool for managing a RabbitMQ broker - -=head1 SYNOPSIS - -rabbitmqctl I [command options] - -=head1 DESCRIPTION - -RabbitMQ is an implementation of AMQP, the emerging standard for high -performance enterprise messaging. The RabbitMQ server is a robust and -scalable implementation of an AMQP broker. - -rabbitmqctl is a wrapper around rabbitmqctl_real(1) tool and performs -all commands properly with I user permissions. - -See rabbitmqctl_real(1) for the list of available commands. - -=head1 SEE ALSO - -rabbitmq-server(1), rabbitmqctl_real(1), rabbitmq-multi(1) - -=head1 AUTHOR - -Originally written by The RabbitMQ Team - -=head1 COPYRIGHT - -This package, the RabbitMQ server is licensed under the MPL. - -If you have any questions regarding licensing, please contact us at -info@rabbitmq.com. - -=head1 REFERENCES - -RabbitMQ Web Site: http://www.rabbitmq.com diff --git a/docs/rabbitmqctl_real.pod b/docs/rabbitmqctl_real.pod index f52eb394..db31b621 100644 --- a/docs/rabbitmqctl_real.pod +++ b/docs/rabbitmqctl_real.pod @@ -1,10 +1,10 @@ =head1 NAME -rabbitmqctl_real - command line tool for managing a RabbitMQ broker +rabbitmqctl - command line tool for managing a RabbitMQ broker =head1 SYNOPSIS -rabbitmqctl_real [-n I] I<> [command options] +rabbitmqctl [-n I] I<> [command options] =head1 DESCRIPTION @@ -12,10 +12,8 @@ RabbitMQ is an implementation of AMQP, the emerging standard for high performance enterprise messaging. The RabbitMQ server is a robust and scalable implementation of an AMQP broker. -rabbitmqctl_real is a command line tool for managing a RabbitMQ broker. -It performs all actions by connecting to one of the broker's node. -rabbitmqctl_real is called by the rabbitmqctl(1) wrapper to be -correctly executed with I user permissions. +rabbitmqctl is a command line tool for managing a RabbitMQ broker. +It performs all actions by connecting to one of the broker's nodes. =head1 OPTIONS @@ -59,7 +57,7 @@ force return a RabbitMQ node to its virgin state. Removes the node from any cluster it belongs to, removes all data from the management database, such as configured users, vhosts and - realms, and deletes all persistent messages. + deletes all persistent messages. force_reset the same as I command, but resets the node unconditionally, @@ -123,7 +121,7 @@ default Erlang node: =head1 SEE ALSO -rabbitmq-server(1), rabbitmqctl(1), rabbitmqctl_real(1) +rabbitmq-multi(1), rabbitmq-server(1) =head1 AUTHOR diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec index 038f6d2d..25213816 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.spec +++ b/packaging/RPMS/Fedora/rabbitmq-server.spec @@ -68,6 +68,8 @@ mv $RPM_BUILD_ROOT/usr/sbin/rabbitmqctl $RPM_BUILD_ROOT/usr/sbin/rabbitmqctl_rea cp ../rabbitmqctl_wrapper $RPM_BUILD_ROOT/usr/sbin/rabbitmqctl chmod 755 $RPM_BUILD_ROOT/usr/sbin/rabbitmqctl +cp %{buildroot}%{_mandir}/man1/rabbitmqctl.1.gz %{buildroot}%{_mandir}/man1/rabbitmqctl_real.1.gz + %post # create rabbitmq group if ! getent group rabbitmq >/dev/null; then diff --git a/packaging/debs/Debian/debian/rules b/packaging/debs/Debian/debian/rules index 3e05863a..e230aec5 100644 --- a/packaging/debs/Debian/debian/rules +++ b/packaging/debs/Debian/debian/rules @@ -14,5 +14,6 @@ install/rabbitmq-server:: rm $(RABBIT_LIB)/LICENSE* mv $(DEB_DESTDIR)usr/sbin/rabbitmqctl $(DEB_DESTDIR)usr/sbin/rabbitmqctl_real cp debian/rabbitmqctl_wrapper $(DEB_DESTDIR)usr/sbin/rabbitmqctl + cp $(DEB_DESTDIR)usr/share/man/man1/rabbitmqctl.1.gz $(DEB_DESTDIR)usr/share/man/man1/rabbitmqctl_real.1.gz chmod a+x $(DEB_DESTDIR)usr/sbin/rabbitmqctl echo "Tag: usr-lib-in-arch-all" > $(DEB_DESTDIR)usr/share/linda/overrides/rabbitmq-server -- cgit v1.2.1 From bf2a93eea473d9b7d83b43781c7b3e6b01efd52f Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 12 Aug 2008 16:46:40 +0100 Subject: Rename rabbitmqctl_real.pod to rabbitmqctl.pod --- docs/rabbitmqctl.pod | 139 ++++++++++++++++++++++++++++++++++++++++++++++ docs/rabbitmqctl_real.pod | 139 ---------------------------------------------- 2 files changed, 139 insertions(+), 139 deletions(-) create mode 100644 docs/rabbitmqctl.pod delete mode 100644 docs/rabbitmqctl_real.pod diff --git a/docs/rabbitmqctl.pod b/docs/rabbitmqctl.pod new file mode 100644 index 00000000..db31b621 --- /dev/null +++ b/docs/rabbitmqctl.pod @@ -0,0 +1,139 @@ +=head1 NAME + +rabbitmqctl - command line tool for managing a RabbitMQ broker + +=head1 SYNOPSIS + +rabbitmqctl [-n I] I<> [command options] + +=head1 DESCRIPTION + +RabbitMQ is an implementation of AMQP, the emerging standard for high +performance enterprise messaging. The RabbitMQ server is a robust and +scalable implementation of an AMQP broker. + +rabbitmqctl is a command line tool for managing a RabbitMQ broker. +It performs all actions by connecting to one of the broker's nodes. + + +=head1 OPTIONS + +B<-n> I + default node is C, where server is the local host. + On a host named C, the node name of the RabbitMQ + Erlang node will usually be rabbit@server (unless NODENAME has been + set to some non-default value at broker startup time). + The output of hostname -s is usually the correct suffix to use + after the "@" sign. See rabbitmq-server(1) for details of configur- + ing the RabbitMQ broker. + + +=head1 COMMANDS + +=head2 APPLICATION AND CLUSTER MANAGEMENT + +stop + stop the Erlang node on which RabbitMQ broker is running. + +stop_app + stop the RabbitMQ application, leaving the Erlang node running. + This command is typically run prior to performing other management + actions that require the RabbitMQ application to be stopped, + e.g. I. + +start_app + start the RabbitMQ application. + This command is typically run prior to performing other management + actions that require the RabbitMQ application to be stopped, + e.g. I. + +status + display various information about the RabbitMQ broker, such as + whether the RabbitMQ application on the current node, its version + number, what nodes are part of the broker, which of these are + running. + +force + return a RabbitMQ node to its virgin state. + Removes the node from any cluster it belongs to, removes all data + from the management database, such as configured users, vhosts and + deletes all persistent messages. + +force_reset + the same as I command, but resets the node unconditionally, + regardless of the current management database state and cluster + configuration. + It should only be used as a last resort if the database or cluster + configuration has been corrupted. + +cluster I ... + instruct the node to become member of a cluster with the specified + nodes determined by I option(s). + See http://www.rabbitmq.com/clustering.html for more information + about clustering. + +=head2 USER MANAGEMENT + +add_user I I + create a user named I with (initial) password I. + +change_password I I + change the password for the user named I to I. + +list_users + list all users. + +=head2 ACCESS CONTROL + +add_vhost I + create a new virtual host called I. + +delete_vhost I + delete a virtual host I. + That command deletes also all its exchanges, queues and user mappings. + +list_vhosts + list all virtual hosts. + +map_user_vhost I I + grant the user named I access to the virtual host called + I. + +unmap_user_vhost I I + deny the user named I access to the virtual host called + I. + +list_user_vhost I + list all the virtual hosts to which the user named I has + been granted access. + +=head1 EXAMPLES + +Create a user named foo with (initial) password bar at the Erlang node +rabbit@test: + + rabbitmqctl -n rabbit@test add_user foo bar + +Grant user named foo access to the virtual host called test at the +default Erlang node: + + rabbitmqctl map_user_vhost foo test + +=head1 SEE ALSO + +rabbitmq-multi(1), rabbitmq-server(1) + +=head1 AUTHOR + +Originally written by The RabbitMQ Team + +=head1 COPYRIGHT + +This package, the RabbitMQ server is licensed under the MPL. + +If you have any questions regarding licensing, please contact us at +info@rabbitmq.com. + +=head1 REFERENCES + +RabbitMQ Web Site: http://www.rabbitmq.com diff --git a/docs/rabbitmqctl_real.pod b/docs/rabbitmqctl_real.pod deleted file mode 100644 index db31b621..00000000 --- a/docs/rabbitmqctl_real.pod +++ /dev/null @@ -1,139 +0,0 @@ -=head1 NAME - -rabbitmqctl - command line tool for managing a RabbitMQ broker - -=head1 SYNOPSIS - -rabbitmqctl [-n I] I<> [command options] - -=head1 DESCRIPTION - -RabbitMQ is an implementation of AMQP, the emerging standard for high -performance enterprise messaging. The RabbitMQ server is a robust and -scalable implementation of an AMQP broker. - -rabbitmqctl is a command line tool for managing a RabbitMQ broker. -It performs all actions by connecting to one of the broker's nodes. - - -=head1 OPTIONS - -B<-n> I - default node is C, where server is the local host. - On a host named C, the node name of the RabbitMQ - Erlang node will usually be rabbit@server (unless NODENAME has been - set to some non-default value at broker startup time). - The output of hostname -s is usually the correct suffix to use - after the "@" sign. See rabbitmq-server(1) for details of configur- - ing the RabbitMQ broker. - - -=head1 COMMANDS - -=head2 APPLICATION AND CLUSTER MANAGEMENT - -stop - stop the Erlang node on which RabbitMQ broker is running. - -stop_app - stop the RabbitMQ application, leaving the Erlang node running. - This command is typically run prior to performing other management - actions that require the RabbitMQ application to be stopped, - e.g. I. - -start_app - start the RabbitMQ application. - This command is typically run prior to performing other management - actions that require the RabbitMQ application to be stopped, - e.g. I. - -status - display various information about the RabbitMQ broker, such as - whether the RabbitMQ application on the current node, its version - number, what nodes are part of the broker, which of these are - running. - -force - return a RabbitMQ node to its virgin state. - Removes the node from any cluster it belongs to, removes all data - from the management database, such as configured users, vhosts and - deletes all persistent messages. - -force_reset - the same as I command, but resets the node unconditionally, - regardless of the current management database state and cluster - configuration. - It should only be used as a last resort if the database or cluster - configuration has been corrupted. - -cluster I ... - instruct the node to become member of a cluster with the specified - nodes determined by I option(s). - See http://www.rabbitmq.com/clustering.html for more information - about clustering. - -=head2 USER MANAGEMENT - -add_user I I - create a user named I with (initial) password I. - -change_password I I - change the password for the user named I to I. - -list_users - list all users. - -=head2 ACCESS CONTROL - -add_vhost I - create a new virtual host called I. - -delete_vhost I - delete a virtual host I. - That command deletes also all its exchanges, queues and user mappings. - -list_vhosts - list all virtual hosts. - -map_user_vhost I I - grant the user named I access to the virtual host called - I. - -unmap_user_vhost I I - deny the user named I access to the virtual host called - I. - -list_user_vhost I - list all the virtual hosts to which the user named I has - been granted access. - -=head1 EXAMPLES - -Create a user named foo with (initial) password bar at the Erlang node -rabbit@test: - - rabbitmqctl -n rabbit@test add_user foo bar - -Grant user named foo access to the virtual host called test at the -default Erlang node: - - rabbitmqctl map_user_vhost foo test - -=head1 SEE ALSO - -rabbitmq-multi(1), rabbitmq-server(1) - -=head1 AUTHOR - -Originally written by The RabbitMQ Team - -=head1 COPYRIGHT - -This package, the RabbitMQ server is licensed under the MPL. - -If you have any questions regarding licensing, please contact us at -info@rabbitmq.com. - -=head1 REFERENCES - -RabbitMQ Web Site: http://www.rabbitmq.com -- cgit v1.2.1 From e3b70ba2dcea8cc272a83e698343783ac9a5c101 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 12 Aug 2008 16:58:20 +0100 Subject: Remove man source files from windows package --- packaging/windows/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/windows/Makefile b/packaging/windows/Makefile index 077461c5..f9437da7 100644 --- a/packaging/windows/Makefile +++ b/packaging/windows/Makefile @@ -15,6 +15,7 @@ dist: rm -rf $(SOURCE_DIR)/scripts rm -rf $(SOURCE_DIR)/codegen* $(SOURCE_DIR)/Makefile rm -f $(SOURCE_DIR)/BUILD + rm -rf $(SOURCE_DIR)/docs mv $(SOURCE_DIR) $(TARGET_DIR) zip -r $(TARGET_ZIP).zip $(TARGET_DIR) -- cgit v1.2.1 From 78b49db227e7e11b42cf1a02a533aa3a96fef564 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 13 Aug 2008 11:44:00 +0100 Subject: Added logrotate script to debian and rpm packages --- packaging/RPMS/Fedora/Makefile | 1 + packaging/RPMS/Fedora/rabbitmq-server.logrotate | 19 +++++++++++++++++++ packaging/RPMS/Fedora/rabbitmq-server.spec | 8 ++++++-- packaging/debs/Debian/debian/control | 2 +- packaging/debs/Debian/debian/dirs | 1 + .../debs/Debian/debian/rabbitmq-server.logrotate | 19 +++++++++++++++++++ packaging/debs/Debian/debian/rules | 1 + 7 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 packaging/RPMS/Fedora/rabbitmq-server.logrotate create mode 100644 packaging/debs/Debian/debian/rabbitmq-server.logrotate diff --git a/packaging/RPMS/Fedora/Makefile b/packaging/RPMS/Fedora/Makefile index c8e979a7..6cc3579b 100644 --- a/packaging/RPMS/Fedora/Makefile +++ b/packaging/RPMS/Fedora/Makefile @@ -21,6 +21,7 @@ prepare: cp $(TOP_DIR)/rabbitmq-server.spec $(TOP_DIR)/SPECS cp $(TOP_DIR)/init.d $(TOP_DIR)/BUILD cp $(TOP_DIR)/rabbitmqctl_wrapper $(TOP_DIR)/BUILD + cp $(TOP_DIR)/rabbitmq-server.logrotate $(TOP_DIR)/BUILD server: prepare rpmbuild -ba $(TOP_DIR)/SPECS/rabbitmq-server.spec $(DEFINES) --target noarch diff --git a/packaging/RPMS/Fedora/rabbitmq-server.logrotate b/packaging/RPMS/Fedora/rabbitmq-server.logrotate new file mode 100644 index 00000000..002adfdc --- /dev/null +++ b/packaging/RPMS/Fedora/rabbitmq-server.logrotate @@ -0,0 +1,19 @@ +/var/log/rabbitmq/*.log { + size=2M + missingok + rotate 10 + compress + delaycompress + notifempty + create 644 rabbitmq rabbitmq +} + +/var/log/rabbitmq/*.log.back /var/log/rabbitmq/*.err { + weekly + missingok + rotate 10 + compress + delaycompress + notifempty + create 644 rabbitmq rabbitmq +} diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec index d1a70e88..4e39012c 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.spec +++ b/packaging/RPMS/Fedora/rabbitmq-server.spec @@ -6,7 +6,7 @@ Group: Development/Libraries Source: http://www.rabbitmq.com/releases/rabbitmq-server/v%{main_version}/%{name}-%{main_version}.tar.gz URL: http://www.rabbitmq.com/ Vendor: LShift Ltd., Cohesive Financial Technologies LLC., Rabbit Technlogies Ltd. -Requires: erlang +Requires: erlang, logrotate Packager: Hubert Plociniczak BuildRoot: %{_tmppath}/%{name}-%{main_version}-%{release}-root Summary: The RabbitMQ server @@ -60,6 +60,9 @@ chmod 0755 %{buildroot}/usr/sbin/rabbitmqctl cp %{buildroot}%{_mandir}/man1/rabbitmqctl.1.gz %{buildroot}%{_mandir}/man1/rabbitmqctl_real.1.gz +mkdir -p %{buildroot}/etc/logrotate.d +cp ../rabbitmq-server.logrotate %{buildroot}/etc/logrotate.d/rabbitmq-server + %post # create rabbitmq group if ! getent group rabbitmq >/dev/null; then @@ -80,7 +83,7 @@ chown -R rabbitmq:rabbitmq /var/log/rabbitmq %preun if [ $1 = 0 ]; then #Complete uninstall - /sbin/service rabbitmq-server stop + /sbin/service rabbitmq-server stop > /dev/null 2>&1 /sbin/chkconfig --del rabbitmq-server # We do not remove /var/log and /var/lib directories @@ -101,6 +104,7 @@ fi /var/lib/rabbitmq/ /var/log/rabbitmq/ /etc/rc.d/init.d/rabbitmq-server +%config(noreplace) /etc/logrotate.d/rabbitmq-server %clean rm -rf %{buildroot} diff --git a/packaging/debs/Debian/debian/control b/packaging/debs/Debian/debian/control index ae698e1e..0696eca7 100644 --- a/packaging/debs/Debian/debian/control +++ b/packaging/debs/Debian/debian/control @@ -7,7 +7,7 @@ Standards-Version: 3.7.2 Package: rabbitmq-server Architecture: all -Depends: erlang-nox, adduser +Depends: erlang-nox, adduser, logrotate Description: An AMQP server written in Erlang RabbitMQ is an implementation of AMQP, the emerging standard for high performance enterprise messaging. The RabbitMQ server is a robust and diff --git a/packaging/debs/Debian/debian/dirs b/packaging/debs/Debian/debian/dirs index 48db317f..1b15b0c3 100644 --- a/packaging/debs/Debian/debian/dirs +++ b/packaging/debs/Debian/debian/dirs @@ -4,4 +4,5 @@ usr/share/man usr/share/linda/overrides var/lib/rabbitmq/mnesia var/log/rabbitmq +etc/logrotate.d diff --git a/packaging/debs/Debian/debian/rabbitmq-server.logrotate b/packaging/debs/Debian/debian/rabbitmq-server.logrotate new file mode 100644 index 00000000..002adfdc --- /dev/null +++ b/packaging/debs/Debian/debian/rabbitmq-server.logrotate @@ -0,0 +1,19 @@ +/var/log/rabbitmq/*.log { + size=2M + missingok + rotate 10 + compress + delaycompress + notifempty + create 644 rabbitmq rabbitmq +} + +/var/log/rabbitmq/*.log.back /var/log/rabbitmq/*.err { + weekly + missingok + rotate 10 + compress + delaycompress + notifempty + create 644 rabbitmq rabbitmq +} diff --git a/packaging/debs/Debian/debian/rules b/packaging/debs/Debian/debian/rules index e230aec5..606bbfd1 100644 --- a/packaging/debs/Debian/debian/rules +++ b/packaging/debs/Debian/debian/rules @@ -14,6 +14,7 @@ install/rabbitmq-server:: rm $(RABBIT_LIB)/LICENSE* mv $(DEB_DESTDIR)usr/sbin/rabbitmqctl $(DEB_DESTDIR)usr/sbin/rabbitmqctl_real cp debian/rabbitmqctl_wrapper $(DEB_DESTDIR)usr/sbin/rabbitmqctl + cp debian/rabbitmq-server.logrotate $(DEB_DESTDIR)etc/logrotate.d/rabbitmq-server cp $(DEB_DESTDIR)usr/share/man/man1/rabbitmqctl.1.gz $(DEB_DESTDIR)usr/share/man/man1/rabbitmqctl_real.1.gz chmod a+x $(DEB_DESTDIR)usr/sbin/rabbitmqctl echo "Tag: usr-lib-in-arch-all" > $(DEB_DESTDIR)usr/share/linda/overrides/rabbitmq-server -- cgit v1.2.1 From 34a2db17b64cdc62497c765de6e41b590abb0628 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 14 Aug 2008 08:18:52 +0100 Subject: cosmetic changes --- include/rabbit.hrl | 12 +++++++----- src/rabbit.erl | 4 ++-- src/rabbit_access_control.erl | 10 ++++++++-- src/rabbit_amqqueue.erl | 6 +++--- src/rabbit_channel.erl | 6 ++++-- src/rabbit_exchange.erl | 10 +++++----- 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/include/rabbit.hrl b/include/rabbit.hrl index a83c0971..cc8fb1b5 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -30,11 +30,13 @@ -record(connection, {user, timeout_sec, frame_max, vhost}). --record(content, {class_id, - properties, %% either 'none', or a decoded record/tuple - properties_bin, %% either 'none', or an encoded properties binary - %% Note: at most one of properties and properties_bin can be 'none' at once. - payload_fragments_rev %% list of binaries, in reverse order (!) +-record(content, + {class_id, + properties, %% either 'none', or a decoded record/tuple + properties_bin, %% either 'none', or an encoded properties binary + %% Note: at most one of properties and properties_bin can be + %% 'none' at once. + payload_fragments_rev %% list of binaries, in reverse order (!) }). -record(resource, {virtual_host, kind, name}). diff --git a/src/rabbit.erl b/src/rabbit.erl index a45b927b..9ab6b1a6 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -128,9 +128,9 @@ start(normal, []) -> io:format("starting ~-20s ...", [Msg]), Thunk(), io:format("done~n"); - ({Msg, M, F, A}) -> + ({Msg, M, F, A}) -> io:format("starting ~-20s ...", [Msg]), - apply(M, F, A), + apply(M, F, A), io:format("done~n") end, [{"database", diff --git a/src/rabbit_access_control.erl b/src/rabbit_access_control.erl index 9bc96514..4342e15b 100644 --- a/src/rabbit_access_control.erl +++ b/src/rabbit_access_control.erl @@ -173,8 +173,14 @@ add_vhost(VHostPath) -> case mnesia:read({vhost, VHostPath}) of [] -> ok = mnesia:write(#vhost{virtual_host = VHostPath}), - [ rabbit_exchange:declare(rabbit_misc:r(VHostPath, exchange, Name), Type, true, false, []) || {Name,Type} - <- [{<<"">>, direct}, { <<"amq.direct">>, direct}, {<<"amq.topic">>, topic}, {<<"amq.fanout">>, fanout}]], + [rabbit_exchange:declare( + rabbit_misc:r(VHostPath, exchange, Name), + Type, true, false, []) || + {Name,Type} <- + [{<<"">>, direct}, + {<<"amq.direct">>, direct}, + {<<"amq.topic">>, topic}, + {<<"amq.fanout">>, fanout}]], ok; [_] -> mnesia:abort({vhost_already_exists, VHostPath}) diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 1be24761..7ce350d8 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -130,7 +130,7 @@ recover_durable_queues() -> ok end). -declare(QueueName = #resource{}, Durable, AutoDelete, Args) -> +declare(QueueName, Durable, AutoDelete, Args) -> Q = start_queue_process(#amqqueue{name = QueueName, durable = Durable, auto_delete = AutoDelete, @@ -360,8 +360,8 @@ on_node_down(Node) -> node(Pid) == Node])) end). -pseudo_queue(Resource = #resource{}, Pid) -> - #amqqueue{name = Resource, +pseudo_queue(QueueName, Pid) -> + #amqqueue{name = QueueName, durable = false, auto_delete = false, arguments = [], diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 15e2879b..caa63b58 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -532,7 +532,8 @@ handle_method(#'queue.declare'{queue = QueueNameBin, Other -> check_name('queue', Other) end, QueueName = rabbit_misc:r(VHostPath, queue, ActualNameBin), - Finish(rabbit_amqqueue:declare(QueueName, Durable, AutoDelete, Args)); + Finish(rabbit_amqqueue:declare(QueueName, + Durable, AutoDelete, Args)); Other -> Other end, return_queue_declare_ok(State, NoWait, Q); @@ -549,7 +550,8 @@ handle_method(#'queue.delete'{queue = QueueNameBin, if_unused = IfUnused, if_empty = IfEmpty, nowait = NoWait - },_, State) -> + }, + _, State) -> QueueName = expand_queue_name_shortcut(QueueNameBin, State), case rabbit_amqqueue:with_or_die( QueueName, diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index cd5511aa..bb132a50 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -90,7 +90,7 @@ recover_durable_exchanges() -> end, ok, durable_exchanges) end). -declare(ExchangeName = #resource{}, Type, Durable, AutoDelete, Args) -> +declare(ExchangeName, Type, Durable, AutoDelete, Args) -> Exchange = #exchange{name = ExchangeName, type = Type, durable = Durable, @@ -145,10 +145,10 @@ list_vhost_exchanges(VHostPath) -> list_exchange_bindings(Name) -> [{QueueName, RoutingKey, Arguments} || - #binding{handlers = Handlers} <- bindings_for_exchange(Name), - #handler{binding_spec = #binding_spec{routing_key = RoutingKey, - arguments = Arguments}, - queue = QueueName} <- Handlers]. + #binding{handlers = Handlers} <- bindings_for_exchange(Name), + #handler{binding_spec = #binding_spec{routing_key = RoutingKey, + arguments = Arguments}, + queue = QueueName} <- Handlers]. bindings_for_exchange(Name) -> qlc:e(qlc:q([B || B = #binding{key = K} <- mnesia:table(binding), -- cgit v1.2.1 From e311be27485b3bcf9245cf83f2ffdb14326105c0 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 14 Aug 2008 08:23:56 +0100 Subject: more restrictive signature for rabbit_misc:r/3 --- src/rabbit_misc.erl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 2c57b16c..11ab0caf 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -66,8 +66,7 @@ -spec(get_config/2 :: (atom(), A) -> A). -spec(set_config/2 :: (atom(), any()) -> 'ok'). -spec(dirty_read/1 :: ({atom(), any()}) -> {'ok', any()} | not_found()). --spec(r/3 :: (#resource{virtual_host :: vhost()} | vhost(), K, name()) -> - r(K) when is_subtype(K, atom())). +-spec(r/3 :: (vhost(), K, name()) -> r(K) when is_subtype(K, atom())). -spec(r/2 :: (vhost(), K) -> #resource{virtual_host :: vhost(), kind :: K, name :: '_'} -- cgit v1.2.1 From 94689e0505b17cb4fb9227bb77cbf0e6f5c143e5 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 14 Aug 2008 11:30:20 +0100 Subject: Added reopen_logs command to rabbit_control --- src/rabbit.erl | 27 ++++++++++++++++++++++++++- src/rabbit_control.erl | 5 +++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index e65d532b..86f5d774 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -27,7 +27,7 @@ -behaviour(application). --export([start/0, stop/0, stop_and_halt/0, status/0]). +-export([start/0, stop/0, stop_and_halt/0, status/0, reopen_logs/0]). -export([start/2, stop/1]). @@ -49,6 +49,7 @@ -spec(start/0 :: () -> 'ok'). -spec(stop/0 :: () -> 'ok'). -spec(stop_and_halt/0 :: () -> 'ok'). +-spec(reopen_logs/0 :: () -> 'ok'). -spec(status/0 :: () -> [{running_applications, [{atom(), string(), string()}]} | {nodes, [node()]} | @@ -85,6 +86,10 @@ status() -> [{running_applications, application:which_applications()}] ++ rabbit_mnesia:status(). +reopen_logs() -> + ok = reopen_main_logs(), + ok = reopen_sasl_logs(). + %%-------------------------------------------------------------------- manage_applications(Iterate, Do, Undo, SkipError, ErrorTag, Apps) -> @@ -280,3 +285,23 @@ sasl_log_location() -> {ok, Bad} -> throw({error, {cannot_log_to_file, Bad}}); _ -> undefined end. + +reopen_main_logs() -> + case error_log_location() of + tty -> ok; + File -> error_logger:swap_handler({logfile, File}) + end. + +reopen_sasl_logs() -> + try + case sasl_log_location() of + undefined -> ok; + tty -> ok; + {file, File} -> gen_event:swap_handler(error_logger, + {sasl_error_logger, swap}, + {sasl_report_file_h, File}); + _ -> ok + end + catch + _ -> ok + end. diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index ad796b61..115af8a6 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -73,6 +73,7 @@ Available commands: force_reset cluster ... status + reopen_logs add_user delete_user @@ -124,6 +125,10 @@ action(reset, Node, []) -> io:format("Resetting node ~p ...", [Node]), call(Node, {rabbit_mnesia, reset, []}); +action(reopen_logs, Node, []) -> + io:format("Reopening logs for node ~p ...", [Node]), + call(Node, {rabbit, reopen_logs, []}); + action(force_reset, Node, []) -> io:format("Forcefully resetting node ~p ...", [Node]), call(Node, {rabbit_mnesia, force_reset, []}); -- cgit v1.2.1 From 6599426640e8863f65684f557e17f207be8e6038 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 14 Aug 2008 13:43:40 +0100 Subject: SCRIPT_HOME variable in windows points to the directory of the rabbitmq-multi.bat script --- scripts/rabbitmq-multi.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/rabbitmq-multi.bat b/scripts/rabbitmq-multi.bat index d1b7b000..819c99af 100644 --- a/scripts/rabbitmq-multi.bat +++ b/scripts/rabbitmq-multi.bat @@ -41,7 +41,7 @@ if "%NODE_PORT%"=="" ( ) set PIDS_FILE=%RABBITMQ_BASE%\rabbitmq.pids -set SCRIPT_HOME=. +set SCRIPT_HOME=%~dp0% if "%ERLANG_HOME%"=="" ( set ERLANG_HOME=%~dp0%..\..\.. -- cgit v1.2.1 From 48e0f08f2f2c264bba63f7c3718c9a9b382efa1e Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 14 Aug 2008 14:26:44 +0100 Subject: Added reopen_logs command to man pages --- docs/rabbitmqctl.pod | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/rabbitmqctl.pod b/docs/rabbitmqctl.pod index db31b621..ebe0cd43 100644 --- a/docs/rabbitmqctl.pod +++ b/docs/rabbitmqctl.pod @@ -66,6 +66,11 @@ force_reset It should only be used as a last resort if the database or cluster configuration has been corrupted. +reopen_logs + instruct the RabbitMQ node to close and reopen the log files. + This command might be helpful when you are e.g. writing your own + logrotate script and you do not want to restart the RabbitMQ node. + cluster I ... instruct the node to become member of a cluster with the specified nodes determined by I option(s). -- cgit v1.2.1 From 6641d07f5f867847c80521c22d2c080bebab759b Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 14 Aug 2008 17:58:19 +0100 Subject: Use postrotate script to reopen logs and sharedscripts option in logrotate. Removed .bak mechanism from linux/unix distros. --- packaging/RPMS/Fedora/rabbitmq-server.logrotate | 18 ++++++------------ packaging/debs/Debian/debian/rabbitmq-server.logrotate | 18 ++++++------------ scripts/rabbitmq-server | 4 ---- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/packaging/RPMS/Fedora/rabbitmq-server.logrotate b/packaging/RPMS/Fedora/rabbitmq-server.logrotate index 002adfdc..e366f36a 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.logrotate +++ b/packaging/RPMS/Fedora/rabbitmq-server.logrotate @@ -1,14 +1,4 @@ -/var/log/rabbitmq/*.log { - size=2M - missingok - rotate 10 - compress - delaycompress - notifempty - create 644 rabbitmq rabbitmq -} - -/var/log/rabbitmq/*.log.back /var/log/rabbitmq/*.err { +/var/log/rabbitmq/*.log /var/log/rabbitmq/*.err { weekly missingok rotate 10 @@ -16,4 +6,8 @@ delaycompress notifempty create 644 rabbitmq rabbitmq -} + sharedscripts + postrotate + /usr/sbin/rabbitmqctl reopen_logs + endscript +} \ No newline at end of file diff --git a/packaging/debs/Debian/debian/rabbitmq-server.logrotate b/packaging/debs/Debian/debian/rabbitmq-server.logrotate index 002adfdc..e366f36a 100644 --- a/packaging/debs/Debian/debian/rabbitmq-server.logrotate +++ b/packaging/debs/Debian/debian/rabbitmq-server.logrotate @@ -1,14 +1,4 @@ -/var/log/rabbitmq/*.log { - size=2M - missingok - rotate 10 - compress - delaycompress - notifempty - create 644 rabbitmq rabbitmq -} - -/var/log/rabbitmq/*.log.back /var/log/rabbitmq/*.err { +/var/log/rabbitmq/*.log /var/log/rabbitmq/*.err { weekly missingok rotate 10 @@ -16,4 +6,8 @@ delaycompress notifempty create 644 rabbitmq rabbitmq -} + sharedscripts + postrotate + /usr/sbin/rabbitmqctl reopen_logs + endscript +} \ No newline at end of file diff --git a/scripts/rabbitmq-server b/scripts/rabbitmq-server index a44dd6da..5368c04c 100755 --- a/scripts/rabbitmq-server +++ b/scripts/rabbitmq-server @@ -39,10 +39,6 @@ CLUSTER_CONFIG_FILE=/etc/default/rabbitmq_cluster.config ## Log rotation LOGS="${LOG_BASE}/${NODENAME}.log" SASL_LOGS="${LOG_BASE}/${NODENAME}-sasl.log" -BACKUP_EXTENSION=".bak" - -[ -f "${LOGS}" ] && cat "${LOGS}" >> "${LOGS}${BACKUP_EXTENSION}" -[ -f "${SASL_LOGS}" ] && cat "${SASL_LOGS}" >> "${SASL_LOGS}${BACKUP_EXTENSION}" if [ -f "$CLUSTER_CONFIG_FILE" ]; then CLUSTER_CONFIG="-rabbit cluster_config \"$CLUSTER_CONFIG_FILE\"" -- cgit v1.2.1 From 8492ce1159df144163364c8110eb149dfe995ae8 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 15 Aug 2008 12:24:24 +0100 Subject: Fixed qa remarks --- src/rabbit.erl | 21 ++++++++------------- src/rabbit_control.erl | 8 ++++---- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index 69f72bfd..5d014158 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -268,20 +268,15 @@ sasl_log_location() -> reopen_main_logs() -> case error_log_location() of - tty -> ok; - File -> error_logger:swap_handler({logfile, File}) + tty -> ok; + File -> error_logger:swap_handler({logfile, File}) end. reopen_sasl_logs() -> - try - case sasl_log_location() of - undefined -> ok; - tty -> ok; - {file, File} -> gen_event:swap_handler(error_logger, - {sasl_error_logger, swap}, - {sasl_report_file_h, File}); - _ -> ok - end - catch - _ -> ok + case sasl_log_location() of + undefined -> ok; + tty -> ok; + File -> gen_event:swap_handler(error_logger, + {sasl_error_logger, swap}, + {sasl_report_file_h, File}); end. diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 999e5fdd..5879c811 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -114,10 +114,6 @@ action(reset, Node, []) -> io:format("Resetting node ~p ...", [Node]), call(Node, {rabbit_mnesia, reset, []}); -action(reopen_logs, Node, []) -> - io:format("Reopening logs for node ~p ...", [Node]), - call(Node, {rabbit, reopen_logs, []}); - action(force_reset, Node, []) -> io:format("Forcefully resetting node ~p ...", [Node]), call(Node, {rabbit_mnesia, force_reset, []}); @@ -134,6 +130,10 @@ action(status, Node, []) -> io:format("~n~p~n", [Res]), ok; +action(reopen_logs, Node, []) -> + io:format("Reopening logs for node ~p ...", [Node]), + call(Node, {rabbit, reopen_logs, []}); + action(add_user, Node, Args = [Username, _Password]) -> io:format("Creating user ~p ...", [Username]), call(Node, {rabbit_access_control, add_user, Args}); -- cgit v1.2.1 From e89e0f2280f575d897c80ea254189b4517fd3c1c Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 15 Aug 2008 12:29:04 +0100 Subject: Forgot to remove semicolon --- src/rabbit.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index 5d014158..7d738ff7 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -278,5 +278,5 @@ reopen_sasl_logs() -> tty -> ok; File -> gen_event:swap_handler(error_logger, {sasl_error_logger, swap}, - {sasl_report_file_h, File}); + {sasl_report_file_h, File}) end. -- cgit v1.2.1 From 17829f7daf06af1014289d45f7788943b80065ec Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Mon, 18 Aug 2008 12:11:58 +0100 Subject: Added optional argument that specifies the suffix of the old log file. Using add_handler and delete_handler because swap_handlers doesn't behave as expected. --- docs/rabbitmqctl.pod | 6 +++++- src/rabbit.erl | 54 +++++++++++++++++++++++++++++++++++++++++--------- src/rabbit_control.erl | 5 ++++- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/docs/rabbitmqctl.pod b/docs/rabbitmqctl.pod index ebe0cd43..d7f453fb 100644 --- a/docs/rabbitmqctl.pod +++ b/docs/rabbitmqctl.pod @@ -66,8 +66,12 @@ force_reset It should only be used as a last resort if the database or cluster configuration has been corrupted. -reopen_logs +reopen_logs [suffix] instruct the RabbitMQ node to close and reopen the log files. + When I value is provided, the RabbitMQ broker will attempt + to rename the current log file to the file with appended suffix. + If file with the original name and suffix already exists, then + file renaming operation is aborted. This command might be helpful when you are e.g. writing your own logrotate script and you do not want to restart the RabbitMQ node. diff --git a/src/rabbit.erl b/src/rabbit.erl index 7d738ff7..a5a74231 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -27,7 +27,7 @@ -behaviour(application). --export([start/0, stop/0, stop_and_halt/0, status/0, reopen_logs/0]). +-export([start/0, stop/0, stop_and_halt/0, status/0, reopen_logs/0, reopen_logs/1]). -export([start/2, stop/1]). @@ -39,6 +39,7 @@ -include("rabbit_framing.hrl"). -include("rabbit.hrl"). +-include_lib("kernel/include/file.hrl"). -define(APPS, [os_mon, mnesia, rabbit]). @@ -50,6 +51,7 @@ -spec(stop/0 :: () -> 'ok'). -spec(stop_and_halt/0 :: () -> 'ok'). -spec(reopen_logs/0 :: () -> 'ok'). +-spec(reopen_logs/1 :: name() -> 'ok'). -spec(status/0 :: () -> [{running_applications, [{atom(), string(), string()}]} | {nodes, [node()]} | @@ -87,8 +89,13 @@ status() -> rabbit_mnesia:status(). reopen_logs() -> - ok = reopen_main_logs(), - ok = reopen_sasl_logs(). + ok = reopen_main_logs([]), + ok = reopen_sasl_logs([]). + +reopen_logs(Suffix) -> + LSuffix = binary_to_list(Suffix), + ok = reopen_main_logs(LSuffix), + ok = reopen_sasl_logs(LSuffix). %%-------------------------------------------------------------------- @@ -266,17 +273,46 @@ sasl_log_location() -> _ -> undefined end. -reopen_main_logs() -> +sasl_error_logger_type() -> + case application:get_env(sasl, errlog_type) of + {ok, error} -> error; + {ok, progress} -> progress; + {ok, all} -> all; + {ok, Bad} -> throw({error, {wrong_errlog_type, Bad}}); + _ -> all + end. + +reopen_main_logs(Suffix) -> case error_log_location() of tty -> ok; - File -> error_logger:swap_handler({logfile, File}) + File -> error_logger:delete_report_handler(error_logger_file_h), + rotate_log_file(File, Suffix), + error_logger:add_report_handler(error_logger_file_h,File) end. -reopen_sasl_logs() -> +reopen_sasl_logs(Suffix) -> case sasl_log_location() of undefined -> ok; tty -> ok; - File -> gen_event:swap_handler(error_logger, - {sasl_error_logger, swap}, - {sasl_report_file_h, File}) + File -> error_logger:delete_report_handler(sasl_report_file_h), + rotate_log_file(File,Suffix), + error_logger:add_report_handler(sasl_report_file_h, + {File, sasl_error_logger_type()}) + end. + +rotate_log_file(File, Suffix) -> + case file:read_file_info(File) of + {ok, FInfo} -> rename_log_file(File, FInfo#file_info.size, Suffix); + {error, _} -> ok + end. + +rename_log_file(_, 0, _) -> + ok; +rename_log_file(_, _, []) -> + ok; +rename_log_file(File, _, Suffix) -> + case file:read_file_info([File,Suffix]) of + {ok, _} -> ok; + {error, enoent} -> file:rename(File, [File, Suffix]); + {error, _} -> ok end. diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 5879c811..4c1b92bb 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -73,7 +73,7 @@ Available commands: force_reset cluster ... status - reopen_logs + reopen_logs [Suffix] add_user delete_user @@ -133,6 +133,9 @@ action(status, Node, []) -> action(reopen_logs, Node, []) -> io:format("Reopening logs for node ~p ...", [Node]), call(Node, {rabbit, reopen_logs, []}); +action(reopen_logs, Node, Args = [Suffix]) -> + io:format("Moving logs to files with suffix ~p and reopening logs ...", [Suffix]), + call(Node, {rabbit, reopen_logs, Args}); action(add_user, Node, Args = [Username, _Password]) -> io:format("Creating user ~p ...", [Username]), -- cgit v1.2.1 From 88dd39bb9d1074d1c20946e00ae9cc3b032f7d61 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 19 Aug 2008 14:48:03 +0100 Subject: Used swap_handler mechanism provided in error_logger to correctly reopen_logs. This creates another copy of the handler which has to be manually removed. Apparently the first one in the list is the old one. Updated man pages. --- docs/rabbitmqctl.pod | 13 +++++--- scripts/rabbitmq-server | 2 +- scripts/rabbitmq-server.bat | 2 +- src/rabbit.erl | 77 ++++++++++++++++++++++----------------------- 4 files changed, 48 insertions(+), 46 deletions(-) diff --git a/docs/rabbitmqctl.pod b/docs/rabbitmqctl.pod index d7f453fb..eb1750d0 100644 --- a/docs/rabbitmqctl.pod +++ b/docs/rabbitmqctl.pod @@ -68,10 +68,10 @@ force_reset reopen_logs [suffix] instruct the RabbitMQ node to close and reopen the log files. - When I value is provided, the RabbitMQ broker will attempt - to rename the current log file to the file with appended suffix. - If file with the original name and suffix already exists, then - file renaming operation is aborted. + When the I value is provided, the RabbitMQ broker will + attempt to append the current contents of the log file to the file + with name composed of the original name and the suffix. It will + create a new file if such a file does not already exist. This command might be helpful when you are e.g. writing your own logrotate script and you do not want to restart the RabbitMQ node. @@ -127,6 +127,11 @@ Grant user named foo access to the virtual host called test at the default Erlang node: rabbitmqctl map_user_vhost foo test + +Append current logs' content to the files with ".1" suffix and reopen +them: + + rabbitmqctl reopen_logs .1 =head1 SEE ALSO diff --git a/scripts/rabbitmq-server b/scripts/rabbitmq-server index a44dd6da..d78be18e 100755 --- a/scripts/rabbitmq-server +++ b/scripts/rabbitmq-server @@ -39,7 +39,7 @@ CLUSTER_CONFIG_FILE=/etc/default/rabbitmq_cluster.config ## Log rotation LOGS="${LOG_BASE}/${NODENAME}.log" SASL_LOGS="${LOG_BASE}/${NODENAME}-sasl.log" -BACKUP_EXTENSION=".bak" +BACKUP_EXTENSION=".1" [ -f "${LOGS}" ] && cat "${LOGS}" >> "${LOGS}${BACKUP_EXTENSION}" [ -f "${SASL_LOGS}" ] && cat "${SASL_LOGS}" >> "${SASL_LOGS}${BACKUP_EXTENSION}" diff --git a/scripts/rabbitmq-server.bat b/scripts/rabbitmq-server.bat index 46f4bd92..a32fe0fc 100644 --- a/scripts/rabbitmq-server.bat +++ b/scripts/rabbitmq-server.bat @@ -65,7 +65,7 @@ set LOG_BASE=%RABBITMQ_BASE_UNIX%/log rem We save the previous logs in their respective backup rem Log management (rotation, filtering based of size...) is left as an exercice for the user. -set BACKUP_EXTENSION=.bak +set BACKUP_EXTENSION=.1 set LOGS="%RABBITMQ_BASE%\log\%NODENAME%.log" set SASL_LOGS="%RABBITMQ_BASE%\log\%NODENAME%-sasl.log" diff --git a/src/rabbit.erl b/src/rabbit.erl index a5a74231..3de40378 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -51,7 +51,7 @@ -spec(stop/0 :: () -> 'ok'). -spec(stop_and_halt/0 :: () -> 'ok'). -spec(reopen_logs/0 :: () -> 'ok'). --spec(reopen_logs/1 :: name() -> 'ok'). +-spec(reopen_logs/1 :: name() -> 'ok' | {'error', 'cannot_append_logfile'}). -spec(status/0 :: () -> [{running_applications, [{atom(), string(), string()}]} | {nodes, [node()]} | @@ -89,13 +89,15 @@ status() -> rabbit_mnesia:status(). reopen_logs() -> - ok = reopen_main_logs([]), - ok = reopen_sasl_logs([]). + ok = reopen_logs(error_log_location(), [], main_log), + ok = reopen_logs(sasl_log_location(), [], sasl_log). reopen_logs(Suffix) -> LSuffix = binary_to_list(Suffix), - ok = reopen_main_logs(LSuffix), - ok = reopen_sasl_logs(LSuffix). + case reopen_logs(error_log_location(), LSuffix, main_log) of + ok -> reopen_logs(sasl_log_location(), LSuffix, sasl_log); + Error -> Error + end. %%-------------------------------------------------------------------- @@ -273,46 +275,41 @@ sasl_log_location() -> _ -> undefined end. -sasl_error_logger_type() -> - case application:get_env(sasl, errlog_type) of - {ok, error} -> error; - {ok, progress} -> progress; - {ok, all} -> all; - {ok, Bad} -> throw({error, {wrong_errlog_type, Bad}}); - _ -> all - end. - -reopen_main_logs(Suffix) -> - case error_log_location() of - tty -> ok; - File -> error_logger:delete_report_handler(error_logger_file_h), - rotate_log_file(File, Suffix), - error_logger:add_report_handler(error_logger_file_h,File) - end. - -reopen_sasl_logs(Suffix) -> - case sasl_log_location() of +reopen_logs(File, Suffix,Swap) -> + case File of undefined -> ok; tty -> ok; - File -> error_logger:delete_report_handler(sasl_report_file_h), - rotate_log_file(File,Suffix), - error_logger:add_report_handler(sasl_report_file_h, - {File, sasl_error_logger_type()}) + _ -> case append_to_log_file(File, Suffix) of + omit -> swap_handler(Swap, File); + ok -> swap_handler(Swap, File); + Error -> Error + end end. -rotate_log_file(File, Suffix) -> +swap_handler(main_log, File) -> + error_logger:swap_handler({logfile, File}), + error_logger:delete_report_handler(error_logger_file_h), + ok; +swap_handler(sasl_log, File ) -> + gen_event:swap_handler(error_logger, + {error_logger, swap}, + {sasl_report_file_h, File}), + gen_event:add_handler(error_logger, error_logger, []), + error_logger:delete_report_handler(sasl_report_file_h), + ok. + +append_to_log_file(File, Suffix) -> case file:read_file_info(File) of - {ok, FInfo} -> rename_log_file(File, FInfo#file_info.size, Suffix); - {error, _} -> ok + {ok, FInfo} -> append_file(File, FInfo#file_info.size, Suffix); + {error, _} -> ok end. -rename_log_file(_, 0, _) -> - ok; -rename_log_file(_, _, []) -> - ok; -rename_log_file(File, _, Suffix) -> - case file:read_file_info([File,Suffix]) of - {ok, _} -> ok; - {error, enoent} -> file:rename(File, [File, Suffix]); - {error, _} -> ok +append_file(_, 0, _) -> + omit; +append_file(_, _, []) -> + omit; +append_file(File, _, Suffix) -> + case file:read_file(File) of + {ok, Data} -> file:write_file([File, Suffix], Data, [append]); + {error, _} -> {error, cannot_append_logfile} end. -- cgit v1.2.1 From 433b04ce96873023190557df81f570afd3999c5e Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 26 Aug 2008 13:25:55 +0100 Subject: Added wrappers around standard error_logger_file_h and sasl_report_file_h modules, because they were not expecting proper arguments in init/1 when swapping handlers. Renamed reopen_logs to rotate_logs. --- docs/rabbitmqctl.pod | 13 ++++---- src/rabbit.erl | 57 +++++++++++++++++++---------------- src/rabbit_control.erl | 12 ++++---- src/rabbit_error_logger_file_h.erl | 52 ++++++++++++++++++++++++++++++++ src/rabbit_sasl_report_file_h.erl | 61 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 157 insertions(+), 38 deletions(-) create mode 100644 src/rabbit_error_logger_file_h.erl create mode 100644 src/rabbit_sasl_report_file_h.erl diff --git a/docs/rabbitmqctl.pod b/docs/rabbitmqctl.pod index eb1750d0..d6e0bac7 100644 --- a/docs/rabbitmqctl.pod +++ b/docs/rabbitmqctl.pod @@ -66,12 +66,13 @@ force_reset It should only be used as a last resort if the database or cluster configuration has been corrupted. -reopen_logs [suffix] - instruct the RabbitMQ node to close and reopen the log files. - When the I value is provided, the RabbitMQ broker will - attempt to append the current contents of the log file to the file - with name composed of the original name and the suffix. It will - create a new file if such a file does not already exist. +rotate_logs [suffix] + instruct the RabbitMQ node to rotate the log files. The RabbitMQ + broker will attempt to append the current contents of the log file + to the file with name composed of the original name and the suffix. + It will create a new file if such a file does not already exist. + When no I is specified, the log file is simply reopened; + no rotation takes place. This command might be helpful when you are e.g. writing your own logrotate script and you do not want to restart the RabbitMQ node. diff --git a/src/rabbit.erl b/src/rabbit.erl index 3de40378..c82e0a13 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -27,7 +27,7 @@ -behaviour(application). --export([start/0, stop/0, stop_and_halt/0, status/0, reopen_logs/0, reopen_logs/1]). +-export([start/0, stop/0, stop_and_halt/0, status/0, rotate_logs/0, rotate_logs/1]). -export([start/2, stop/1]). @@ -50,8 +50,8 @@ -spec(start/0 :: () -> 'ok'). -spec(stop/0 :: () -> 'ok'). -spec(stop_and_halt/0 :: () -> 'ok'). --spec(reopen_logs/0 :: () -> 'ok'). --spec(reopen_logs/1 :: name() -> 'ok' | {'error', 'cannot_append_logfile'}). +-spec(rotate_logs/0 :: () -> 'ok'). +-spec(rotate_logs/1 :: name() -> 'ok' | {'error', 'cannot_append_logfile'}). -spec(status/0 :: () -> [{running_applications, [{atom(), string(), string()}]} | {nodes, [node()]} | @@ -88,14 +88,14 @@ status() -> [{running_applications, application:which_applications()}] ++ rabbit_mnesia:status(). -reopen_logs() -> - ok = reopen_logs(error_log_location(), [], main_log), - ok = reopen_logs(sasl_log_location(), [], sasl_log). +rotate_logs() -> + ok = rotate_logs(error_log_location(wrapper), [], main_log), + ok = rotate_logs(sasl_log_location(), [], sasl_log). -reopen_logs(Suffix) -> +rotate_logs(Suffix) -> LSuffix = binary_to_list(Suffix), - case reopen_logs(error_log_location(), LSuffix, main_log) of - ok -> reopen_logs(sasl_log_location(), LSuffix, sasl_log); + case rotate_logs(error_log_location(wrapper), LSuffix, main_log) of + ok -> rotate_logs(sasl_log_location(), LSuffix, sasl_log); Error -> Error end. @@ -176,7 +176,11 @@ start(normal, []) -> {ok, DefaultVHost} = application:get_env(default_vhost), ok = error_logger:add_report_handler( rabbit_error_logger, [DefaultVHost]), - ok = start_builtin_amq_applications() + ok = start_builtin_amq_applications(), + ok = swap_handler(error_logger_file_h, rabbit_error_logger_file_h, + error_log_location(default)), + ok = swap_handler(sasl_report_file_h, rabbit_sasl_report_file_h, + sasl_log_location()) end}, {"TCP listeners", fun () -> @@ -208,7 +212,7 @@ print_banner() -> ?PROTOCOL_VERSION_MAJOR, ?PROTOCOL_VERSION_MINOR, ?COPYRIGHT_MESSAGE, ?INFORMATION_MESSAGE]), io:format("Logging to ~p~nSASL logging to ~p~n~n", - [error_log_location(), sasl_log_location()]). + [error_log_location(default), sasl_log_location()]). start_child(Mod) -> {ok,_} = supervisor:start_child(rabbit_sup, @@ -260,10 +264,15 @@ ensure_working_log_config() -> _Filename -> ok end. -error_log_location() -> +error_log_location(default) -> case error_logger:logfile(filename) of {error,no_log_file} -> tty; File -> File + end; +error_log_location(wrapper) -> + case gen_event:call(error_logger, rabbit_error_logger_file_h, filename) of + {error,no_log_file} -> tty; + File -> File end. sasl_log_location() -> @@ -275,28 +284,24 @@ sasl_log_location() -> _ -> undefined end. -reopen_logs(File, Suffix,Swap) -> +rotate_logs(File, Suffix, main_log) -> + rotate_logs(File, Suffix, rabbit_error_logger_file_h, rabbit_error_logger_file_h); +rotate_logs(File, Suffix, sasl_log) -> + rotate_logs(File, Suffix, rabbit_sasl_report_file_h, rabbit_sasl_report_file_h). + +rotate_logs(File, Suffix, OldHandler, NewHandler) -> case File of undefined -> ok; tty -> ok; _ -> case append_to_log_file(File, Suffix) of - omit -> swap_handler(Swap, File); - ok -> swap_handler(Swap, File); + omit -> swap_handler(OldHandler, NewHandler, File); + ok -> swap_handler(OldHandler, NewHandler, File); Error -> Error end end. -swap_handler(main_log, File) -> - error_logger:swap_handler({logfile, File}), - error_logger:delete_report_handler(error_logger_file_h), - ok; -swap_handler(sasl_log, File ) -> - gen_event:swap_handler(error_logger, - {error_logger, swap}, - {sasl_report_file_h, File}), - gen_event:add_handler(error_logger, error_logger, []), - error_logger:delete_report_handler(sasl_report_file_h), - ok. +swap_handler(Old, New, File) -> + gen_event:swap_handler(error_logger, {Old, swap}, {New, File}). append_to_log_file(File, Suffix) -> case file:read_file_info(File) of diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 4c1b92bb..28761eeb 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -73,7 +73,7 @@ Available commands: force_reset cluster ... status - reopen_logs [Suffix] + rotate_logs [Suffix] add_user delete_user @@ -130,12 +130,12 @@ action(status, Node, []) -> io:format("~n~p~n", [Res]), ok; -action(reopen_logs, Node, []) -> +action(rotate_logs, Node, []) -> io:format("Reopening logs for node ~p ...", [Node]), - call(Node, {rabbit, reopen_logs, []}); -action(reopen_logs, Node, Args = [Suffix]) -> - io:format("Moving logs to files with suffix ~p and reopening logs ...", [Suffix]), - call(Node, {rabbit, reopen_logs, Args}); + call(Node, {rabbit, rotate_logs, []}); +action(rotate_logs, Node, Args = [Suffix]) -> + io:format("Rotating logs to files with suffix ~p ...", [Suffix]), + call(Node, {rabbit, rotate_logs, Args}); action(add_user, Node, Args = [Username, _Password]) -> io:format("Creating user ~p ...", [Username]), diff --git a/src/rabbit_error_logger_file_h.erl b/src/rabbit_error_logger_file_h.erl new file mode 100644 index 00000000..4fadf46f --- /dev/null +++ b/src/rabbit_error_logger_file_h.erl @@ -0,0 +1,52 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developers of the Original Code are LShift Ltd., +%% Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd. +%% +%% Portions created by LShift Ltd., Cohesive Financial Technologies +%% LLC., and Rabbit Technologies Ltd. are Copyright (C) 2007-2008 +%% LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit +%% Technologies Ltd.; +%% +%% All Rights Reserved. +%% +%% Contributor(s): ______________________________________. +%% + +-module(rabbit_error_logger_file_h). + +-behaviour(gen_event). + +-export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2, code_change/3]). + +init({File, []}) -> + error_logger_file_h:init(File); +init({_File, _Type} = FileInfo) -> + error_logger_file_h:init(FileInfo); +init(File) -> + error_logger_file_h:init(File). + +handle_event(Event, State) -> + error_logger_file_h:handle_event(Event, State). + +handle_info(Event, State) -> + error_logger_file_h:handle_info(Event, State). + +handle_call(Event, State) -> + error_logger_file_h:handle_call(Event, State). + +terminate(Reason, State) -> + error_logger_file_h:terminate(Reason, State). + +code_change(OldVsn, State, Extra) -> + error_logger_file_h:code_change(OldVsn, State, Extra). diff --git a/src/rabbit_sasl_report_file_h.erl b/src/rabbit_sasl_report_file_h.erl new file mode 100644 index 00000000..7bfa2ca1 --- /dev/null +++ b/src/rabbit_sasl_report_file_h.erl @@ -0,0 +1,61 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developers of the Original Code are LShift Ltd., +%% Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd. +%% +%% Portions created by LShift Ltd., Cohesive Financial Technologies +%% LLC., and Rabbit Technologies Ltd. are Copyright (C) 2007-2008 +%% LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit +%% Technologies Ltd.; +%% +%% All Rights Reserved. +%% +%% Contributor(s): ______________________________________. +%% + +-module(rabbit_sasl_report_file_h). + +-behaviour(gen_event). + +-export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2, code_change/3]). + +init({File, []}) -> + sasl_report_file_h:init({File, sasl_error_logger_type()}); +init({_File, _Type} = FileInfo) -> + sasl_report_file_h:init(FileInfo); +init(File) -> + sasl_report_file_h:init({File, sasl_error_logger_type()}). + +handle_event(Event, State) -> + sasl_report_file_h:handle_event(Event, State). + +handle_info(Event, State) -> + sasl_report_file_h:handle_info(Event, State). + +handle_call(Event, State) -> + sasl_report_file_h:handle_call(Event, State). + +terminate(Reason, State) -> + sasl_report_file_h:terminate(Reason, State). + +code_change(OldVsn, State, Extra) -> + sasl_report_file_h:code_change(OldVsn, State, Extra). + +sasl_error_logger_type() -> + case application:get_env(sasl, errlog_type) of + {ok, error} -> error; + {ok, progress} -> progress; + {ok, all} -> all; + {ok, Bad} -> throw({error, {wrong_errlog_type, Bad}}); + _ -> all + end. -- cgit v1.2.1 From 7d62d02e18f6ee9238515c486a3a5fb38def0252 Mon Sep 17 00:00:00 2001 From: Karol Skocik Date: Tue, 26 Aug 2008 15:25:16 +0100 Subject: fixed bug in emitting erlang binary string --- codegen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen.py b/codegen.py index 7d830efa..4785b18c 100644 --- a/codegen.py +++ b/codegen.py @@ -47,7 +47,7 @@ erlangTypeMap = { erlangDefaultValueTypeConvMap = { bool : lambda x: str(x).lower(), - str : lambda x: "<<" + x + ">>", + str : lambda x: "<<\"" + x + "\">>", int : lambda x: str(x), float : lambda x: str(x) } -- cgit v1.2.1 From 475a336f0982fb1f433990ca4b2e98c331ba720a Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 26 Aug 2008 18:26:04 +0100 Subject: Moved append operation inside init/1 in handlers' wrappers. Added comments, fixed various small things. --- docs/rabbitmqctl.pod | 2 +- src/rabbit.erl | 75 +++++++++++++++----------------------- src/rabbit_control.erl | 2 +- src/rabbit_error_logger_file_h.erl | 14 +++++++ src/rabbit_misc.erl | 21 +++++++++++ src/rabbit_sasl_report_file_h.erl | 17 +++++++++ 6 files changed, 84 insertions(+), 47 deletions(-) diff --git a/docs/rabbitmqctl.pod b/docs/rabbitmqctl.pod index d6e0bac7..927fd8af 100644 --- a/docs/rabbitmqctl.pod +++ b/docs/rabbitmqctl.pod @@ -132,7 +132,7 @@ default Erlang node: Append current logs' content to the files with ".1" suffix and reopen them: - rabbitmqctl reopen_logs .1 + rabbitmqctl rotate_logs .1 =head1 SEE ALSO diff --git a/src/rabbit.erl b/src/rabbit.erl index c82e0a13..dd1cec2f 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -27,7 +27,7 @@ -behaviour(application). --export([start/0, stop/0, stop_and_halt/0, status/0, rotate_logs/0, rotate_logs/1]). +-export([start/0, stop/0, stop_and_halt/0, status/0, rotate_logs/1]). -export([start/2, stop/1]). @@ -39,7 +39,6 @@ -include("rabbit_framing.hrl"). -include("rabbit.hrl"). --include_lib("kernel/include/file.hrl"). -define(APPS, [os_mon, mnesia, rabbit]). @@ -50,8 +49,7 @@ -spec(start/0 :: () -> 'ok'). -spec(stop/0 :: () -> 'ok'). -spec(stop_and_halt/0 :: () -> 'ok'). --spec(rotate_logs/0 :: () -> 'ok'). --spec(rotate_logs/1 :: name() -> 'ok' | {'error', 'cannot_append_logfile'}). +-spec(rotate_logs/1 :: name() -> 'ok' | {'error', any()}). -spec(status/0 :: () -> [{running_applications, [{atom(), string(), string()}]} | {nodes, [node()]} | @@ -88,16 +86,11 @@ status() -> [{running_applications, application:which_applications()}] ++ rabbit_mnesia:status(). -rotate_logs() -> - ok = rotate_logs(error_log_location(wrapper), [], main_log), - ok = rotate_logs(sasl_log_location(), [], sasl_log). - -rotate_logs(Suffix) -> - LSuffix = binary_to_list(Suffix), - case rotate_logs(error_log_location(wrapper), LSuffix, main_log) of - ok -> rotate_logs(sasl_log_location(), LSuffix, sasl_log); - Error -> Error - end. +rotate_logs(BinarySuffix) -> + Suffix = binary_to_list(BinarySuffix), + log_rotation_result( + rotate_logs(error_log_location(wrapper), Suffix, rabbit_error_logger_file_h), + rotate_logs(sasl_log_location(), Suffix, rabbit_sasl_report_file_h)). %%-------------------------------------------------------------------- @@ -177,10 +170,14 @@ start(normal, []) -> ok = error_logger:add_report_handler( rabbit_error_logger, [DefaultVHost]), ok = start_builtin_amq_applications(), - ok = swap_handler(error_logger_file_h, rabbit_error_logger_file_h, - error_log_location(default)), - ok = swap_handler(sasl_report_file_h, rabbit_sasl_report_file_h, - sasl_log_location()) + %% Swap default handlers with rabbit wrappers + %% to simplify swapping of log handlers later + ok = rotate_logs(error_log_location(default), "", + error_logger_file_h, + rabbit_error_logger_file_h), + ok = rotate_logs(sasl_log_location(), "", + sasl_report_file_h, + rabbit_sasl_report_file_h) end}, {"TCP listeners", fun () -> @@ -284,37 +281,25 @@ sasl_log_location() -> _ -> undefined end. -rotate_logs(File, Suffix, main_log) -> - rotate_logs(File, Suffix, rabbit_error_logger_file_h, rabbit_error_logger_file_h); -rotate_logs(File, Suffix, sasl_log) -> - rotate_logs(File, Suffix, rabbit_sasl_report_file_h, rabbit_sasl_report_file_h). +rotate_logs(File, Suffix, Handler) -> + rotate_logs(File, Suffix, Handler, Handler). rotate_logs(File, Suffix, OldHandler, NewHandler) -> case File of undefined -> ok; tty -> ok; - _ -> case append_to_log_file(File, Suffix) of - omit -> swap_handler(OldHandler, NewHandler, File); - ok -> swap_handler(OldHandler, NewHandler, File); - Error -> Error - end + _ -> gen_event:swap_handler( + error_logger, + {OldHandler, swap}, + {NewHandler, {File, Suffix}}) end. -swap_handler(Old, New, File) -> - gen_event:swap_handler(error_logger, {Old, swap}, {New, File}). - -append_to_log_file(File, Suffix) -> - case file:read_file_info(File) of - {ok, FInfo} -> append_file(File, FInfo#file_info.size, Suffix); - {error, _} -> ok - end. - -append_file(_, 0, _) -> - omit; -append_file(_, _, []) -> - omit; -append_file(File, _, Suffix) -> - case file:read_file(File) of - {ok, Data} -> file:write_file([File, Suffix], Data, [append]); - {error, _} -> {error, cannot_append_logfile} - end. +log_rotation_result({error, MainLogError}, {error, SaslLogError}) -> + {error, {{cannot_rotate_main_logs, MainLogError}, + {cannot_rotate_sasl_logs, SaslLogError}}}; +log_rotation_result({error, MainLogError}, ok) -> + {error, {cannot_rotate_main_logs, MainLogError}}; +log_rotation_result(ok, {error, SaslLogError}) -> + {error, {cannot_rotate_sasl_logs, SaslLogError}}; +log_rotation_result(ok, ok) -> + ok. diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 28761eeb..bc588279 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -132,7 +132,7 @@ action(status, Node, []) -> action(rotate_logs, Node, []) -> io:format("Reopening logs for node ~p ...", [Node]), - call(Node, {rabbit, rotate_logs, []}); + call(Node, {rabbit, rotate_logs, [""]}); action(rotate_logs, Node, Args = [Suffix]) -> io:format("Rotating logs to files with suffix ~p ...", [Suffix]), call(Node, {rabbit, rotate_logs, Args}); diff --git a/src/rabbit_error_logger_file_h.erl b/src/rabbit_error_logger_file_h.erl index 4fadf46f..20c6b778 100644 --- a/src/rabbit_error_logger_file_h.erl +++ b/src/rabbit_error_logger_file_h.erl @@ -29,6 +29,20 @@ -export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2, code_change/3]). +%% rabbit_error_logger_file_h is a wrapper around error_logger_file_h +%% module because the original's init/1 does not match properly +%% with the result of closing the old handler when swapping handlers. +%% The first init/1 additionally allows for simple log rotation +%% when suffix is not "" + +%% Used only when swapping handlers in log rotation +init({{File, Suffix}, []}) -> + case rabbit_misc:append_file(File, Suffix) of + ok -> error_logger_file_h:init(File); + Error -> Error + end; +%% Used only when swapping handlers without performing +%% log rotation init({File, []}) -> error_logger_file_h:init(File); init({_File, _Type} = FileInfo) -> diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 11ab0caf..9aeb1621 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -26,6 +26,7 @@ -module(rabbit_misc). -include("rabbit.hrl"). -include("rabbit_framing.hrl"). +-include_lib("kernel/include/file.hrl"). -export([method_record_type/1, polite_pause/0, polite_pause/1]). -export([die/1, frame_error/2, protocol_error/3, protocol_error/4]). @@ -41,6 +42,7 @@ -export([intersperse/2, upmap/2, map_in_order/2]). -export([guid/0, string_guid/1, binstring_guid/1]). -export([dirty_read_all/1, dirty_foreach_key/2, dirty_dump_log/1]). +-export([append_file/2]). -import(mnesia). -import(lists). @@ -92,6 +94,7 @@ -spec(dirty_foreach_key/2 :: (fun ((any()) -> any()), atom()) -> 'ok' | 'aborted'). -spec(dirty_dump_log/1 :: (string()) -> 'ok' | {'error', any()}). +-spec(append_file/2 :: (string(), string()) -> 'ok' | {'error', any()}). -endif. @@ -333,3 +336,21 @@ dirty_dump_log1(LH, {K, Terms}) -> dirty_dump_log1(LH, {K, Terms, BadBytes}) -> io:format("Bad Chunk, ~p: ~p~n", [BadBytes, Terms]), dirty_dump_log1(LH, disk_log:chunk(LH, K)). + + +append_file(File, Suffix) -> + case catch file:read_file_info(File) of + {ok, FInfo} -> append_file(File, FInfo#file_info.size, Suffix); + {error, enoent} -> ok; + {error, Error} -> {error, {cannot_read_logfile, Error}} + end. + +append_file(_, 0, _) -> + ok; +append_file(_, _, "") -> + ok; +append_file(File, _, Suffix) -> + case catch file:read_file(File) of + {ok, Data} -> file:write_file([File, Suffix], Data, [append]); + {error, Error} -> {error, {cannot_append_logfile, Error}} + end. diff --git a/src/rabbit_sasl_report_file_h.erl b/src/rabbit_sasl_report_file_h.erl index 7bfa2ca1..eb5bf091 100644 --- a/src/rabbit_sasl_report_file_h.erl +++ b/src/rabbit_sasl_report_file_h.erl @@ -29,6 +29,21 @@ -export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2, code_change/3]). +%% rabbit_sasl_report_file_h is a wrapper around sasl_report_file_h +%% module because the original's init/1 does not match properly +%% with the result of closing the old handler when swapping handlers. +%% The first init/1 additionally allows for simple log rotation +%% when suffix is not "" + +%% Used only when swapping handlers and performing +%% log rotation +init({{File, Suffix}, []}) -> + case rabbit_misc:append_file(File, Suffix) of + ok -> sasl_report_file_h:init({File, sasl_error_logger_type()}); + Error -> Error + end; +%% Used only when swapping handlers without +%% doing any log rotation init({File, []}) -> sasl_report_file_h:init({File, sasl_error_logger_type()}); init({_File, _Type} = FileInfo) -> @@ -51,6 +66,8 @@ terminate(Reason, State) -> code_change(OldVsn, State, Extra) -> sasl_report_file_h:code_change(OldVsn, State, Extra). +%%---------------------------------------------------------------------- + sasl_error_logger_type() -> case application:get_env(sasl, errlog_type) of {ok, error} -> error; -- cgit v1.2.1 From 793bb869d223dbdabd3d69ca9094ace9521fdcae Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Tue, 26 Aug 2008 20:29:02 +0100 Subject: support default empty AMQP tables --- codegen.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/codegen.py b/codegen.py index 4785b18c..5dbc57c7 100644 --- a/codegen.py +++ b/codegen.py @@ -45,11 +45,20 @@ erlangTypeMap = { 'timestamp': 'timestamp', } +# Coming up with a proper encoding of AMQP tables in JSON is too much +# hassle at this stage. Given that the only default value we are +# interested in is for the empty table, we only support that. +def convertTable(d): + if len(d) == 0: + return "[]" + else: raise 'Non-empty table defaults not supported', d + erlangDefaultValueTypeConvMap = { bool : lambda x: str(x).lower(), str : lambda x: "<<\"" + x + "\">>", int : lambda x: str(x), - float : lambda x: str(x) + float : lambda x: str(x), + dict: convertTable } def erlangize(s): -- cgit v1.2.1 From e0bee37888a96a92d2fad7da9e9ee2d6456f99c6 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 27 Aug 2008 11:00:20 +0100 Subject: Minor style changes --- src/rabbit.erl | 16 +++++++--------- src/rabbit_misc.erl | 8 ++++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index dd1cec2f..d4b21c43 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -261,15 +261,13 @@ ensure_working_log_config() -> _Filename -> ok end. -error_log_location(default) -> - case error_logger:logfile(filename) of - {error,no_log_file} -> tty; - File -> File - end; -error_log_location(wrapper) -> - case gen_event:call(error_logger, rabbit_error_logger_file_h, filename) of - {error,no_log_file} -> tty; - File -> File +error_log_location(Type) -> + case case Type of + default -> error_logger:logfile(filename); + wrapper -> gen_event:call(error_logger, rabbit_error_logger_file_h, filename) + end of + {error, no_log_file} -> tty; + File -> File end. sasl_log_location() -> diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 9aeb1621..d7d1ff14 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -342,7 +342,7 @@ append_file(File, Suffix) -> case catch file:read_file_info(File) of {ok, FInfo} -> append_file(File, FInfo#file_info.size, Suffix); {error, enoent} -> ok; - {error, Error} -> {error, {cannot_read_logfile, Error}} + Error -> Error end. append_file(_, 0, _) -> @@ -350,7 +350,7 @@ append_file(_, 0, _) -> append_file(_, _, "") -> ok; append_file(File, _, Suffix) -> - case catch file:read_file(File) of - {ok, Data} -> file:write_file([File, Suffix], Data, [append]); - {error, Error} -> {error, {cannot_append_logfile, Error}} + case file:read_file(File) of + {ok, Data} -> file:write_file([File, Suffix], Data, [append]); + Error -> Error end. -- cgit v1.2.1 From 816763d0da3e3f27dd80a7dd0ccfbae70496cbb8 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 27 Aug 2008 11:11:26 +0100 Subject: Reverted BACKUP_EXTENSION variable. This change belongs to bug 19193 --- scripts/rabbitmq-server | 2 +- scripts/rabbitmq-server.bat | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/rabbitmq-server b/scripts/rabbitmq-server index d78be18e..a44dd6da 100755 --- a/scripts/rabbitmq-server +++ b/scripts/rabbitmq-server @@ -39,7 +39,7 @@ CLUSTER_CONFIG_FILE=/etc/default/rabbitmq_cluster.config ## Log rotation LOGS="${LOG_BASE}/${NODENAME}.log" SASL_LOGS="${LOG_BASE}/${NODENAME}-sasl.log" -BACKUP_EXTENSION=".1" +BACKUP_EXTENSION=".bak" [ -f "${LOGS}" ] && cat "${LOGS}" >> "${LOGS}${BACKUP_EXTENSION}" [ -f "${SASL_LOGS}" ] && cat "${SASL_LOGS}" >> "${SASL_LOGS}${BACKUP_EXTENSION}" diff --git a/scripts/rabbitmq-server.bat b/scripts/rabbitmq-server.bat index a32fe0fc..46f4bd92 100644 --- a/scripts/rabbitmq-server.bat +++ b/scripts/rabbitmq-server.bat @@ -65,7 +65,7 @@ set LOG_BASE=%RABBITMQ_BASE_UNIX%/log rem We save the previous logs in their respective backup rem Log management (rotation, filtering based of size...) is left as an exercice for the user. -set BACKUP_EXTENSION=.1 +set BACKUP_EXTENSION=.bak set LOGS="%RABBITMQ_BASE%\log\%NODENAME%.log" set SASL_LOGS="%RABBITMQ_BASE%\log\%NODENAME%-sasl.log" -- cgit v1.2.1 From 1dad9e3275aabcb10d7de4eb82d44d1b13c6983d Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 27 Aug 2008 12:51:47 +0100 Subject: Added rotate_logs_all command to rabbitmq_multi. logrotate uses this command to correctly swap handlers on all nodes. --- packaging/RPMS/Fedora/rabbitmq-server.logrotate | 7 ++-- .../debs/Debian/debian/rabbitmq-server.logrotate | 7 ++-- src/rabbit_multi.erl | 38 ++++++++++++++++++---- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/packaging/RPMS/Fedora/rabbitmq-server.logrotate b/packaging/RPMS/Fedora/rabbitmq-server.logrotate index e366f36a..8b5811d8 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.logrotate +++ b/packaging/RPMS/Fedora/rabbitmq-server.logrotate @@ -1,13 +1,12 @@ -/var/log/rabbitmq/*.log /var/log/rabbitmq/*.err { +/var/log/rabbitmq/*.log { weekly missingok - rotate 10 + rotate 20 compress delaycompress notifempty - create 644 rabbitmq rabbitmq sharedscripts postrotate - /usr/sbin/rabbitmqctl reopen_logs + /usr/sbin/rabbitmq-multi rotate_logs_all > /dev/null 2>&1 endscript } \ No newline at end of file diff --git a/packaging/debs/Debian/debian/rabbitmq-server.logrotate b/packaging/debs/Debian/debian/rabbitmq-server.logrotate index e366f36a..8b5811d8 100644 --- a/packaging/debs/Debian/debian/rabbitmq-server.logrotate +++ b/packaging/debs/Debian/debian/rabbitmq-server.logrotate @@ -1,13 +1,12 @@ -/var/log/rabbitmq/*.log /var/log/rabbitmq/*.err { +/var/log/rabbitmq/*.log { weekly missingok - rotate 10 + rotate 20 compress delaycompress notifempty - create 644 rabbitmq rabbitmq sharedscripts postrotate - /usr/sbin/rabbitmqctl reopen_logs + /usr/sbin/rabbitmq-multi rotate_logs_all > /dev/null 2>&1 endscript } \ No newline at end of file diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl index cd92f1ac..29f12ff7 100644 --- a/src/rabbit_multi.erl +++ b/src/rabbit_multi.erl @@ -69,8 +69,9 @@ usage() -> Available commands: - start_all - start a local cluster of RabbitMQ nodes. - stop_all - stops all local RabbitMQ nodes. + start_all - start a local cluster of RabbitMQ nodes. + stop_all - stops all local RabbitMQ nodes. + rotate_logs_all [Suffix] - rotate logs for all local RabbitMQ nodes. "), halt(3). @@ -89,11 +90,19 @@ action(start_all, [NodeCount], RpcTimeout) -> action(stop_all, [], RpcTimeout) -> io:format("Stopping all nodes...~n", []), - case read_pids_file() of - [] -> throw(no_nodes_running); - NodePids -> stop_nodes(NodePids, RpcTimeout), - delete_pids_file() - end. + call_all_nodes(fun(NodePids) -> + stop_nodes(NodePids, RpcTimeout), + delete_pids_file() end); + +action(rotate_logs_all, [], RpcTimeout) -> + action(rotate_logs_all, [""], RpcTimeout); + +action(rotate_logs_all, [Suffix], RpcTimeout) -> + io:format("Rotating logs for all nodes...~n", []), + call_all_nodes(fun(NodePids) -> + rotate_logs(NodePids, + list_to_binary(Suffix), + RpcTimeout) end). %% PNodePid is the list of PIDs %% Running is a boolean exhibiting success at some moment @@ -272,6 +281,21 @@ is_dead(Pid) -> end end}]). +rotate_logs([], _, _) -> ok; +rotate_logs([{Node, _} | Rest], BinarySuffix, RpcTimeout) -> + io:format("Rotating logs for node ~p~n", [Node]), + case rpc:call(Node, rabbit, rotate_logs, [BinarySuffix], RpcTimeout) of + {badrpc, _} -> io:format("timeout"), + throw(rotate_logs_failed); + ok -> rotate_logs(Rest, BinarySuffix, RpcTimeout) + end. + +call_all_nodes(Func) -> + case read_pids_file() of + [] -> throw(no_nodes_running); + NodePids -> Func(NodePids) + end. + getenv(Var) -> case os:getenv(Var) of false -> throw({missing_env_var, Var}); -- cgit v1.2.1 From 23f9b0a9da27d87deda1875d9d60de9a9f5ea30c Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 27 Aug 2008 12:55:07 +0100 Subject: Update man pages with rotate_logs_all command --- docs/rabbitmq-multi.pod | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/rabbitmq-multi.pod b/docs/rabbitmq-multi.pod index 2e3f28c8..772ca70a 100644 --- a/docs/rabbitmq-multi.pod +++ b/docs/rabbitmq-multi.pod @@ -26,6 +26,9 @@ start_all I stop_all stop all local RabbitMQ nodes +rotate_logs_all + rotate log files for all local RabbitMQ nodes + =head1 EXAMPLES Start 3 local RabbitMQ nodes with unique, sequential port numbers: -- cgit v1.2.1 From 5a4dcf246250bd44300bca11ccf07d656b0cfbc2 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 27 Aug 2008 13:39:22 +0100 Subject: Logrotate script calls init.d script instead of calling rabbitmq-multi directly --- packaging/RPMS/Fedora/init.d | 14 +++++++++++++- packaging/RPMS/Fedora/rabbitmq-server.logrotate | 2 +- packaging/debs/Debian/debian/init.d | 15 ++++++++++++++- packaging/debs/Debian/debian/rabbitmq-server.logrotate | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packaging/RPMS/Fedora/init.d b/packaging/RPMS/Fedora/init.d index a7e6b98c..dc0c2698 100644 --- a/packaging/RPMS/Fedora/init.d +++ b/packaging/RPMS/Fedora/init.d @@ -23,6 +23,7 @@ NAME=rabbitmq-server DESC=rabbitmq-server USER=rabbitmq NODE_COUNT=1 +ROTATE_SUFFIX= LOCK_FILE=/var/lock/subsys/$NAME @@ -82,6 +83,13 @@ restart_rabbitmq () { echo "$NAME." } +rotate_logs_rabbitmq() { + set +e + su $USER -s /bin/sh -c "$DAEMON rotate_logs_all ${ROTATE_SUFFIX}" 2>&1 + RETVAL=$? + set -e +} + case "$1" in start) echo -n "Starting $DESC: " @@ -93,6 +101,10 @@ case "$1" in stop_rabbitmq echo "$NAME." ;; + rotate-logs) + echo -n "Rotating log files for $DESC: " + rotate_logs_rabbitmq + ;; force-reload|reload|restart) restart_rabbitmq ;; @@ -106,7 +118,7 @@ case "$1" in restart_rabbitmq ;; *) - echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" >&2 + echo "Usage: $0 {start|stop|rotate-logs|status|restart|condrestart|try-restart|reload|force-reload}" >&2 RETVAL=1 ;; esac diff --git a/packaging/RPMS/Fedora/rabbitmq-server.logrotate b/packaging/RPMS/Fedora/rabbitmq-server.logrotate index 8b5811d8..64cd01a1 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.logrotate +++ b/packaging/RPMS/Fedora/rabbitmq-server.logrotate @@ -7,6 +7,6 @@ notifempty sharedscripts postrotate - /usr/sbin/rabbitmq-multi rotate_logs_all > /dev/null 2>&1 + /sbin/service rabbitmq-server rotate-logs endscript } \ No newline at end of file diff --git a/packaging/debs/Debian/debian/init.d b/packaging/debs/Debian/debian/init.d index ae82dd5c..c3c180a8 100644 --- a/packaging/debs/Debian/debian/init.d +++ b/packaging/debs/Debian/debian/init.d @@ -15,6 +15,7 @@ NAME=rabbitmq-server DESC=rabbitmq-server USER=rabbitmq NODE_COUNT=1 +ROTATE_SUFFIX= test -x $DAEMON || exit 0 @@ -51,6 +52,14 @@ stop_rabbitmq () { set -e } +rotate_logs_rabbitmq() { + set +e + su $USER -s /bin/sh -c "$DAEMON rotate_logs_all ${ROTATE_SUFFIX}" 2>&1 + RETVAL=$? + set -e + +} + case "$1" in start) echo -n "Starting $DESC: " @@ -62,6 +71,10 @@ case "$1" in stop_rabbitmq echo "$NAME." ;; + rotate-logs) + echo -n "Rotating log files for $DESC: " + rotate_logs_rabbitmq + ;; force-reload|restart) echo -n "Restarting $DESC: " stop_rabbitmq @@ -69,7 +82,7 @@ case "$1" in echo "$NAME." ;; *) - echo "Usage: $0 {start|stop|restart|force-reload}" >&2 + echo "Usage: $0 {start|stop|rotate-logs|restart|force-reload}" >&2 exit 1 ;; esac diff --git a/packaging/debs/Debian/debian/rabbitmq-server.logrotate b/packaging/debs/Debian/debian/rabbitmq-server.logrotate index 8b5811d8..247635d1 100644 --- a/packaging/debs/Debian/debian/rabbitmq-server.logrotate +++ b/packaging/debs/Debian/debian/rabbitmq-server.logrotate @@ -7,6 +7,6 @@ notifempty sharedscripts postrotate - /usr/sbin/rabbitmq-multi rotate_logs_all > /dev/null 2>&1 + /etc/init.d/rabbitmq-server rotate-logs endscript } \ No newline at end of file -- cgit v1.2.1 From bf5ceb4dac3197bce4e573e2f94a59410d625d69 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 27 Aug 2008 14:49:16 +0100 Subject: Fixed spec definition. Renamed name() to binary_name() because of the conflict with definition in kernel/include/file.hrl --- include/rabbit.hrl | 2 +- include/rabbit_framing_spec.hrl | 2 +- src/rabbit.erl | 2 +- src/rabbit_misc.erl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/rabbit.hrl b/include/rabbit.hrl index cc8fb1b5..b374f047 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -71,7 +71,7 @@ -type(r(Kind) :: #resource{virtual_host :: vhost(), kind :: Kind, - name :: name()}). + name :: binary_name()}). -type(queue_name() :: r('queue')). -type(exchange_name() :: r('exchange')). -type(user() :: diff --git a/include/rabbit_framing_spec.hrl b/include/rabbit_framing_spec.hrl index ef9ab584..6bd1cd91 100644 --- a/include/rabbit_framing_spec.hrl +++ b/include/rabbit_framing_spec.hrl @@ -46,7 +46,7 @@ -type(channel_number() :: non_neg_integer()). %% TODO: make this more precise -type(amqp_error() :: {bool(), non_neg_integer(), binary()}). --type(name() :: binary()). +-type(binary_name() :: binary()). -type(routing_key() :: binary()). -type(username() :: binary()). -type(password() :: binary()). diff --git a/src/rabbit.erl b/src/rabbit.erl index d4b21c43..687d0b30 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -49,7 +49,7 @@ -spec(start/0 :: () -> 'ok'). -spec(stop/0 :: () -> 'ok'). -spec(stop_and_halt/0 :: () -> 'ok'). --spec(rotate_logs/1 :: name() -> 'ok' | {'error', any()}). +-spec(rotate_logs/1 :: (binary_name()) -> 'ok' | {'error', any()}). -spec(status/0 :: () -> [{running_applications, [{atom(), string(), string()}]} | {nodes, [node()]} | diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index d7d1ff14..9dba775e 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -68,7 +68,7 @@ -spec(get_config/2 :: (atom(), A) -> A). -spec(set_config/2 :: (atom(), any()) -> 'ok'). -spec(dirty_read/1 :: ({atom(), any()}) -> {'ok', any()} | not_found()). --spec(r/3 :: (vhost(), K, name()) -> r(K) when is_subtype(K, atom())). +-spec(r/3 :: (vhost(), K, binary_name()) -> r(K) when is_subtype(K, atom())). -spec(r/2 :: (vhost(), K) -> #resource{virtual_host :: vhost(), kind :: K, name :: '_'} -- cgit v1.2.1 From 5d081a3aefadbe1650cb8b10169a4553dcec3bd7 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 27 Aug 2008 16:24:18 +0100 Subject: Added few missing articles --- docs/rabbitmqctl.pod | 10 +++++----- src/rabbit.erl | 2 +- src/rabbit_error_logger_file_h.erl | 4 ++-- src/rabbit_sasl_report_file_h.erl | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/rabbitmqctl.pod b/docs/rabbitmqctl.pod index 927fd8af..6c84cbb1 100644 --- a/docs/rabbitmqctl.pod +++ b/docs/rabbitmqctl.pod @@ -69,10 +69,10 @@ force_reset rotate_logs [suffix] instruct the RabbitMQ node to rotate the log files. The RabbitMQ broker will attempt to append the current contents of the log file - to the file with name composed of the original name and the suffix. - It will create a new file if such a file does not already exist. - When no I is specified, the log file is simply reopened; - no rotation takes place. + to the file with the name composed of the original name and the + suffix. It will create a new file if such a file does not already + exist. When no I is specified, the log file is simply + reopened; no rotation takes place. This command might be helpful when you are e.g. writing your own logrotate script and you do not want to restart the RabbitMQ node. @@ -129,7 +129,7 @@ default Erlang node: rabbitmqctl map_user_vhost foo test -Append current logs' content to the files with ".1" suffix and reopen +Append the current logs' content to the files with ".1" suffix and reopen them: rabbitmqctl rotate_logs .1 diff --git a/src/rabbit.erl b/src/rabbit.erl index 687d0b30..6376d2ee 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -171,7 +171,7 @@ start(normal, []) -> rabbit_error_logger, [DefaultVHost]), ok = start_builtin_amq_applications(), %% Swap default handlers with rabbit wrappers - %% to simplify swapping of log handlers later + %% to simplify the swapping of log handlers later ok = rotate_logs(error_log_location(default), "", error_logger_file_h, rabbit_error_logger_file_h), diff --git a/src/rabbit_error_logger_file_h.erl b/src/rabbit_error_logger_file_h.erl index 20c6b778..d5c0ab08 100644 --- a/src/rabbit_error_logger_file_h.erl +++ b/src/rabbit_error_logger_file_h.erl @@ -29,11 +29,11 @@ -export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2, code_change/3]). -%% rabbit_error_logger_file_h is a wrapper around error_logger_file_h +%% rabbit_error_logger_file_h is a wrapper around the error_logger_file_h %% module because the original's init/1 does not match properly %% with the result of closing the old handler when swapping handlers. %% The first init/1 additionally allows for simple log rotation -%% when suffix is not "" +%% when the suffix is not the empty string. %% Used only when swapping handlers in log rotation init({{File, Suffix}, []}) -> diff --git a/src/rabbit_sasl_report_file_h.erl b/src/rabbit_sasl_report_file_h.erl index eb5bf091..15f1bfe2 100644 --- a/src/rabbit_sasl_report_file_h.erl +++ b/src/rabbit_sasl_report_file_h.erl @@ -29,11 +29,11 @@ -export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2, code_change/3]). -%% rabbit_sasl_report_file_h is a wrapper around sasl_report_file_h +%% rabbit_sasl_report_file_h is a wrapper around the sasl_report_file_h %% module because the original's init/1 does not match properly %% with the result of closing the old handler when swapping handlers. %% The first init/1 additionally allows for simple log rotation -%% when suffix is not "" +%% when the suffix is not the empty string. %% Used only when swapping handlers and performing %% log rotation -- cgit v1.2.1 From 2c7abca856ba0a09170e47049929677c13a1649f Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 28 Aug 2008 11:26:42 +0100 Subject: Create suffix file even when the original one is empty or doesn't exist. --- src/rabbit_misc.erl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 9dba775e..cf6a483a 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -341,14 +341,17 @@ dirty_dump_log1(LH, {K, Terms, BadBytes}) -> append_file(File, Suffix) -> case catch file:read_file_info(File) of {ok, FInfo} -> append_file(File, FInfo#file_info.size, Suffix); - {error, enoent} -> ok; + {error, enoent} -> append_file(File, 0, Suffix); Error -> Error end. -append_file(_, 0, _) -> - ok; append_file(_, _, "") -> ok; +append_file(File, 0, Suffix) -> + case file:open([File, Suffix], [append]) of + {ok, Fd} -> file:close(Fd); + Error -> Error + end; append_file(File, _, Suffix) -> case file:read_file(File) of {ok, Data} -> file:write_file([File, Suffix], Data, [append]); -- cgit v1.2.1 From 32af9f32ba07f59d69f55f759c97696617e665cc Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 29 Aug 2008 15:57:25 +0100 Subject: When appending the old log file fails always try to create the handler. This can happen when the file we append to is not writable. Fixed missing case clause. --- src/rabbit.erl | 1 + src/rabbit_error_logger_file_h.erl | 16 +++++++++++++--- src/rabbit_sasl_report_file_h.erl | 16 +++++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index 6376d2ee..bf4cb013 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -267,6 +267,7 @@ error_log_location(Type) -> wrapper -> gen_event:call(error_logger, rabbit_error_logger_file_h, filename) end of {error, no_log_file} -> tty; + {error, _} -> undefined; File -> File end. diff --git a/src/rabbit_error_logger_file_h.erl b/src/rabbit_error_logger_file_h.erl index d5c0ab08..2de861b6 100644 --- a/src/rabbit_error_logger_file_h.erl +++ b/src/rabbit_error_logger_file_h.erl @@ -38,13 +38,23 @@ %% Used only when swapping handlers in log rotation init({{File, Suffix}, []}) -> case rabbit_misc:append_file(File, Suffix) of - ok -> error_logger_file_h:init(File); - Error -> Error + ok -> init(File); + Error -> + case init(File) of + {ok, FInfo} -> + error_logger:error_msg("Error occured while appending " ++ + "~p log file to \"~s\":~n~p~n", + [File, [File, Suffix], Error]), + io:format("~nOrignal log file could not be appended to " ++ + "\"~s\"~n", [[File, Suffix]]), + {ok, FInfo}; + CriticalError -> CriticalError + end end; %% Used only when swapping handlers without performing %% log rotation init({File, []}) -> - error_logger_file_h:init(File); + init(File); init({_File, _Type} = FileInfo) -> error_logger_file_h:init(FileInfo); init(File) -> diff --git a/src/rabbit_sasl_report_file_h.erl b/src/rabbit_sasl_report_file_h.erl index 15f1bfe2..3b8a591a 100644 --- a/src/rabbit_sasl_report_file_h.erl +++ b/src/rabbit_sasl_report_file_h.erl @@ -39,13 +39,23 @@ %% log rotation init({{File, Suffix}, []}) -> case rabbit_misc:append_file(File, Suffix) of - ok -> sasl_report_file_h:init({File, sasl_error_logger_type()}); - Error -> Error + ok -> init(File); + Error -> + case init(File) of + {ok, FInfo} -> + error_logger:error_msg("Error occured while appending " ++ + "~p sasl log file to \"~s\":~n~p~n", + [File, [File, Suffix], Error]), + io:format("~nOrignal sasl log file could not be appended " + "to \"~s\"~n", [[File, Suffix]]), + {ok, FInfo}; + CriticalError -> CriticalError + end end; %% Used only when swapping handlers without %% doing any log rotation init({File, []}) -> - sasl_report_file_h:init({File, sasl_error_logger_type()}); + init(File); init({_File, _Type} = FileInfo) -> sasl_report_file_h:init(FileInfo); init(File) -> -- cgit v1.2.1 From be7dc82465032ad93451411f07edfcf10e23a8fb Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 29 Aug 2008 16:11:24 +0100 Subject: tabs -> spaces --- src/rabbit_channel.erl | 2 +- src/rabbit_multi.erl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index caa63b58..5cc07aed 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -531,7 +531,7 @@ handle_method(#'queue.declare'{queue = QueueNameBin, <<>> -> rabbit_misc:binstring_guid("amq.gen"); Other -> check_name('queue', Other) end, - QueueName = rabbit_misc:r(VHostPath, queue, ActualNameBin), + QueueName = rabbit_misc:r(VHostPath, queue, ActualNameBin), Finish(rabbit_amqqueue:declare(QueueName, Durable, AutoDelete, Args)); Other -> Other diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl index cd92f1ac..bde69336 100644 --- a/src/rabbit_multi.erl +++ b/src/rabbit_multi.erl @@ -233,7 +233,7 @@ stop_node({Node, Pid}, RpcTimeout) -> rpc:call(Node, rabbit, stop_and_halt, []), case kill_wait(Pid, RpcTimeout, false) of false -> kill_wait(Pid, RpcTimeout, true); - true -> ok + true -> ok end, io:format("OK~n", []). -- cgit v1.2.1 From 95b30ad6494ff6d686d6f29afb4f243d2ffe070a Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 29 Aug 2008 16:35:08 +0100 Subject: More info about the behaviour of rotate_logs command --- docs/rabbitmqctl.pod | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/rabbitmqctl.pod b/docs/rabbitmqctl.pod index 6c84cbb1..3a33e20f 100644 --- a/docs/rabbitmqctl.pod +++ b/docs/rabbitmqctl.pod @@ -71,8 +71,11 @@ rotate_logs [suffix] broker will attempt to append the current contents of the log file to the file with the name composed of the original name and the suffix. It will create a new file if such a file does not already - exist. When no I is specified, the log file is simply - reopened; no rotation takes place. + exist. When no I is specified, the empty log file is + simply created at the original location; no rotation takes place. + When an error occurs while appending the contents of the old log + file, operation behaves in the same way as if no I was + specified. This command might be helpful when you are e.g. writing your own logrotate script and you do not want to restart the RabbitMQ node. -- cgit v1.2.1 From d4233cf55b3b462bdbc8f6a2e39e3e905883b3f8 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 29 Aug 2008 16:56:39 +0100 Subject: Typo --- docs/rabbitmqctl.pod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rabbitmqctl.pod b/docs/rabbitmqctl.pod index 3a33e20f..b34cbca7 100644 --- a/docs/rabbitmqctl.pod +++ b/docs/rabbitmqctl.pod @@ -74,7 +74,7 @@ rotate_logs [suffix] exist. When no I is specified, the empty log file is simply created at the original location; no rotation takes place. When an error occurs while appending the contents of the old log - file, operation behaves in the same way as if no I was + file, the operation behaves in the same way as if no I was specified. This command might be helpful when you are e.g. writing your own logrotate script and you do not want to restart the RabbitMQ node. -- cgit v1.2.1 From 93000a7040bea67e7d53ccf862b502e1fc9ac050 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 29 Aug 2008 17:32:40 +0100 Subject: Use rabbit_log instead of error_logger --- src/rabbit_error_logger_file_h.erl | 6 +++--- src/rabbit_sasl_report_file_h.erl | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rabbit_error_logger_file_h.erl b/src/rabbit_error_logger_file_h.erl index 2de861b6..8e13a46c 100644 --- a/src/rabbit_error_logger_file_h.erl +++ b/src/rabbit_error_logger_file_h.erl @@ -42,9 +42,9 @@ init({{File, Suffix}, []}) -> Error -> case init(File) of {ok, FInfo} -> - error_logger:error_msg("Error occured while appending " ++ - "~p log file to \"~s\":~n~p~n", - [File, [File, Suffix], Error]), + rabbit_log:error("Error occured while appending " ++ + "~p log file to \"~s\":~n~p~n", + [File, [File, Suffix], Error]), io:format("~nOrignal log file could not be appended to " ++ "\"~s\"~n", [[File, Suffix]]), {ok, FInfo}; diff --git a/src/rabbit_sasl_report_file_h.erl b/src/rabbit_sasl_report_file_h.erl index 3b8a591a..cc463074 100644 --- a/src/rabbit_sasl_report_file_h.erl +++ b/src/rabbit_sasl_report_file_h.erl @@ -43,9 +43,9 @@ init({{File, Suffix}, []}) -> Error -> case init(File) of {ok, FInfo} -> - error_logger:error_msg("Error occured while appending " ++ - "~p sasl log file to \"~s\":~n~p~n", - [File, [File, Suffix], Error]), + rabbit_log:error("Error occured while appending " ++ + "~p sasl log file to \"~s\":~n~p~n", + [File, [File, Suffix], Error]), io:format("~nOrignal sasl log file could not be appended " "to \"~s\"~n", [[File, Suffix]]), {ok, FInfo}; -- cgit v1.2.1 From e2049ca6f77bd7635b67f5d8f0b35e1d2922d39c Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 1 Sep 2008 09:42:45 +0100 Subject: always log an error when append fails and don't log the error to the console --- src/rabbit_error_logger_file_h.erl | 19 ++++++------------- src/rabbit_sasl_report_file_h.erl | 19 ++++++------------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/rabbit_error_logger_file_h.erl b/src/rabbit_error_logger_file_h.erl index 8e13a46c..e65bb576 100644 --- a/src/rabbit_error_logger_file_h.erl +++ b/src/rabbit_error_logger_file_h.erl @@ -38,19 +38,12 @@ %% Used only when swapping handlers in log rotation init({{File, Suffix}, []}) -> case rabbit_misc:append_file(File, Suffix) of - ok -> init(File); - Error -> - case init(File) of - {ok, FInfo} -> - rabbit_log:error("Error occured while appending " ++ - "~p log file to \"~s\":~n~p~n", - [File, [File, Suffix], Error]), - io:format("~nOrignal log file could not be appended to " ++ - "\"~s\"~n", [[File, Suffix]]), - {ok, FInfo}; - CriticalError -> CriticalError - end - end; + ok -> ok; + Error -> rabbit_log:error("Failed to append contents of " ++ + "log file '~s' to '~s':~n~p~n", + [File, [File, Suffix], Error]) + end, + init(File); %% Used only when swapping handlers without performing %% log rotation init({File, []}) -> diff --git a/src/rabbit_sasl_report_file_h.erl b/src/rabbit_sasl_report_file_h.erl index cc463074..befd8057 100644 --- a/src/rabbit_sasl_report_file_h.erl +++ b/src/rabbit_sasl_report_file_h.erl @@ -39,19 +39,12 @@ %% log rotation init({{File, Suffix}, []}) -> case rabbit_misc:append_file(File, Suffix) of - ok -> init(File); - Error -> - case init(File) of - {ok, FInfo} -> - rabbit_log:error("Error occured while appending " ++ - "~p sasl log file to \"~s\":~n~p~n", - [File, [File, Suffix], Error]), - io:format("~nOrignal sasl log file could not be appended " - "to \"~s\"~n", [[File, Suffix]]), - {ok, FInfo}; - CriticalError -> CriticalError - end - end; + ok -> ok; + Error -> rabbit_log:error("Failed to append contents of " ++ + "sasl log file '~s' to '~s':~n~p~n", + [File, [File, Suffix], Error]) + end, + init(File); %% Used only when swapping handlers without %% doing any log rotation init({File, []}) -> -- cgit v1.2.1 From ac7ad4bc25f33632eed8f1d2a34007a4a60d5791 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 1 Sep 2008 09:46:22 +0100 Subject: cosmetic --- src/rabbit.erl | 4 +++- src/rabbit_error_logger_file_h.erl | 9 +++++---- src/rabbit_sasl_report_file_h.erl | 9 +++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index bf4cb013..473a2180 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -264,7 +264,9 @@ ensure_working_log_config() -> error_log_location(Type) -> case case Type of default -> error_logger:logfile(filename); - wrapper -> gen_event:call(error_logger, rabbit_error_logger_file_h, filename) + wrapper -> gen_event:call(error_logger, + rabbit_error_logger_file_h, + filename) end of {error, no_log_file} -> tty; {error, _} -> undefined; diff --git a/src/rabbit_error_logger_file_h.erl b/src/rabbit_error_logger_file_h.erl index e65bb576..30af2f7f 100644 --- a/src/rabbit_error_logger_file_h.erl +++ b/src/rabbit_error_logger_file_h.erl @@ -38,10 +38,11 @@ %% Used only when swapping handlers in log rotation init({{File, Suffix}, []}) -> case rabbit_misc:append_file(File, Suffix) of - ok -> ok; - Error -> rabbit_log:error("Failed to append contents of " ++ - "log file '~s' to '~s':~n~p~n", - [File, [File, Suffix], Error]) + ok -> ok; + {error, Error} -> + rabbit_log:error("Failed to append contents of " ++ + "log file '~s' to '~s':~n~p~n", + [File, [File, Suffix], Error]) end, init(File); %% Used only when swapping handlers without performing diff --git a/src/rabbit_sasl_report_file_h.erl b/src/rabbit_sasl_report_file_h.erl index befd8057..eaf9bc09 100644 --- a/src/rabbit_sasl_report_file_h.erl +++ b/src/rabbit_sasl_report_file_h.erl @@ -39,10 +39,11 @@ %% log rotation init({{File, Suffix}, []}) -> case rabbit_misc:append_file(File, Suffix) of - ok -> ok; - Error -> rabbit_log:error("Failed to append contents of " ++ - "sasl log file '~s' to '~s':~n~p~n", - [File, [File, Suffix], Error]) + ok -> ok; + {error, Error} -> + rabbit_log:error("Failed to append contents of " ++ + "sasl log file '~s' to '~s':~n~p~n", + [File, [File, Suffix], Error]) end, init(File); %% Used only when swapping handlers without -- cgit v1.2.1 From 595ef162999ddb1be3a62f11b56b949a46ff40c4 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 1 Sep 2008 09:51:56 +0100 Subject: cosmetic --- src/rabbit.erl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index 473a2180..edcea1f7 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -88,9 +88,12 @@ status() -> rotate_logs(BinarySuffix) -> Suffix = binary_to_list(BinarySuffix), - log_rotation_result( - rotate_logs(error_log_location(wrapper), Suffix, rabbit_error_logger_file_h), - rotate_logs(sasl_log_location(), Suffix, rabbit_sasl_report_file_h)). + log_rotation_result(rotate_logs(error_log_location(wrapper), + Suffix, + rabbit_error_logger_file_h), + rotate_logs(sasl_log_location(), + Suffix, + rabbit_sasl_report_file_h)). %%-------------------------------------------------------------------- -- cgit v1.2.1 From 022227f7f5b84f7618a41efb635dfe6290653a01 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 2 Sep 2008 11:46:52 +0100 Subject: Added test suite for log rotation. Initialise log rotation in its own phase. --- src/rabbit.erl | 107 +++++++++++++++++++++++++-------------------------- src/rabbit_tests.erl | 89 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+), 55 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index edcea1f7..1af550a3 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -31,6 +31,8 @@ -export([start/2, stop/1]). +-export([error_log_location/1, sasl_log_location/0]). + -import(application). -import(mnesia). -import(lists). @@ -46,6 +48,8 @@ -ifdef(use_specs). +-type(log_location() :: 'tty' | 'undefined' | string()). + -spec(start/0 :: () -> 'ok'). -spec(stop/0 :: () -> 'ok'). -spec(stop_and_halt/0 :: () -> 'ok'). @@ -54,6 +58,8 @@ [{running_applications, [{atom(), string(), string()}]} | {nodes, [node()]} | {running_nodes, [node()]}]). +-spec(error_log_location/1 :: ('default' | 'wrapper') -> log_location()). +-spec(sasl_log_location/0 :: () -> log_location()). -endif. @@ -61,7 +67,6 @@ start() -> try - ok = ensure_working_log_config(), ok = rabbit_mnesia:ensure_mnesia_dir(), ok = start_applications(?APPS) after @@ -143,7 +148,9 @@ start(normal, []) -> apply(M, F, A), io:format("done~n") end, - [{"database", + [{"log configuration", + fun () -> ok = maybe_swap_log_handlers() end}, + {"database", fun () -> ok = rabbit_mnesia:init() end}, {"core processes", fun () -> @@ -172,15 +179,7 @@ start(normal, []) -> {ok, DefaultVHost} = application:get_env(default_vhost), ok = error_logger:add_report_handler( rabbit_error_logger, [DefaultVHost]), - ok = start_builtin_amq_applications(), - %% Swap default handlers with rabbit wrappers - %% to simplify the swapping of log handlers later - ok = rotate_logs(error_log_location(default), "", - error_logger_file_h, - rabbit_error_logger_file_h), - ok = rotate_logs(sasl_log_location(), "", - sasl_report_file_h, - rabbit_sasl_report_file_h) + ok = start_builtin_amq_applications() end}, {"TCP listeners", fun () -> @@ -204,6 +203,29 @@ stop(_State) -> %--------------------------------------------------------------------------- +error_log_location(Type) -> + case case Type of + default -> error_logger:logfile(filename); + wrapper -> gen_event:call(error_logger, + rabbit_error_logger_file_h, + filename) + end of + {error, no_log_file} -> tty; + {error, _} -> undefined; + File -> File + end. + +sasl_log_location() -> + case application:get_env(sasl, sasl_error_logger) of + {ok, {file, File}} -> File; + {ok, false} -> undefined; + {ok, tty} -> tty; + {ok, Bad} -> throw({error, {cannot_log_to_file, Bad}}); + _ -> undefined + end. + +%--------------------------------------------------------------------------- + print_banner() -> {ok, Product} = application:get_key(id), {ok, Version} = application:get_key(vsn), @@ -220,6 +242,25 @@ start_child(Mod) -> transient, 100, worker, [Mod]}), ok. +maybe_swap_log_handlers() -> + Handlers = gen_event:which_handlers(error_logger), + ok = maybe_swap_log_handlers(error_logger_file_h, + rabbit_error_logger_file_h, + error_log_location(default), + Handlers), + ok = maybe_swap_log_handlers(sasl_report_file_h, + rabbit_sasl_report_file_h, + sasl_log_location(), + Handlers), + ok. + +maybe_swap_log_handlers(Old, New, LogLocation, Handlers) -> + case lists:member(Old, Handlers) + and not(lists:member(New, Handlers)) of + true -> rotate_logs(LogLocation, "", Old, New); + false -> ok + end. + maybe_insert_default_data() -> case rabbit_mnesia:is_db_empty() of true -> insert_default_data(); @@ -241,50 +282,6 @@ start_builtin_amq_applications() -> %%restart ok. -ensure_working_log_config() -> - case error_logger:logfile(filename) of - {error, no_log_file} -> - %% either no log file was configured or opening it failed. - case application:get_env(kernel, error_logger) of - {ok, {file, Filename}} -> - case filelib:ensure_dir(Filename) of - ok -> ok; - {error, Reason1} -> - throw({error, {cannot_log_to_file, - Filename, Reason1}}) - end, - case error_logger:logfile({open, Filename}) of - ok -> ok; - {error, Reason2} -> - throw({error, {cannot_log_to_file, - Filename, Reason2}}) - end; - _ -> ok - end; - _Filename -> ok - end. - -error_log_location(Type) -> - case case Type of - default -> error_logger:logfile(filename); - wrapper -> gen_event:call(error_logger, - rabbit_error_logger_file_h, - filename) - end of - {error, no_log_file} -> tty; - {error, _} -> undefined; - File -> File - end. - -sasl_log_location() -> - case application:get_env(sasl, sasl_error_logger) of - {ok, {file, File}} -> File; - {ok, false} -> undefined; - {ok, tty} -> tty; - {ok, Bad} -> throw({error, {cannot_log_to_file, Bad}}); - _ -> undefined - end. - rotate_logs(File, Suffix, Handler) -> rotate_logs(File, Suffix, Handler, Handler). diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 6f43b08a..f8d68f17 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -1,3 +1,4 @@ + %% The contents of this file are subject to the Mozilla Public License %% Version 1.1 (the "License"); you may not use this file except in %% compliance with the License. You may obtain a copy of the License at @@ -29,6 +30,9 @@ -import(lists). +-include("rabbit.hrl"). +-include_lib("kernel/include/file.hrl"). + test_content_prop_roundtrip(Datum, Binary) -> Types = [element(1, E) || E <- Datum], Values = [element(2, E) || E <- Datum], @@ -38,6 +42,7 @@ test_content_prop_roundtrip(Datum, Binary) -> all_tests() -> passed = test_parsing(), passed = test_topic_matching(), + passed = test_log_management(), passed = test_app_management(), passed = test_cluster_management(), passed = test_user_management(), @@ -136,6 +141,57 @@ test_app_management() -> ok = control_action(status, []), passed. +test_log_management() -> + MainLog = rabbit:error_log_location(wrapper), + SaslLog = rabbit:sasl_log_location(), + Suffix = ".1", + + %% prepare basic logs + file:delete([MainLog, Suffix]), + file:delete([SaslLog, Suffix]), + ok = test_logs_working(MainLog, SaslLog), + + %% simple logs reopening + ok = control_action(rotate_logs, []), + true = empty_file(MainLog), + true = empty_file(SaslLog), + ok = test_logs_working(MainLog, SaslLog), + + %% simple log rotation + ok = control_action(rotate_logs, [Suffix]), + true = non_empty_file([MainLog, Suffix]), + true = non_empty_file([SaslLog, Suffix]), + true = empty_file(MainLog), + true = empty_file(MainLog), + ok = test_logs_working(MainLog, SaslLog), + + %% reopening logs with log rotation performed first + clean_logs([MainLog, SaslLog], Suffix), + ok = control_action(rotate_logs, []), + ok = file:rename(MainLog, [MainLog, Suffix]), + ok = file:rename(SaslLog, [SaslLog, Suffix]), + ok = test_logs_working([MainLog, Suffix], [SaslLog, Suffix]), + ok = control_action(rotate_logs, []), + ok = test_logs_working(MainLog, SaslLog), + + %% logs with suffix are not writable + non_writable_file([MainLog, Suffix]), + non_writable_file([SaslLog, Suffix]), + ok = control_action(rotate_logs, [Suffix]), + ok = test_logs_working(MainLog, SaslLog), + + %% original log files are not writable + non_writable_file(MainLog), + non_writable_file(SaslLog), + {error, _} = control_action(rotate_logs, []), + %% cleanup, add handlers removed by last command + clean_logs([MainLog, SaslLog], Suffix), + ok = error_logger:add_report_handler(rabbit_error_logger_file_h, + MainLog), + ok = error_logger:add_report_handler(rabbit_sasl_report_file_h, + SaslLog), + passed. + test_cluster_management() -> %% 'cluster' and 'reset' should only work if the app is stopped @@ -329,6 +385,8 @@ test_user_management() -> passed. +%--------------------------------------------------------------------- + control_action(Command, Args) -> control_action(Command, node(), Args). control_action(Command, Node, Args) -> @@ -340,3 +398,34 @@ control_action(Command, Node, Args) -> io:format("failed.~n"), Other end. + +empty_file(File) -> + case file:read_file_info(File) of + {ok, FInfo} -> FInfo#file_info.size == 0; + Error -> Error + end. + +non_empty_file(File) -> + case empty_file(File) of + {error, Reason} -> {error, Reason}; + Result -> not(Result) + end. + +test_logs_working(MainLogFile, SaslLogFile) -> + ok = rabbit_log:error("foo bar"), + ok = error_logger:error_report(crash_report, [foo, bar]), + %% give the error loggers some time to catch up + timer:sleep(50), + true = non_empty_file(MainLogFile), + true = non_empty_file(SaslLogFile), + ok. + +clean_logs(Files, Suffix) -> + lists:map(fun(File) -> + file:delete(File), + file:delete([File, Suffix]) + end, Files), + ok. + +non_writable_file(File) -> + ok = file:write_file_info(File, #file_info{mode=0}). -- cgit v1.2.1 From 86c1663dda5a65a7b281f53f571acea7679d43de Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 2 Sep 2008 12:14:47 +0100 Subject: Refactoring of the log tests --- src/rabbit_tests.erl | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index f8d68f17..bf34df21 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -153,16 +153,13 @@ test_log_management() -> %% simple logs reopening ok = control_action(rotate_logs, []), - true = empty_file(MainLog), - true = empty_file(SaslLog), + [true, true] = empty_files([MainLog, SaslLog]), ok = test_logs_working(MainLog, SaslLog), %% simple log rotation ok = control_action(rotate_logs, [Suffix]), - true = non_empty_file([MainLog, Suffix]), - true = non_empty_file([SaslLog, Suffix]), - true = empty_file(MainLog), - true = empty_file(MainLog), + [true, true] = non_empty_files([[MainLog, Suffix], [SaslLog, Suffix]]), + [true, true] = empty_files([MainLog, SaslLog]), ok = test_logs_working(MainLog, SaslLog), %% reopening logs with log rotation performed first @@ -175,14 +172,12 @@ test_log_management() -> ok = test_logs_working(MainLog, SaslLog), %% logs with suffix are not writable - non_writable_file([MainLog, Suffix]), - non_writable_file([SaslLog, Suffix]), + non_writable_files([[MainLog, Suffix], [SaslLog, Suffix]]), ok = control_action(rotate_logs, [Suffix]), ok = test_logs_working(MainLog, SaslLog), %% original log files are not writable - non_writable_file(MainLog), - non_writable_file(SaslLog), + non_writable_files([MainLog, SaslLog]), {error, _} = control_action(rotate_logs, []), %% cleanup, add handlers removed by last command clean_logs([MainLog, SaslLog], Suffix), @@ -399,25 +394,29 @@ control_action(Command, Node, Args) -> Other end. -empty_file(File) -> - case file:read_file_info(File) of - {ok, FInfo} -> FInfo#file_info.size == 0; - Error -> Error - end. - -non_empty_file(File) -> - case empty_file(File) of - {error, Reason} -> {error, Reason}; - Result -> not(Result) - end. +empty_files(Files) -> + lists:map(fun(File) -> + case file:read_file_info(File) of + {ok, FInfo} -> FInfo#file_info.size == 0; + Error -> Error + end + end, Files). + +non_empty_files(Files) -> + Results = empty_files(Files), + lists:map(fun(EmptyFile) -> + case EmptyFile of + {error, Reason} -> {error, Reason}; + _ -> not(EmptyFile) + end + end, Results). test_logs_working(MainLogFile, SaslLogFile) -> ok = rabbit_log:error("foo bar"), ok = error_logger:error_report(crash_report, [foo, bar]), %% give the error loggers some time to catch up timer:sleep(50), - true = non_empty_file(MainLogFile), - true = non_empty_file(SaslLogFile), + [true, true] = non_empty_files([MainLogFile, SaslLogFile]), ok. clean_logs(Files, Suffix) -> @@ -427,5 +426,7 @@ clean_logs(Files, Suffix) -> end, Files), ok. -non_writable_file(File) -> - ok = file:write_file_info(File, #file_info{mode=0}). +non_writable_files(Files) -> + lists:map(fun(File) -> + ok = file:write_file_info(File, #file_info{mode=0}) + end, Files). -- cgit v1.2.1 From 1eb954d164f75d7a29403657ef1a9c983a049580 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 2 Sep 2008 13:01:19 +0100 Subject: Better naming for types --- include/rabbit.hrl | 2 +- include/rabbit_framing_spec.hrl | 2 +- src/rabbit.erl | 3 ++- src/rabbit_misc.erl | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/rabbit.hrl b/include/rabbit.hrl index b374f047..180a0dc3 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -71,7 +71,7 @@ -type(r(Kind) :: #resource{virtual_host :: vhost(), kind :: Kind, - name :: binary_name()}). + name :: resource_name()}). -type(queue_name() :: r('queue')). -type(exchange_name() :: r('exchange')). -type(user() :: diff --git a/include/rabbit_framing_spec.hrl b/include/rabbit_framing_spec.hrl index 6bd1cd91..e9e65092 100644 --- a/include/rabbit_framing_spec.hrl +++ b/include/rabbit_framing_spec.hrl @@ -46,7 +46,7 @@ -type(channel_number() :: non_neg_integer()). %% TODO: make this more precise -type(amqp_error() :: {bool(), non_neg_integer(), binary()}). --type(binary_name() :: binary()). +-type(resource_name() :: binary()). -type(routing_key() :: binary()). -type(username() :: binary()). -type(password() :: binary()). diff --git a/src/rabbit.erl b/src/rabbit.erl index 1af550a3..779416e3 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -49,11 +49,12 @@ -ifdef(use_specs). -type(log_location() :: 'tty' | 'undefined' | string()). +-type(file_suffix() :: binary()). -spec(start/0 :: () -> 'ok'). -spec(stop/0 :: () -> 'ok'). -spec(stop_and_halt/0 :: () -> 'ok'). --spec(rotate_logs/1 :: (binary_name()) -> 'ok' | {'error', any()}). +-spec(rotate_logs/1 :: (file_suffix()) -> 'ok' | {'error', any()}). -spec(status/0 :: () -> [{running_applications, [{atom(), string(), string()}]} | {nodes, [node()]} | diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index cf6a483a..db6da45c 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -68,7 +68,7 @@ -spec(get_config/2 :: (atom(), A) -> A). -spec(set_config/2 :: (atom(), any()) -> 'ok'). -spec(dirty_read/1 :: ({atom(), any()}) -> {'ok', any()} | not_found()). --spec(r/3 :: (vhost(), K, binary_name()) -> r(K) when is_subtype(K, atom())). +-spec(r/3 :: (vhost(), K, resource_name()) -> r(K) when is_subtype(K, atom())). -spec(r/2 :: (vhost(), K) -> #resource{virtual_host :: vhost(), kind :: K, name :: '_'} -- cgit v1.2.1 From d3443aad822e33578f692b0271c7235f24509c32 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 2 Sep 2008 14:30:05 +0100 Subject: Removed unused include --- src/rabbit_tests.erl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index bf34df21..5693c263 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -30,7 +30,6 @@ -import(lists). --include("rabbit.hrl"). -include_lib("kernel/include/file.hrl"). test_content_prop_roundtrip(Datum, Binary) -> -- cgit v1.2.1 From af50129da1992c1d8ee8aee0b82c57602a182827 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Tue, 2 Sep 2008 14:47:03 +0100 Subject: some minor tweaks - list comprehension instead of lists:map - make clean_logs check the return of file:delete, and return ok itself - rename non_writable_files to make_files_nonwritable for clarity --- src/rabbit_tests.erl | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 5693c263..46158375 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -162,7 +162,7 @@ test_log_management() -> ok = test_logs_working(MainLog, SaslLog), %% reopening logs with log rotation performed first - clean_logs([MainLog, SaslLog], Suffix), + ok = clean_logs([MainLog, SaslLog], Suffix), ok = control_action(rotate_logs, []), ok = file:rename(MainLog, [MainLog, Suffix]), ok = file:rename(SaslLog, [SaslLog, Suffix]), @@ -171,15 +171,15 @@ test_log_management() -> ok = test_logs_working(MainLog, SaslLog), %% logs with suffix are not writable - non_writable_files([[MainLog, Suffix], [SaslLog, Suffix]]), + ok = make_files_non_writable([[MainLog, Suffix], [SaslLog, Suffix]]), ok = control_action(rotate_logs, [Suffix]), ok = test_logs_working(MainLog, SaslLog), %% original log files are not writable - non_writable_files([MainLog, SaslLog]), + ok = make_files_non_writable([MainLog, SaslLog]), {error, _} = control_action(rotate_logs, []), %% cleanup, add handlers removed by last command - clean_logs([MainLog, SaslLog], Suffix), + ok = clean_logs([MainLog, SaslLog], Suffix), ok = error_logger:add_report_handler(rabbit_error_logger_file_h, MainLog), ok = error_logger:add_report_handler(rabbit_sasl_report_file_h, @@ -394,21 +394,16 @@ control_action(Command, Node, Args) -> end. empty_files(Files) -> - lists:map(fun(File) -> - case file:read_file_info(File) of - {ok, FInfo} -> FInfo#file_info.size == 0; - Error -> Error - end - end, Files). + [case file:read_file_info(File) of + {ok, FInfo} -> FInfo#file_info.size == 0; + Error -> Error + end || File <- Files]. non_empty_files(Files) -> - Results = empty_files(Files), - lists:map(fun(EmptyFile) -> - case EmptyFile of - {error, Reason} -> {error, Reason}; - _ -> not(EmptyFile) - end - end, Results). + [case EmptyFile of + {error, Reason} -> {error, Reason}; + _ -> not(EmptyFile) + end || EmptyFile <- empty_files(Files)]. test_logs_working(MainLogFile, SaslLogFile) -> ok = rabbit_log:error("foo bar"), @@ -419,13 +414,13 @@ test_logs_working(MainLogFile, SaslLogFile) -> ok. clean_logs(Files, Suffix) -> - lists:map(fun(File) -> - file:delete(File), - file:delete([File, Suffix]) - end, Files), + [begin + ok = file:delete(File), + ok = file:delete([File, Suffix]) + end || File <- Files], ok. -non_writable_files(Files) -> - lists:map(fun(File) -> - ok = file:write_file_info(File, #file_info{mode=0}) - end, Files). +make_files_non_writable(Files) -> + [ok = file:write_file_info(File, #file_info{mode=0}) || + File <- Files], + ok. -- cgit v1.2.1 From 3d51aa4d28b496c4d828022d3bab631978f24f0b Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 2 Sep 2008 17:33:29 +0100 Subject: Added more test cases --- src/rabbit_tests.erl | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 46158375..a443d72c 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -148,7 +148,6 @@ test_log_management() -> %% prepare basic logs file:delete([MainLog, Suffix]), file:delete([SaslLog, Suffix]), - ok = test_logs_working(MainLog, SaslLog), %% simple logs reopening ok = control_action(rotate_logs, []), @@ -170,16 +169,45 @@ test_log_management() -> ok = control_action(rotate_logs, []), ok = test_logs_working(MainLog, SaslLog), + %% log rotation on empty file + ok = clean_logs([MainLog, SaslLog], Suffix), + ok = control_action(rotate_logs, []), + ok = control_action(rotate_logs, [Suffix]), + [true, true] = empty_files([[MainLog, Suffix], [SaslLog, Suffix]]), + + %% original main log file is not writable + ok = make_files_non_writable([MainLog]), + {error, {cannot_rotate_main_logs, _}} = control_action(rotate_logs, []), + ok = clean_logs([MainLog], Suffix), + ok = error_logger:add_report_handler(rabbit_error_logger_file_h, + MainLog), + + %% original sasl log file is not writable + ok = make_files_non_writable([SaslLog]), + {error, {cannot_rotate_sasl_logs, _}} = control_action(rotate_logs, []), + ok = clean_logs([SaslLog], Suffix), + ok = error_logger:add_report_handler(rabbit_sasl_report_file_h, + SaslLog), + %% logs with suffix are not writable + ok = control_action(rotate_logs, [Suffix]), ok = make_files_non_writable([[MainLog, Suffix], [SaslLog, Suffix]]), ok = control_action(rotate_logs, [Suffix]), ok = test_logs_working(MainLog, SaslLog), %% original log files are not writable ok = make_files_non_writable([MainLog, SaslLog]), - {error, _} = control_action(rotate_logs, []), - %% cleanup, add handlers removed by last command + {error, {{cannot_rotate_main_logs, _}, + {cannot_rotate_sasl_logs, _}}} = control_action(rotate_logs, []), + + %% logging directed to tty (handlers were removed in last test) ok = clean_logs([MainLog, SaslLog], Suffix), + ok = application:set_env(sasl, sasl_error_logger, tty), + ok = control_action(rotate_logs, []), + [{error, enoent}, {error, enoent}] = empty_files([MainLog, SaslLog]), + + %% cleanup + ok = application:set_env(sasl, sasl_error_logger, {file, SaslLog}), ok = error_logger:add_report_handler(rabbit_error_logger_file_h, MainLog), ok = error_logger:add_report_handler(rabbit_sasl_report_file_h, @@ -253,7 +281,6 @@ test_cluster_management() -> end, ok = control_action(start_app, []), - passed. test_cluster_management2(SecondaryNode) -> @@ -415,11 +442,18 @@ test_logs_working(MainLogFile, SaslLogFile) -> clean_logs(Files, Suffix) -> [begin - ok = file:delete(File), - ok = file:delete([File, Suffix]) + ok = delete_file(File), + ok = delete_file([File, Suffix]) end || File <- Files], ok. +delete_file(File) -> + case file:delete(File) of + ok -> ok; + {error, enoent} -> ok; + Error -> Error + end. + make_files_non_writable(Files) -> [ok = file:write_file_info(File, #file_info{mode=0}) || File <- Files], -- cgit v1.2.1 From c0c4eb35c0f0fde780603aae8f8f42b951cb5676 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 3 Sep 2008 13:43:47 +0100 Subject: Simplified the way we get logs locations, Proper checking for the right handlers. Added test case for log rotation when logging is turned off. --- src/rabbit.erl | 73 ++++++++++++++++++++++++++-------------------------- src/rabbit_tests.erl | 15 ++++++++--- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index 779416e3..5190fd58 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -31,7 +31,7 @@ -export([start/2, stop/1]). --export([error_log_location/1, sasl_log_location/0]). +-export([logs_location/1]). -import(application). -import(mnesia). @@ -59,8 +59,7 @@ [{running_applications, [{atom(), string(), string()}]} | {nodes, [node()]} | {running_nodes, [node()]}]). --spec(error_log_location/1 :: ('default' | 'wrapper') -> log_location()). --spec(sasl_log_location/0 :: () -> log_location()). +-spec(logs_location/1 :: ('sasl' | 'kernel') -> log_location()). -endif. @@ -94,10 +93,10 @@ status() -> rotate_logs(BinarySuffix) -> Suffix = binary_to_list(BinarySuffix), - log_rotation_result(rotate_logs(error_log_location(wrapper), + log_rotation_result(rotate_logs(logs_location(kernel), Suffix, rabbit_error_logger_file_h), - rotate_logs(sasl_log_location(), + rotate_logs(logs_location(sasl), Suffix, rabbit_sasl_report_file_h)). @@ -149,8 +148,8 @@ start(normal, []) -> apply(M, F, A), io:format("done~n") end, - [{"log configuration", - fun () -> ok = maybe_swap_log_handlers() end}, + [{"log configuration", + fun () -> ok = ensure_working_log_handlers() end}, {"database", fun () -> ok = rabbit_mnesia:init() end}, {"core processes", @@ -204,23 +203,15 @@ stop(_State) -> %--------------------------------------------------------------------------- -error_log_location(Type) -> - case case Type of - default -> error_logger:logfile(filename); - wrapper -> gen_event:call(error_logger, - rabbit_error_logger_file_h, - filename) - end of - {error, no_log_file} -> tty; - {error, _} -> undefined; - File -> File - end. - -sasl_log_location() -> - case application:get_env(sasl, sasl_error_logger) of +logs_location(Type) -> + case application:get_env(Type, case Type of + kernel -> error_logger; + sasl -> sasl_error_logger + end) of {ok, {file, File}} -> File; {ok, false} -> undefined; {ok, tty} -> tty; + {ok, silent} -> undefined; {ok, Bad} -> throw({error, {cannot_log_to_file, Bad}}); _ -> undefined end. @@ -235,7 +226,9 @@ print_banner() -> ?PROTOCOL_VERSION_MAJOR, ?PROTOCOL_VERSION_MINOR, ?COPYRIGHT_MESSAGE, ?INFORMATION_MESSAGE]), io:format("Logging to ~p~nSASL logging to ~p~n~n", - [error_log_location(default), sasl_log_location()]). + [logs_location(kernel), logs_location(sasl)]). + + start_child(Mod) -> {ok,_} = supervisor:start_child(rabbit_sup, @@ -243,23 +236,31 @@ start_child(Mod) -> transient, 100, worker, [Mod]}), ok. -maybe_swap_log_handlers() -> +ensure_working_log_handlers() -> Handlers = gen_event:which_handlers(error_logger), - ok = maybe_swap_log_handlers(error_logger_file_h, - rabbit_error_logger_file_h, - error_log_location(default), - Handlers), - ok = maybe_swap_log_handlers(sasl_report_file_h, - rabbit_sasl_report_file_h, - sasl_log_location(), - Handlers), + ok = ensure_working_log_handler(error_logger_file_h, + rabbit_error_logger_file_h, + error_logger_tty_h, + logs_location(kernel), + Handlers), + + ok = ensure_working_log_handler(sasl_report_file_h, + rabbit_sasl_report_file_h, + sasl_report_tty_h, + logs_location(sasl), + Handlers), ok. -maybe_swap_log_handlers(Old, New, LogLocation, Handlers) -> - case lists:member(Old, Handlers) - and not(lists:member(New, Handlers)) of - true -> rotate_logs(LogLocation, "", Old, New); - false -> ok +ensure_working_log_handler(OldFHandler, NewFHandler, TTYHandler, + LogLocation, Handlers) -> + case LogLocation of + undefined -> ok; + tty -> true = lists:member(TTYHandler, Handlers), ok; + _ -> case lists:member(NewFHandler, Handlers) of + true -> ok; + false -> rotate_logs(LogLocation, "", + OldFHandler, NewFHandler) + end end. maybe_insert_default_data() -> diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index a443d72c..59bd9d70 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -1,4 +1,3 @@ - %% The contents of this file are subject to the Mozilla Public License %% Version 1.1 (the "License"); you may not use this file except in %% compliance with the License. You may obtain a copy of the License at @@ -141,8 +140,8 @@ test_app_management() -> passed. test_log_management() -> - MainLog = rabbit:error_log_location(wrapper), - SaslLog = rabbit:sasl_log_location(), + MainLog = rabbit:logs_location(kernel), + SaslLog = rabbit:logs_location(sasl), Suffix = ".1", %% prepare basic logs @@ -203,11 +202,19 @@ test_log_management() -> %% logging directed to tty (handlers were removed in last test) ok = clean_logs([MainLog, SaslLog], Suffix), ok = application:set_env(sasl, sasl_error_logger, tty), + ok = application:set_env(kernel, error_logger, tty), ok = control_action(rotate_logs, []), [{error, enoent}, {error, enoent}] = empty_files([MainLog, SaslLog]), - + + %% rotate logs when logging is turned off + ok = application:set_env(sasl, sasl_error_logger, false), + ok = application:set_env(kernel, error_logger, silent), + ok = control_action(rotate_logs, []), + [{error, enoent}, {error, enoent}] = empty_files([MainLog, SaslLog]), + %% cleanup ok = application:set_env(sasl, sasl_error_logger, {file, SaslLog}), + ok = application:set_env(kernel, error_logger, {file, MainLog}), ok = error_logger:add_report_handler(rabbit_error_logger_file_h, MainLog), ok = error_logger:add_report_handler(rabbit_sasl_report_file_h, -- cgit v1.2.1 From 38616df03ffeac5984a3edd515e89de7be5b8db6 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 3 Sep 2008 15:44:56 +0100 Subject: Renamed logs_location/1 function to log_location/1. Added more test cases to cover problems with logging during startup. --- src/rabbit.erl | 16 ++++++------ src/rabbit_tests.erl | 71 ++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 69 insertions(+), 18 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index 5190fd58..2d309c05 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -31,7 +31,7 @@ -export([start/2, stop/1]). --export([logs_location/1]). +-export([log_location/1]). -import(application). -import(mnesia). @@ -59,7 +59,7 @@ [{running_applications, [{atom(), string(), string()}]} | {nodes, [node()]} | {running_nodes, [node()]}]). --spec(logs_location/1 :: ('sasl' | 'kernel') -> log_location()). +-spec(log_location/1 :: ('sasl' | 'kernel') -> log_location()). -endif. @@ -93,10 +93,10 @@ status() -> rotate_logs(BinarySuffix) -> Suffix = binary_to_list(BinarySuffix), - log_rotation_result(rotate_logs(logs_location(kernel), + log_rotation_result(rotate_logs(log_location(kernel), Suffix, rabbit_error_logger_file_h), - rotate_logs(logs_location(sasl), + rotate_logs(log_location(sasl), Suffix, rabbit_sasl_report_file_h)). @@ -203,7 +203,7 @@ stop(_State) -> %--------------------------------------------------------------------------- -logs_location(Type) -> +log_location(Type) -> case application:get_env(Type, case Type of kernel -> error_logger; sasl -> sasl_error_logger @@ -226,7 +226,7 @@ print_banner() -> ?PROTOCOL_VERSION_MAJOR, ?PROTOCOL_VERSION_MINOR, ?COPYRIGHT_MESSAGE, ?INFORMATION_MESSAGE]), io:format("Logging to ~p~nSASL logging to ~p~n~n", - [logs_location(kernel), logs_location(sasl)]). + [log_location(kernel), log_location(sasl)]). @@ -241,13 +241,13 @@ ensure_working_log_handlers() -> ok = ensure_working_log_handler(error_logger_file_h, rabbit_error_logger_file_h, error_logger_tty_h, - logs_location(kernel), + log_location(kernel), Handlers), ok = ensure_working_log_handler(sasl_report_file_h, rabbit_sasl_report_file_h, sasl_report_tty_h, - logs_location(sasl), + log_location(sasl), Handlers), ok. diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 59bd9d70..34eebec1 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -42,6 +42,7 @@ all_tests() -> passed = test_topic_matching(), passed = test_log_management(), passed = test_app_management(), + passed = test_log_management_during_startup(), passed = test_cluster_management(), passed = test_user_management(), passed. @@ -140,8 +141,8 @@ test_app_management() -> passed. test_log_management() -> - MainLog = rabbit:logs_location(kernel), - SaslLog = rabbit:logs_location(sasl), + MainLog = rabbit:log_location(kernel), + SaslLog = rabbit:log_location(sasl), Suffix = ".1", %% prepare basic logs @@ -178,15 +179,13 @@ test_log_management() -> ok = make_files_non_writable([MainLog]), {error, {cannot_rotate_main_logs, _}} = control_action(rotate_logs, []), ok = clean_logs([MainLog], Suffix), - ok = error_logger:add_report_handler(rabbit_error_logger_file_h, - MainLog), + ok = add_log_handlers([{rabbit_error_logger_file_h, MainLog}]), %% original sasl log file is not writable ok = make_files_non_writable([SaslLog]), {error, {cannot_rotate_sasl_logs, _}} = control_action(rotate_logs, []), ok = clean_logs([SaslLog], Suffix), - ok = error_logger:add_report_handler(rabbit_sasl_report_file_h, - SaslLog), + ok = add_log_handlers([{rabbit_sasl_report_file_h, SaslLog}]), %% logs with suffix are not writable ok = control_action(rotate_logs, [Suffix]), @@ -215,10 +214,52 @@ test_log_management() -> %% cleanup ok = application:set_env(sasl, sasl_error_logger, {file, SaslLog}), ok = application:set_env(kernel, error_logger, {file, MainLog}), - ok = error_logger:add_report_handler(rabbit_error_logger_file_h, - MainLog), - ok = error_logger:add_report_handler(rabbit_sasl_report_file_h, - SaslLog), + ok = add_log_handlers([{rabbit_error_logger_file_h, MainLog}, + {rabbit_sasl_report_file_h, SaslLog}]), + passed. + +test_log_management_during_startup() -> + MainLog = rabbit:log_location(kernel), + SaslLog = rabbit:log_location(sasl), + + %% start application with simple tty logging + ok = control_action(stop_app, []), + ok = application:set_env(kernel, error_logger, tty), + ok = application:set_env(sasl, sasl_error_logger, tty), + ok = add_log_handlers([{error_logger_tty_h, []}, + {sasl_report_tty_h, []}]), + ok = control_action(start_app, []), + + %% start application with tty logging and + %% proper handlers not installed + ok = control_action(stop_app, []), + ok = error_logger:tty(false), + ok = delete_log_handlers([sasl_report_tty_h]), + ok = case catch control_action(start_app, []) of + ok -> exit(got_success_but_expected_failure); + {error, {cannot_start_application, rabbit, _}} -> ok + end, + + %% fix sasl logging + ok = application:set_env(sasl, sasl_error_logger, + {file, SaslLog}), + + %% start application with logging to invalid directory + TmpLog = "/tmp/rabbit-tests/test.log", + file:delete(TmpLog), + ok = application:set_env(kernel, error_logger, {file, TmpLog}), + + ok = delete_log_handlers([rabbit_error_logger_file_h]), + ok = add_log_handlers([{error_logger_file_h, MainLog}]), + ok = case catch control_action(start_app, []) of + ok -> exit(got_success_but_expected_failure); + {error, {cannot_start_application, rabbit, _}} -> ok + end, + + %% cleanup + ok = add_log_handlers([{error_logger_file_h, MainLog}]), + ok = application:set_env(kernel, error_logger, {file, MainLog}), + ok = control_action(start_app, []), passed. test_cluster_management() -> @@ -465,3 +506,13 @@ make_files_non_writable(Files) -> [ok = file:write_file_info(File, #file_info{mode=0}) || File <- Files], ok. + +add_log_handlers(Handlers) -> + [ok = error_logger:add_report_handler(Handler, Args) || + {Handler, Args} <- Handlers], + ok. + +delete_log_handlers(Handlers) -> + [[] = error_logger:delete_report_handler(Handler) || + Handler <- Handlers], + ok. -- cgit v1.2.1 From 61dfd8b50862e44ec9f667690dfa082d3c887c70 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 4 Sep 2008 11:12:11 +0100 Subject: Moved log configuration to start/0, throw more informative errors --- src/rabbit.erl | 25 +++++++++++++++++-------- src/rabbit_tests.erl | 4 ++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index 2d309c05..4cb11f4f 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -67,6 +67,7 @@ start() -> try + ok = ensure_working_log_handlers(), ok = rabbit_mnesia:ensure_mnesia_dir(), ok = start_applications(?APPS) after @@ -148,9 +149,7 @@ start(normal, []) -> apply(M, F, A), io:format("done~n") end, - [{"log configuration", - fun () -> ok = ensure_working_log_handlers() end}, - {"database", + [{"database", fun () -> ok = rabbit_mnesia:init() end}, {"core processes", fun () -> @@ -253,16 +252,26 @@ ensure_working_log_handlers() -> ensure_working_log_handler(OldFHandler, NewFHandler, TTYHandler, LogLocation, Handlers) -> - case LogLocation of + case LogLocation of undefined -> ok; - tty -> true = lists:member(TTYHandler, Handlers), ok; + tty -> case lists:member(TTYHandler, Handlers) of + true -> ok; + false -> + throw({error, {cannot_log_to_tty, + TTYHandler, not_installed}}) + end; _ -> case lists:member(NewFHandler, Handlers) of true -> ok; - false -> rotate_logs(LogLocation, "", - OldFHandler, NewFHandler) + false -> case rotate_logs(LogLocation, "", + OldFHandler, NewFHandler) of + ok -> ok; + {error, Reason} -> + throw({error, {cannot_log_to_file, + LogLocation, Reason}}) + end end end. - + maybe_insert_default_data() -> case rabbit_mnesia:is_db_empty() of true -> insert_default_data(); diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 34eebec1..64425ee7 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -237,7 +237,7 @@ test_log_management_during_startup() -> ok = delete_log_handlers([sasl_report_tty_h]), ok = case catch control_action(start_app, []) of ok -> exit(got_success_but_expected_failure); - {error, {cannot_start_application, rabbit, _}} -> ok + {error, {cannot_log_to_tty, _, _}} -> ok end, %% fix sasl logging @@ -253,7 +253,7 @@ test_log_management_during_startup() -> ok = add_log_handlers([{error_logger_file_h, MainLog}]), ok = case catch control_action(start_app, []) of ok -> exit(got_success_but_expected_failure); - {error, {cannot_start_application, rabbit, _}} -> ok + {error, {cannot_log_to_file, _, _}} -> ok end, %% cleanup -- cgit v1.2.1 From 6926865c7c5ca7dac6be8a78ece469add7b14b92 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 4 Sep 2008 14:02:11 +0100 Subject: Perform standard handler installation when original handler was not installed correcly or terminated with an error. --- src/rabbit_error_logger_file_h.erl | 4 ++++ src/rabbit_sasl_report_file_h.erl | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/rabbit_error_logger_file_h.erl b/src/rabbit_error_logger_file_h.erl index 30af2f7f..d67b02ef 100644 --- a/src/rabbit_error_logger_file_h.erl +++ b/src/rabbit_error_logger_file_h.erl @@ -45,6 +45,10 @@ init({{File, Suffix}, []}) -> [File, [File, Suffix], Error]) end, init(File); +%% Used only when swapping handlers and the original handler +%% failed to terminate or was never installed +init({{File, _}, error}) -> + init(File); %% Used only when swapping handlers without performing %% log rotation init({File, []}) -> diff --git a/src/rabbit_sasl_report_file_h.erl b/src/rabbit_sasl_report_file_h.erl index eaf9bc09..3374d63d 100644 --- a/src/rabbit_sasl_report_file_h.erl +++ b/src/rabbit_sasl_report_file_h.erl @@ -46,6 +46,10 @@ init({{File, Suffix}, []}) -> [File, [File, Suffix], Error]) end, init(File); +%% Used only when swapping handlers and the original handler +%% failed to terminate or was never installed +init({{File, _}, error}) -> + init(File); %% Used only when swapping handlers without %% doing any log rotation init({File, []}) -> -- cgit v1.2.1 From 45e60556aa523bddd6144eeadb6387c5705bd1f6 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 4 Sep 2008 15:00:03 +0100 Subject: Added tests to cover the changes made in last commit --- Makefile | 8 ++++---- packaging/debs/Debian/Makefile | 7 ++++--- src/rabbit_tests.erl | 12 +++++++++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 2ed64aa5..4bbf227a 100644 --- a/Makefile +++ b/Makefile @@ -99,11 +99,11 @@ generic_stage: if [ -f INSTALL.in ]; then \ cp INSTALL.in $(GENERIC_STAGE_DIR)/INSTALL; \ - elinks -dump -no-references -no-numbering $(WEB_URL)install.html \ - >> $(GENERIC_STAGE_DIR)/INSTALL; \ +# elinks -dump -no-references -no-numbering $(WEB_URL)install.html \ +# >> $(GENERIC_STAGE_DIR)/INSTALL; \ cp BUILD.in $(GENERIC_STAGE_DIR)/BUILD; \ - elinks -dump -no-references -no-numbering $(WEB_URL)build-server.html \ - >> $(GENERIC_STAGE_DIR)/BUILD; \ +# elinks -dump -no-references -no-numbering $(WEB_URL)build-server.html \ +# >> $(GENERIC_STAGE_DIR)/BUILD; \ else \ cp INSTALL $(GENERIC_STAGE_DIR); \ cp BUILD $(GENERIC_STAGE_DIR); \ diff --git a/packaging/debs/Debian/Makefile b/packaging/debs/Debian/Makefile index aeb958a7..5e4812a3 100644 --- a/packaging/debs/Debian/Makefile +++ b/packaging/debs/Debian/Makefile @@ -18,10 +18,11 @@ package: clean make -C ../.. check_tools tar -zxvf $(TARBALL_DIR)/$(TARBALL) cp -r debian $(UNPACKED_DIR) - chmod -R a+x $(UNPACKED_DIR)/debian + chmod a+x $(UNPACKED_DIR)/debian/rules + cp /home/hubert/work/tmp/rabbitmq-server-1.4.0.tar.gz $(UNPACKED_DIR)/rabbitmq-server-1.4.0.orig.tar.gz UNOFFICIAL_RELEASE=$(UNOFFICIAL_RELEASE) VERSION=$(VERSION) ./check-changelog.sh rabbitmq-server $(UNPACKED_DIR) - cd $(UNPACKED_DIR); GNUPGHOME=$(GNUPG_PATH)/.gnupg dpkg-buildpackage -rfakeroot $(SIGNING) - rm -rf $(UNPACKED_DIR) +# cd $(UNPACKED_DIR); GNUPGHOME=$(GNUPG_PATH)/.gnupg dpkg-buildpackage -rfakeroot $(SIGNING) +# rm -rf $(UNPACKED_DIR) clean: rm -rf $(UNPACKED_DIR) diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 64425ee7..fff02d73 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -209,7 +209,7 @@ test_log_management() -> ok = application:set_env(sasl, sasl_error_logger, false), ok = application:set_env(kernel, error_logger, silent), ok = control_action(rotate_logs, []), - [{error, enoent}, {error, enoent}] = empty_files([MainLog, SaslLog]), + [{error, enoent}, {error, enoent}] = empty_files([MainLog, SaslLog]), %% cleanup ok = application:set_env(sasl, sasl_error_logger, {file, SaslLog}), @@ -256,10 +256,16 @@ test_log_management_during_startup() -> {error, {cannot_log_to_file, _, _}} -> ok end, - %% cleanup - ok = add_log_handlers([{error_logger_file_h, MainLog}]), + %% start application with standard error_logger_file_h + %% handler not installed ok = application:set_env(kernel, error_logger, {file, MainLog}), ok = control_action(start_app, []), + ok = control_action(stop_app, []), + + %% start application with standard sasl handler not installed + %% and rabbit main log handler installed correctly + ok = delete_log_handlers([rabbit_sasl_report_file_h]), + ok = control_action(start_app, []), passed. test_cluster_management() -> -- cgit v1.2.1 From af097e64fa01ae71ef67ef12b76521430dcd63e7 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 4 Sep 2008 15:05:21 +0100 Subject: Reverted changes that accidentally got committed --- Makefile | 8 ++++---- packaging/debs/Debian/Makefile | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 4bbf227a..2ed64aa5 100644 --- a/Makefile +++ b/Makefile @@ -99,11 +99,11 @@ generic_stage: if [ -f INSTALL.in ]; then \ cp INSTALL.in $(GENERIC_STAGE_DIR)/INSTALL; \ -# elinks -dump -no-references -no-numbering $(WEB_URL)install.html \ -# >> $(GENERIC_STAGE_DIR)/INSTALL; \ + elinks -dump -no-references -no-numbering $(WEB_URL)install.html \ + >> $(GENERIC_STAGE_DIR)/INSTALL; \ cp BUILD.in $(GENERIC_STAGE_DIR)/BUILD; \ -# elinks -dump -no-references -no-numbering $(WEB_URL)build-server.html \ -# >> $(GENERIC_STAGE_DIR)/BUILD; \ + elinks -dump -no-references -no-numbering $(WEB_URL)build-server.html \ + >> $(GENERIC_STAGE_DIR)/BUILD; \ else \ cp INSTALL $(GENERIC_STAGE_DIR); \ cp BUILD $(GENERIC_STAGE_DIR); \ diff --git a/packaging/debs/Debian/Makefile b/packaging/debs/Debian/Makefile index 5e4812a3..aeb958a7 100644 --- a/packaging/debs/Debian/Makefile +++ b/packaging/debs/Debian/Makefile @@ -18,11 +18,10 @@ package: clean make -C ../.. check_tools tar -zxvf $(TARBALL_DIR)/$(TARBALL) cp -r debian $(UNPACKED_DIR) - chmod a+x $(UNPACKED_DIR)/debian/rules - cp /home/hubert/work/tmp/rabbitmq-server-1.4.0.tar.gz $(UNPACKED_DIR)/rabbitmq-server-1.4.0.orig.tar.gz + chmod -R a+x $(UNPACKED_DIR)/debian UNOFFICIAL_RELEASE=$(UNOFFICIAL_RELEASE) VERSION=$(VERSION) ./check-changelog.sh rabbitmq-server $(UNPACKED_DIR) -# cd $(UNPACKED_DIR); GNUPGHOME=$(GNUPG_PATH)/.gnupg dpkg-buildpackage -rfakeroot $(SIGNING) -# rm -rf $(UNPACKED_DIR) + cd $(UNPACKED_DIR); GNUPGHOME=$(GNUPG_PATH)/.gnupg dpkg-buildpackage -rfakeroot $(SIGNING) + rm -rf $(UNPACKED_DIR) clean: rm -rf $(UNPACKED_DIR) -- cgit v1.2.1 From 01a5436e2ff2a9a19d22558b9c2e6631dcd6aef2 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 4 Sep 2008 15:20:04 +0100 Subject: Only debian/rules file needs to have exec permission --- packaging/debs/Debian/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/debs/Debian/Makefile b/packaging/debs/Debian/Makefile index aeb958a7..dd74c31e 100644 --- a/packaging/debs/Debian/Makefile +++ b/packaging/debs/Debian/Makefile @@ -18,7 +18,7 @@ package: clean make -C ../.. check_tools tar -zxvf $(TARBALL_DIR)/$(TARBALL) cp -r debian $(UNPACKED_DIR) - chmod -R a+x $(UNPACKED_DIR)/debian + chmod a+x $(UNPACKED_DIR)/debian/rules UNOFFICIAL_RELEASE=$(UNOFFICIAL_RELEASE) VERSION=$(VERSION) ./check-changelog.sh rabbitmq-server $(UNPACKED_DIR) cd $(UNPACKED_DIR); GNUPGHOME=$(GNUPG_PATH)/.gnupg dpkg-buildpackage -rfakeroot $(SIGNING) rm -rf $(UNPACKED_DIR) -- cgit v1.2.1 From 85cb7e0861062e9fe9b65939d87d0d056d308cdf Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 4 Sep 2008 16:55:34 +0100 Subject: Removed dot --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2ed64aa5..ee7bb30d 100644 --- a/Makefile +++ b/Makefile @@ -115,7 +115,7 @@ srcdist: distclean $(MAKE) VERSION=$(VERSION) GENERIC_STAGE_DIR=dist/$(TARBALL_NAME) generic_stage mkdir -p dist/$(TARBALL_NAME)/codegen - cp -r $(AMQP_CODEGEN_DIR)/* dist/$(TARBALL_NAME)/codegen/. + cp -r $(AMQP_CODEGEN_DIR)/* dist/$(TARBALL_NAME)/codegen/ cp codegen.py Makefile dist/$(TARBALL_NAME) cp -r scripts dist/$(TARBALL_NAME) -- cgit v1.2.1 From f46e39fce6066a60d22dc91fed47a251cd3db7a1 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 4 Sep 2008 17:30:04 +0100 Subject: Added python-json as a dependency to the debian/rpm packages --- packaging/RPMS/Fedora/rabbitmq-server.spec | 1 + packaging/debs/Debian/debian/control | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec index 25213816..d29b2db8 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.spec +++ b/packaging/RPMS/Fedora/rabbitmq-server.spec @@ -8,6 +8,7 @@ Group: Development/Libraries Source: http://www.rabbitmq.com/releases/%{source_name}-%{main_version}.tar.gz URL: http://www.rabbitmq.com/ Vendor: LShift Ltd., Cohesive Financial Technologies LLC., Rabbit Technlogies Ltd. +BuildRequires: python, python-json Requires: erlang Packager: Hubert Plociniczak BuildRoot: %{_tmppath}/%{name}-%{main_version}-%{release}-root diff --git a/packaging/debs/Debian/debian/control b/packaging/debs/Debian/debian/control index df9a330b..abc6a658 100644 --- a/packaging/debs/Debian/debian/control +++ b/packaging/debs/Debian/debian/control @@ -2,7 +2,7 @@ Source: rabbitmq-server Section: net Priority: extra Maintainer: Tony Garnock-Jones -Build-Depends: cdbs, debhelper (>= 5), erlang-base | erlang-base-hipe, erlang-nox, erlang-dev, erlang-src, make, python +Build-Depends: cdbs, debhelper (>= 5), erlang-base | erlang-base-hipe, erlang-nox, erlang-dev, erlang-src, make, python, python-json Standards-Version: 3.7.2 Package: rabbitmq-server -- cgit v1.2.1 From ae317d9c2a90f5c78d8463e396c4dc06b48161eb Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 5 Sep 2008 12:34:07 +0100 Subject: Create non-native debian packages --- packaging/debs/Debian/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packaging/debs/Debian/Makefile b/packaging/debs/Debian/Makefile index dd74c31e..3e74cb52 100644 --- a/packaging/debs/Debian/Makefile +++ b/packaging/debs/Debian/Makefile @@ -1,5 +1,6 @@ TARBALL_DIR=../../../dist TARBALL=$(shell (cd $(TARBALL_DIR); echo rabbitmq-server-[0-9]*.tar.gz)) +DEBIAN_ORIG_TARBALL=$(shell echo $(TARBALL) | sed -e 's:\(.*\)-\(.*\)\(\.tar\.gz\):\1_\2\.orig\3:g') VERSION=$(shell echo $(TARBALL) | sed -e 's:rabbitmq-server-\(.*\)\.tar\.gz:\1:g') UNPACKED_DIR=rabbitmq-server-$(VERSION) PACKAGENAME=rabbitmq-server @@ -16,7 +17,8 @@ all: package: clean make -C ../.. check_tools - tar -zxvf $(TARBALL_DIR)/$(TARBALL) + cp $(TARBALL_DIR)/$(TARBALL) $(DEBIAN_ORIG_TARBALL) + tar -zxvf $(DEBIAN_ORIG_TARBALL) cp -r debian $(UNPACKED_DIR) chmod a+x $(UNPACKED_DIR)/debian/rules UNOFFICIAL_RELEASE=$(UNOFFICIAL_RELEASE) VERSION=$(VERSION) ./check-changelog.sh rabbitmq-server $(UNPACKED_DIR) -- cgit v1.2.1 From 06a8be7b93aa617cf927a7c356913721a003971b Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 5 Sep 2008 16:41:42 +0100 Subject: Removed catch in append_file/2 since there is nothing to catch. --- src/rabbit.erl | 2 +- src/rabbit_misc.erl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index 4cb11f4f..c6ef1749 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -149,7 +149,7 @@ start(normal, []) -> apply(M, F, A), io:format("done~n") end, - [{"database", + [{"database", fun () -> ok = rabbit_mnesia:init() end}, {"core processes", fun () -> diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index db6da45c..3e4ed8f3 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -339,7 +339,7 @@ dirty_dump_log1(LH, {K, Terms, BadBytes}) -> append_file(File, Suffix) -> - case catch file:read_file_info(File) of + case file:read_file_info(File) of {ok, FInfo} -> append_file(File, FInfo#file_info.size, Suffix); {error, enoent} -> append_file(File, 0, Suffix); Error -> Error -- cgit v1.2.1 From a8c009ddc7e3abbf2aeb4a2b77cd1472638132f1 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 9 Sep 2008 11:45:26 +0100 Subject: Updated the license to reflect the current state. Debian packaging has the same license as the broker itself. --- packaging/debs/Debian/debian/copyright | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packaging/debs/Debian/debian/copyright b/packaging/debs/Debian/debian/copyright index e16996e5..9f9f8672 100644 --- a/packaging/debs/Debian/debian/copyright +++ b/packaging/debs/Debian/debian/copyright @@ -5,7 +5,7 @@ It was downloaded from http://www.rabbitmq.com/ Upstream Author: The RabbitMQ team -Copyright: 2006-2008 LShift Ltd. +Copyright: 2006-2008 Rabbit Technologies Ltd. License: The RabbitMQ server is licensed under the MPL. @@ -485,7 +485,7 @@ EXHIBIT A -Mozilla Public License. If you have any questions regarding licensing, please contact us at info@rabbitmq.com. -The Debian packaging is (C) 2007, Tony Garnock-Jones and -is licensed under the GPL, see `/usr/share/common-licenses/GPL'. +The Debian packaging is (C) 2007-2008, Rabbit Technologies Ltd. +and is licensed under the MPL 1.1, see above. -- cgit v1.2.1 From 579778ee3cc8ffbae8f6e13c2aeeeb104a5d12a0 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 9 Sep 2008 12:48:35 +0100 Subject: Renamed startup.log, .err to startup_log, _err to avoid logrotation problems. This also removes the problem when the node is called startup. Same situation for shutdown logs. --- packaging/RPMS/Fedora/init.d | 10 +++++----- packaging/debs/Debian/debian/init.d | 15 ++++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packaging/RPMS/Fedora/init.d b/packaging/RPMS/Fedora/init.d index dc0c2698..a79765cc 100644 --- a/packaging/RPMS/Fedora/init.d +++ b/packaging/RPMS/Fedora/init.d @@ -43,16 +43,16 @@ cd / start_rabbitmq () { set +e - su $USER -s /bin/sh -c "$DAEMON start_all ${NODE_COUNT}" > /var/log/rabbitmq/startup.log 2> /var/log/rabbitmq/startup.err + su $USER -s /bin/sh -c "$DAEMON start_all ${NODE_COUNT}" > /var/log/rabbitmq/startup_log 2> /var/log/rabbitmq/startup_err case "$?" in 0) echo SUCCESS && touch $LOCK_FILE ;; 1) - echo TIMEOUT - check /var/log/rabbitmq/startup.\{log,err\} + echo TIMEOUT - check /var/log/rabbitmq/startup_\{log,err\} ;; *) - echo FAILED - check /var/log/rabbitmq/startup.log, .err + echo FAILED - check /var/log/rabbitmq/startup_log, _err RETVAL=1;; esac set -e @@ -60,10 +60,10 @@ start_rabbitmq () { stop_rabbitmq () { set +e - su $USER -s /bin/sh -c "$DAEMON stop_all" > /var/log/rabbitmq/shutdown.log 2> /var/log/rabbitmq/shutdown.err + su $USER -s /bin/sh -c "$DAEMON stop_all" > /var/log/rabbitmq/shutdown_log 2> /var/log/rabbitmq/shutdown_err if [ $? != 0 ] ; then - echo FAILED - check /var/log/rabbitmq/shutdown.log, .err + echo FAILED - check /var/log/rabbitmq/shutdown_log, _err RETVAL=$? else rm -rf $LOCK_FILE diff --git a/packaging/debs/Debian/debian/init.d b/packaging/debs/Debian/debian/init.d index c3c180a8..7c192c51 100644 --- a/packaging/debs/Debian/debian/init.d +++ b/packaging/debs/Debian/debian/init.d @@ -24,19 +24,20 @@ if [ -f /etc/default/rabbitmq ] ; then . /etc/default/rabbitmq fi +RETVAL=0 set -e cd / start_rabbitmq () { set +e - su $USER -s /bin/sh -c "$DAEMON start_all ${NODE_COUNT}" > /var/log/rabbitmq/startup.log 2> /var/log/rabbitmq/startup.err + su $USER -s /bin/sh -c "$DAEMON start_all ${NODE_COUNT}" > /var/log/rabbitmq/startup_log 2> /var/log/rabbitmq/startup_err case "$?" in 0) echo SUCCESS;; 1) - echo TIMEOUT - check /var/log/rabbitmq/startup.\{log,err\};; + echo TIMEOUT - check /var/log/rabbitmq/startup_\{log,err\};; *) - echo FAILED - check /var/log/rabbitmq/startup.log, .err + echo FAILED - check /var/log/rabbitmq/startup_log, _err exit 1;; esac set -e @@ -44,9 +45,9 @@ start_rabbitmq () { stop_rabbitmq () { set +e - su $USER -s /bin/sh -c "$DAEMON stop_all" > /var/log/rabbitmq/shutdown.log 2> /var/log/rabbitmq/shutdown.err + su $USER -s /bin/sh -c "$DAEMON stop_all" > /var/log/rabbitmq/shutdown_log 2> /var/log/rabbitmq/shutdown_err if [ $? != 0 ] ; then - echo FAILED - check /var/log/rabbitmq/shutdown.log, .err + echo FAILED - check /var/log/rabbitmq/shutdown_log, _err exit 0 fi set -e @@ -83,8 +84,8 @@ case "$1" in ;; *) echo "Usage: $0 {start|stop|rotate-logs|restart|force-reload}" >&2 - exit 1 + RETVAL=1 ;; esac -exit 0 +exit RETVAL -- cgit v1.2.1 From 3fd8dc51c47715ef167a1e9c39fafac53b393311 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 9 Sep 2008 13:33:00 +0100 Subject: Return value of the RETVAL variable in init.d --- packaging/debs/Debian/debian/init.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/debs/Debian/debian/init.d b/packaging/debs/Debian/debian/init.d index 7c192c51..278d76f0 100644 --- a/packaging/debs/Debian/debian/init.d +++ b/packaging/debs/Debian/debian/init.d @@ -88,4 +88,4 @@ case "$1" in ;; esac -exit RETVAL +exit $RETVAL -- cgit v1.2.1 From cee9b87eed4228d2e9d54b7eb40c5eaf2fc4b327 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 9 Sep 2008 16:15:09 +0100 Subject: Fixed various QA remarks. Renamed rotate_logs_all to rotate_logs. logrotate will fail silently to logrotate if calling rotate_logs on any of the logs failed. --- docs/rabbitmq-multi.pod | 4 ++-- packaging/RPMS/Fedora/init.d | 3 +-- packaging/debs/Debian/debian/init.d | 3 +-- src/rabbit_multi.erl | 15 ++++++++------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/docs/rabbitmq-multi.pod b/docs/rabbitmq-multi.pod index 772ca70a..7916fc78 100644 --- a/docs/rabbitmq-multi.pod +++ b/docs/rabbitmq-multi.pod @@ -26,8 +26,8 @@ start_all I stop_all stop all local RabbitMQ nodes -rotate_logs_all - rotate log files for all local RabbitMQ nodes +rotate_logs + rotate log files for all local and running RabbitMQ nodes =head1 EXAMPLES diff --git a/packaging/RPMS/Fedora/init.d b/packaging/RPMS/Fedora/init.d index a79765cc..d699f9b6 100644 --- a/packaging/RPMS/Fedora/init.d +++ b/packaging/RPMS/Fedora/init.d @@ -85,8 +85,7 @@ restart_rabbitmq () { rotate_logs_rabbitmq() { set +e - su $USER -s /bin/sh -c "$DAEMON rotate_logs_all ${ROTATE_SUFFIX}" 2>&1 - RETVAL=$? + su $USER -s /bin/sh -c "$DAEMON rotate_logs ${ROTATE_SUFFIX}" 2>&1 set -e } diff --git a/packaging/debs/Debian/debian/init.d b/packaging/debs/Debian/debian/init.d index 278d76f0..da9d70f2 100644 --- a/packaging/debs/Debian/debian/init.d +++ b/packaging/debs/Debian/debian/init.d @@ -55,8 +55,7 @@ stop_rabbitmq () { rotate_logs_rabbitmq() { set +e - su $USER -s /bin/sh -c "$DAEMON rotate_logs_all ${ROTATE_SUFFIX}" 2>&1 - RETVAL=$? + su $USER -s /bin/sh -c "$DAEMON rotate_logs ${ROTATE_SUFFIX}" 2>&1 set -e } diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl index 29f12ff7..4d00e660 100644 --- a/src/rabbit_multi.erl +++ b/src/rabbit_multi.erl @@ -94,10 +94,10 @@ action(stop_all, [], RpcTimeout) -> stop_nodes(NodePids, RpcTimeout), delete_pids_file() end); -action(rotate_logs_all, [], RpcTimeout) -> - action(rotate_logs_all, [""], RpcTimeout); +action(rotate_logs, [], RpcTimeout) -> + action(rotate_logs, [""], RpcTimeout); -action(rotate_logs_all, [Suffix], RpcTimeout) -> +action(rotate_logs, [Suffix], RpcTimeout) -> io:format("Rotating logs for all nodes...~n", []), call_all_nodes(fun(NodePids) -> rotate_logs(NodePids, @@ -283,11 +283,12 @@ is_dead(Pid) -> rotate_logs([], _, _) -> ok; rotate_logs([{Node, _} | Rest], BinarySuffix, RpcTimeout) -> - io:format("Rotating logs for node ~p~n", [Node]), + io:format("Rotating logs for node ~p", [Node]), case rpc:call(Node, rabbit, rotate_logs, [BinarySuffix], RpcTimeout) of - {badrpc, _} -> io:format("timeout"), - throw(rotate_logs_failed); - ok -> rotate_logs(Rest, BinarySuffix, RpcTimeout) + {badrpc, Error} -> io:format(": ~p.~n", [Error]), + throw(rotate_logs_failed); + ok -> io:format(": ok.~n", []), + rotate_logs(Rest, BinarySuffix, RpcTimeout) end. call_all_nodes(Func) -> -- cgit v1.2.1 From 0ba5c5bcdef606fca67d4fe9f529b402895bff2a Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 9 Sep 2008 16:45:04 +0100 Subject: Start the RabbitMQ server after adding it to chkconfig. --- packaging/RPMS/Fedora/rabbitmq-server.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec index d1a70e88..5bb71bfa 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.spec +++ b/packaging/RPMS/Fedora/rabbitmq-server.spec @@ -76,6 +76,7 @@ chown -R rabbitmq:rabbitmq /var/lib/rabbitmq chown -R rabbitmq:rabbitmq /var/log/rabbitmq /sbin/chkconfig --add %{name} +/sbin/service rabbitmq-server start %preun if [ $1 = 0 ]; then -- cgit v1.2.1 From 4d4a9a044f7bb013efed85b070ec755f8a854fd1 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 9 Sep 2008 17:05:01 +0100 Subject: Continue rotate_logs command even when the command on specific node returns an error. Display the error message in that case only. --- src/rabbit_multi.erl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl index 4d00e660..8a6bfbe0 100644 --- a/src/rabbit_multi.erl +++ b/src/rabbit_multi.erl @@ -285,11 +285,10 @@ rotate_logs([], _, _) -> ok; rotate_logs([{Node, _} | Rest], BinarySuffix, RpcTimeout) -> io:format("Rotating logs for node ~p", [Node]), case rpc:call(Node, rabbit, rotate_logs, [BinarySuffix], RpcTimeout) of - {badrpc, Error} -> io:format(": ~p.~n", [Error]), - throw(rotate_logs_failed); - ok -> io:format(": ok.~n", []), - rotate_logs(Rest, BinarySuffix, RpcTimeout) - end. + {badrpc, Error} -> io:format(": ~p.~n", [Error]); + ok -> io:format(": ok.~n", []) + end, + rotate_logs(Rest, BinarySuffix, RpcTimeout). call_all_nodes(Func) -> case read_pids_file() of -- cgit v1.2.1 From c3a66f9ea0d91556fa10af3c2cd34de97eedb53d Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 10 Sep 2008 10:53:55 +0100 Subject: Use lists:foreach instead of tail recursion in rotate_logs command. Updated usage function() Reverted change in rabbitmq-server.spec that didn't belong to this bug. --- packaging/RPMS/Fedora/rabbitmq-server.spec | 2 +- src/rabbit_multi.erl | 31 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec index 4e39012c..765ccf9b 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.spec +++ b/packaging/RPMS/Fedora/rabbitmq-server.spec @@ -83,7 +83,7 @@ chown -R rabbitmq:rabbitmq /var/log/rabbitmq %preun if [ $1 = 0 ]; then #Complete uninstall - /sbin/service rabbitmq-server stop > /dev/null 2>&1 + /sbin/service rabbitmq-server stop /sbin/chkconfig --del rabbitmq-server # We do not remove /var/log and /var/lib directories diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl index 8a6bfbe0..bf1d2d99 100644 --- a/src/rabbit_multi.erl +++ b/src/rabbit_multi.erl @@ -69,9 +69,9 @@ usage() -> Available commands: - start_all - start a local cluster of RabbitMQ nodes. - stop_all - stops all local RabbitMQ nodes. - rotate_logs_all [Suffix] - rotate logs for all local RabbitMQ nodes. + start_all - start a local cluster of RabbitMQ nodes. + stop_all - stops all local RabbitMQ nodes. + rotate_logs [Suffix] - rotate logs for all local and running RabbitMQ nodes. "), halt(3). @@ -99,10 +99,18 @@ action(rotate_logs, [], RpcTimeout) -> action(rotate_logs, [Suffix], RpcTimeout) -> io:format("Rotating logs for all nodes...~n", []), - call_all_nodes(fun(NodePids) -> - rotate_logs(NodePids, - list_to_binary(Suffix), - RpcTimeout) end). + BinarySuffix = list_to_binary(Suffix), + call_all_nodes( + fun(NodePids) -> + lists:foreach(fun ({Node, _}) -> + io:format("Rotating logs for node ~p", [Node]), + case rpc:call(Node, rabbit, rotate_logs, + [BinarySuffix], RpcTimeout) of + {badrpc, Error} -> io:format(": ~p.~n", [Error]); + ok -> io:format(": ok.~n", []) + end + end, NodePids) + end). %% PNodePid is the list of PIDs %% Running is a boolean exhibiting success at some moment @@ -281,15 +289,6 @@ is_dead(Pid) -> end end}]). -rotate_logs([], _, _) -> ok; -rotate_logs([{Node, _} | Rest], BinarySuffix, RpcTimeout) -> - io:format("Rotating logs for node ~p", [Node]), - case rpc:call(Node, rabbit, rotate_logs, [BinarySuffix], RpcTimeout) of - {badrpc, Error} -> io:format(": ~p.~n", [Error]); - ok -> io:format(": ok.~n", []) - end, - rotate_logs(Rest, BinarySuffix, RpcTimeout). - call_all_nodes(Func) -> case read_pids_file() of [] -> throw(no_nodes_running); -- cgit v1.2.1 From f389cf21e9a5bc101f905f1f5623c7205aa906e0 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 10 Sep 2008 11:39:19 +0100 Subject: Refactoring of call_all_nodes/1 --- src/rabbit_multi.erl | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl index bf1d2d99..2b117717 100644 --- a/src/rabbit_multi.erl +++ b/src/rabbit_multi.erl @@ -90,9 +90,16 @@ action(start_all, [NodeCount], RpcTimeout) -> action(stop_all, [], RpcTimeout) -> io:format("Stopping all nodes...~n", []), - call_all_nodes(fun(NodePids) -> - stop_nodes(NodePids, RpcTimeout), - delete_pids_file() end); + call_all_nodes(fun({Node, Pid}) -> + io:format("Stopping node ~p~n", [Node]), + rpc:call(Node, rabbit, stop_and_halt, []), + case kill_wait(Pid, RpcTimeout, false) of + false -> kill_wait(Pid, RpcTimeout, true); + true -> ok + end, + io:format("OK~n", []) + end), + delete_pids_file(); action(rotate_logs, [], RpcTimeout) -> action(rotate_logs, [""], RpcTimeout); @@ -101,15 +108,13 @@ action(rotate_logs, [Suffix], RpcTimeout) -> io:format("Rotating logs for all nodes...~n", []), BinarySuffix = list_to_binary(Suffix), call_all_nodes( - fun(NodePids) -> - lists:foreach(fun ({Node, _}) -> - io:format("Rotating logs for node ~p", [Node]), - case rpc:call(Node, rabbit, rotate_logs, - [BinarySuffix], RpcTimeout) of - {badrpc, Error} -> io:format(": ~p.~n", [Error]); - ok -> io:format(": ok.~n", []) - end - end, NodePids) + fun ({Node, _}) -> + io:format("Rotating logs for node ~p", [Node]), + case rpc:call(Node, rabbit, rotate_logs, + [BinarySuffix], RpcTimeout) of + {badrpc, Error} -> io:format(": ~p.~n", [Error]); + ok -> io:format(": ok.~n", []) + end end). %% PNodePid is the list of PIDs @@ -239,21 +244,6 @@ read_pids_file() -> FileName, Reason}}) end. -stop_nodes([],_) -> ok; - -stop_nodes([NodePid | Rest], RpcTimeout) -> - stop_node(NodePid, RpcTimeout), - stop_nodes(Rest, RpcTimeout). - -stop_node({Node, Pid}, RpcTimeout) -> - io:format("Stopping node ~p~n", [Node]), - rpc:call(Node, rabbit, stop_and_halt, []), - case kill_wait(Pid, RpcTimeout, false) of - false -> kill_wait(Pid, RpcTimeout, true); - true -> ok - end, - io:format("OK~n", []). - kill_wait(Pid, TimeLeft, Forceful) when TimeLeft < 0 -> Cmd = with_os([{unix, fun () -> if Forceful -> "kill -9"; true -> "kill" @@ -292,7 +282,7 @@ is_dead(Pid) -> call_all_nodes(Func) -> case read_pids_file() of [] -> throw(no_nodes_running); - NodePids -> Func(NodePids) + NodePids -> lists:foreach(Func, NodePids) end. getenv(Var) -> -- cgit v1.2.1 From 3a7ab39ddeea3cc9f2bc9f3d1bfdb79387f88e24 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 11 Sep 2008 14:10:14 +0100 Subject: Added status command to rabbit_mutli, init.d scripts now use that command. Used status command in init.d scripts to check if the server is running before stopping it. Fixed various indentation problems in init.d scripts. Synchronized the init.d in Debian and RPM to behave in a similar way. --- docs/rabbitmq-multi.pod | 3 + packaging/RPMS/Fedora/init.d | 99 +++++++++++++++++++-------------- packaging/debs/Debian/debian/init.d | 108 +++++++++++++++++++++++------------- src/rabbit_multi.erl | 12 ++++ 4 files changed, 141 insertions(+), 81 deletions(-) diff --git a/docs/rabbitmq-multi.pod b/docs/rabbitmq-multi.pod index 7916fc78..65d05833 100644 --- a/docs/rabbitmq-multi.pod +++ b/docs/rabbitmq-multi.pod @@ -23,6 +23,9 @@ start_all I start count nodes with unique names, listening on all IP addresses and on sequential ports starting from 5672. +status + print the status of all running RabbitMQ nodes + stop_all stop all local RabbitMQ nodes diff --git a/packaging/RPMS/Fedora/init.d b/packaging/RPMS/Fedora/init.d index d699f9b6..397beeaa 100644 --- a/packaging/RPMS/Fedora/init.d +++ b/packaging/RPMS/Fedora/init.d @@ -47,40 +47,49 @@ start_rabbitmq () { case "$?" in 0) echo SUCCESS && touch $LOCK_FILE + RETVAL=0 ;; 1) echo TIMEOUT - check /var/log/rabbitmq/startup_\{log,err\} + RETVAL=1 ;; *) echo FAILED - check /var/log/rabbitmq/startup_log, _err - RETVAL=1;; + RETVAL=1 + ;; esac set -e } stop_rabbitmq () { set +e - su $USER -s /bin/sh -c "$DAEMON stop_all" > /var/log/rabbitmq/shutdown_log 2> /var/log/rabbitmq/shutdown_err - - if [ $? != 0 ] ; then - echo FAILED - check /var/log/rabbitmq/shutdown_log, _err + status_rabbitmq quiet + if [ $RETVAL == 0 ] ; then + su $USER -s /bin/sh -c "$DAEMON stop_all" > /var/log/rabbitmq/shutdown_log 2> /var/log/rabbitmq/shutdown_err RETVAL=$? + if [ $RETVAL != 0 ] ; then + echo FAILED - check /var/log/rabbitmq/shutdown_log, _err + else + rm -rf $LOCK_FILE + fi else - rm -rf $LOCK_FILE + echo No nodes running RETVAL=0 fi set -e } -status_rabbitmq () { - status $NAME -} - -restart_rabbitmq () { - echo -n "Restarting $DESC: " - stop_rabbitmq - start_rabbitmq - echo "$NAME." +status_rabbitmq() { + set +e + if [ "$1" != "quiet" ] ; then + su $USER -s /bin/sh -c "$DAEMON status" 2>&1 + else + su $USER -s /bin/sh -c "$DAEMON status" > /dev/null 2>&1 + fi + if [ $? != 0 ] ; then + RETVAL=1 + fi + set -e } rotate_logs_rabbitmq() { @@ -89,37 +98,43 @@ rotate_logs_rabbitmq() { set -e } +restart_rabbitmq() { + stop_rabbitmq + start_rabbitmq +} + case "$1" in - start) - echo -n "Starting $DESC: " - start_rabbitmq - echo "$NAME." - ;; - stop) - echo -n "Stopping $DESC: " - stop_rabbitmq - echo "$NAME." - ;; - rotate-logs) - echo -n "Rotating log files for $DESC: " - rotate_logs_rabbitmq - ;; - force-reload|reload|restart) + start) + echo -n "Starting $DESC: " + start_rabbitmq + echo "$NAME." + ;; + stop) + echo -n "Stopping $DESC: " + stop_rabbitmq + echo "$NAME." + ;; + status) + status_rabbitmq + ;; + rotate-logs) + echo -n "Rotating log files for $DESC: " + rotate_logs_rabbitmq + ;; + force-reload|reload|restart) + echo -n "Restarting $DESC: " restart_rabbitmq - ;; - status) - echo "Status of $DESC: " - status_rabbitmq - RETVAL=$? - ;; - condrestart|try-restart) - status_rabbitmq >/dev/null 2>&1 || exit 0 + echo "$NAME." + ;; + condrestart|try-restart) + echo -n "Restarting $DESC: " restart_rabbitmq + echo "$NAME." + ;; + *) + echo "Usage: $0 {start|stop|status|rotate-logs|restart|condrestart|try-restart|reload|force-reload}" >&2 + RETVAL=1 ;; - *) - echo "Usage: $0 {start|stop|rotate-logs|status|restart|condrestart|try-restart|reload|force-reload}" >&2 - RETVAL=1 - ;; esac exit $RETVAL diff --git a/packaging/debs/Debian/debian/init.d b/packaging/debs/Debian/debian/init.d index da9d70f2..a93f3066 100644 --- a/packaging/debs/Debian/debian/init.d +++ b/packaging/debs/Debian/debian/init.d @@ -29,26 +29,50 @@ set -e cd / start_rabbitmq () { - set +e - su $USER -s /bin/sh -c "$DAEMON start_all ${NODE_COUNT}" > /var/log/rabbitmq/startup_log 2> /var/log/rabbitmq/startup_err - case "$?" in - 0) - echo SUCCESS;; - 1) - echo TIMEOUT - check /var/log/rabbitmq/startup_\{log,err\};; - *) - echo FAILED - check /var/log/rabbitmq/startup_log, _err - exit 1;; - esac - set -e + set +e + su $USER -s /bin/sh -c "$DAEMON start_all ${NODE_COUNT}" > /var/log/rabbitmq/startup_log 2> /var/log/rabbitmq/startup_err + case "$?" in + 0) + echo SUCCESS + RETVAL=0 + ;; + 1) + echo TIMEOUT - check /var/log/rabbitmq/startup_\{log,err\} + RETVAL=1 + ;; + *) + echo FAILED - check /var/log/rabbitmq/startup_log, _err + RETVAL=1 + ;; + esac + set -e } stop_rabbitmq () { set +e - su $USER -s /bin/sh -c "$DAEMON stop_all" > /var/log/rabbitmq/shutdown_log 2> /var/log/rabbitmq/shutdown_err + status_rabbitmq quiet + if [ $RETVAL == 0 ] ; then + su $USER -s /bin/sh -c "$DAEMON stop_all" > /var/log/rabbitmq/shutdown_log 2> /var/log/rabbitmq/shutdown_err + RETVAL=$? + if [ $RETVAL != 0 ] ; then + echo FAILED - check /var/log/rabbitmq/shutdown_log, _err + fi + else + echo No nodes running + RETVAL=0 + fi + set -e +} + +status_rabbitmq() { + set +e + if [ "$1" != "quiet" ] ; then + su $USER -s /bin/sh -c "$DAEMON status" 2>&1 + else + su $USER -s /bin/sh -c "$DAEMON status" > /dev/null 2>&1 + fi if [ $? != 0 ] ; then - echo FAILED - check /var/log/rabbitmq/shutdown_log, _err - exit 0 + RETVAL=1 fi set -e } @@ -57,34 +81,40 @@ rotate_logs_rabbitmq() { set +e su $USER -s /bin/sh -c "$DAEMON rotate_logs ${ROTATE_SUFFIX}" 2>&1 set -e +} +restart_rabbitmq() { + stop_rabbitmq + start_rabbitmq } case "$1" in - start) - echo -n "Starting $DESC: " - start_rabbitmq - echo "$NAME." - ;; - stop) - echo -n "Stopping $DESC: " - stop_rabbitmq - echo "$NAME." - ;; - rotate-logs) - echo -n "Rotating log files for $DESC: " - rotate_logs_rabbitmq - ;; - force-reload|restart) - echo -n "Restarting $DESC: " - stop_rabbitmq - start_rabbitmq - echo "$NAME." - ;; - *) - echo "Usage: $0 {start|stop|rotate-logs|restart|force-reload}" >&2 - RETVAL=1 - ;; + start) + echo -n "Starting $DESC: " + start_rabbitmq + echo "$NAME." + ;; + stop) + echo -n "Stopping $DESC: " + stop_rabbitmq + echo "$NAME." + ;; + status) + status_rabbitmq + ;; + rotate-logs) + echo -n "Rotating log files for $DESC: " + rotate_logs_rabbitmq + ;; + force-reload|restart) + echo -n "Restarting $DESC: " + restart_rabbitmq + echo "$NAME." + ;; + *) + echo "Usage: $0 {start|stop|status|rotate-logs|restart|force-reload}" >&2 + RETVAL=1 + ;; esac exit $RETVAL diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl index 2b117717..9373e8cb 100644 --- a/src/rabbit_multi.erl +++ b/src/rabbit_multi.erl @@ -70,6 +70,7 @@ usage() -> Available commands: start_all - start a local cluster of RabbitMQ nodes. + status - print status of all running nodes stop_all - stops all local RabbitMQ nodes. rotate_logs [Suffix] - rotate logs for all local and running RabbitMQ nodes. "), @@ -88,6 +89,17 @@ action(start_all, [NodeCount], RpcTimeout) -> false -> timeout end; +action(status, [], RpcTimeout) -> + io:format("Status of all running nodes...~n", []), + call_all_nodes( + fun({Node, Pid}) -> + io:format("Node '~p' with Pid ~p: ", [Node, Pid]), + case rpc:call(Node, rabbit, status, [], RpcTimeout) of + {badrpc, Error} -> io:format("~p~n", [Error]); + [{running_applications, Apps} | _] -> io:format("~p~n", [Apps]) + end + end); + action(stop_all, [], RpcTimeout) -> io:format("Stopping all nodes...~n", []), call_all_nodes(fun({Node, Pid}) -> -- cgit v1.2.1 From 03715ed3ca7374af437b277815e6a1953e90233d Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 11 Sep 2008 17:33:43 +0100 Subject: Use parse_status to correctly determine the status of the node. No need to print node's apps. --- src/rabbit_multi.erl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl index 9373e8cb..2ff59dc8 100644 --- a/src/rabbit_multi.erl +++ b/src/rabbit_multi.erl @@ -94,9 +94,10 @@ action(status, [], RpcTimeout) -> call_all_nodes( fun({Node, Pid}) -> io:format("Node '~p' with Pid ~p: ", [Node, Pid]), - case rpc:call(Node, rabbit, status, [], RpcTimeout) of - {badrpc, Error} -> io:format("~p~n", [Error]); - [{running_applications, Apps} | _] -> io:format("~p~n", [Apps]) + case parse_status( + rpc:call(Node, rabbit, status, [], RpcTimeout)) of + false -> io:format("~p~n", ["not running"]); + true -> io:format("~p~n", ["running"]) end end); -- cgit v1.2.1 From ef4d1c3083322f1334be0aac150981922de93714 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 11 Sep 2008 17:52:23 +0100 Subject: cosmetic --- src/rabbit_multi.erl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl index 2ff59dc8..15349a60 100644 --- a/src/rabbit_multi.erl +++ b/src/rabbit_multi.erl @@ -93,12 +93,14 @@ action(status, [], RpcTimeout) -> io:format("Status of all running nodes...~n", []), call_all_nodes( fun({Node, Pid}) -> - io:format("Node '~p' with Pid ~p: ", [Node, Pid]), - case parse_status( - rpc:call(Node, rabbit, status, [], RpcTimeout)) of - false -> io:format("~p~n", ["not running"]); - true -> io:format("~p~n", ["running"]) - end + io:format("Node '~p' with Pid ~p: ~p~n", + [Node, Pid, + case parse_status( + rpc:call( + Node, rabbit, status, [], RpcTimeout)) of + false -> not_running; + true -> running + end]) end); action(stop_all, [], RpcTimeout) -> -- cgit v1.2.1 From c426de7aee243cc40983ea5e6dd515216e5b6651 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 11 Sep 2008 17:52:22 +0100 Subject: cosmetic --- src/rabbit_multi.erl | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/rabbit_multi.erl b/src/rabbit_multi.erl index 15349a60..c6a7e920 100644 --- a/src/rabbit_multi.erl +++ b/src/rabbit_multi.erl @@ -93,14 +93,12 @@ action(status, [], RpcTimeout) -> io:format("Status of all running nodes...~n", []), call_all_nodes( fun({Node, Pid}) -> + Status = rpc:call(Node, rabbit, status, [], RpcTimeout), io:format("Node '~p' with Pid ~p: ~p~n", - [Node, Pid, - case parse_status( - rpc:call( - Node, rabbit, status, [], RpcTimeout)) of - false -> not_running; - true -> running - end]) + [Node, Pid, case parse_status(Status) of + false -> not_running; + true -> running + end]) end); action(stop_all, [], RpcTimeout) -> -- cgit v1.2.1 From 26586179ac092aadcf0366b82c6578118fd6d001 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Mon, 15 Sep 2008 09:55:28 +0100 Subject: Fixed checking build dependencies in rpms while building on Debian systems. Unfortunately .spec doesn't have 'not' logic. --- packaging/RPMS/Fedora/Makefile | 2 +- packaging/RPMS/Fedora/rabbitmq-server.spec | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packaging/RPMS/Fedora/Makefile b/packaging/RPMS/Fedora/Makefile index c8e979a7..521fac43 100644 --- a/packaging/RPMS/Fedora/Makefile +++ b/packaging/RPMS/Fedora/Makefile @@ -5,7 +5,7 @@ SOURCE_TARBALL_DIR=../../../dist TARBALL=$(SOURCE_TARBALL_DIR)/rabbitmq-server-$(VERSION).tar.gz TOP_DIR=$(shell pwd) RPM_VERSION=$(shell echo $(VERSION) | tr - _) -DEFINES=--define '_topdir $(TOP_DIR)' --define '_tmppath $(TOP_DIR)/tmp' --define 'main_version $(VERSION)' --define 'rpm_version $(RPM_VERSION)' +DEFINES=--define '_topdir $(TOP_DIR)' --define '_tmppath $(TOP_DIR)/tmp' --define 'main_version $(VERSION)' --define 'rpm_version $(RPM_VERSION)' --define 'debian 1' rpms: clean server diff --git a/packaging/RPMS/Fedora/rabbitmq-server.spec b/packaging/RPMS/Fedora/rabbitmq-server.spec index d29b2db8..6a57babd 100644 --- a/packaging/RPMS/Fedora/rabbitmq-server.spec +++ b/packaging/RPMS/Fedora/rabbitmq-server.spec @@ -8,7 +8,10 @@ Group: Development/Libraries Source: http://www.rabbitmq.com/releases/%{source_name}-%{main_version}.tar.gz URL: http://www.rabbitmq.com/ Vendor: LShift Ltd., Cohesive Financial Technologies LLC., Rabbit Technlogies Ltd. +%if 0%{?debian} +%else BuildRequires: python, python-json +%endif Requires: erlang Packager: Hubert Plociniczak BuildRoot: %{_tmppath}/%{name}-%{main_version}-%{release}-root -- cgit v1.2.1 From e397b876eb9615a9cf3a7633b3bf2efaa20a8f04 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sun, 28 Sep 2008 11:37:28 +0100 Subject: disable Nagle --- scripts/rabbitmq-server | 5 ++++- scripts/rabbitmq-server.bat | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/rabbitmq-server b/scripts/rabbitmq-server index 80289d8e..b930c8ed 100755 --- a/scripts/rabbitmq-server +++ b/scripts/rabbitmq-server @@ -28,7 +28,10 @@ [ "x" = "x$NODE_IP_ADDRESS" ] && NODE_IP_ADDRESS=0.0.0.0 [ "x" = "x$NODE_PORT" ] && NODE_PORT=5672 -ERL_ARGS="+K true +A30 -kernel inet_default_listen_options [{sndbuf,16384},{recbuf,4096}]" +ERL_ARGS="+K true +A30 \ +-kernel inet_default_listen_options [{nodelay,true},{sndbuf,16384},{recbuf,4096}] \ +-kernel inet_default_connect_options [{nodelay,true}]" + CLUSTER_CONFIG_FILE=/etc/default/rabbitmq_cluster.config [ "x" = "x$LOG_BASE" ] && LOG_BASE=/var/log/rabbitmq diff --git a/scripts/rabbitmq-server.bat b/scripts/rabbitmq-server.bat index 42c09fac..f08027d2 100644 --- a/scripts/rabbitmq-server.bat +++ b/scripts/rabbitmq-server.bat @@ -99,7 +99,8 @@ set MNESIA_DIR=%MNESIA_BASE%/%NODENAME%-mnesia -s rabbit ^ +W w ^ +A30 ^ --kernel inet_default_listen_options "[{sndbuf, 16384}, {recbuf, 4096}]" ^ +-kernel inet_default_listen_options "[{nodelay, true}, {sndbuf, 16384}, {recbuf, 4096}]" ^ +-kernel inet_default_connect_options "[{nodelay, true}]" ^ -rabbit tcp_listeners "[{\"%NODE_IP_ADDRESS%\", %NODE_PORT%}]" ^ -kernel error_logger {file,\""%LOG_BASE%/%NODENAME%.log"\"} ^ -sasl errlog_type error ^ -- cgit v1.2.1 From 2d0364fd47662b0038d6fb9a7aef905c3465e7bc Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Tue, 30 Sep 2008 14:14:01 +0100 Subject: modulate gen_server:call timeout when doing work in parallel When we fire off lots of gen_server:calls in parallel, we may create enough work for the VM to cause the calls to time out - since the amount of work that can actually be done in parallel is finite. The fix is to adjust the timeout based on the total workload. Alternatively we could not have any timeout at all, but that is bad Erlang style since a small error somewhere could result in stuck processes. I moved the parallelisation - and hence timeout modulation - from the channel into the amqqueue module, changing the API in the process - commit, rollback and notify_down now all operate on lists of QPids (and I've renamed the functions to make that clear). The alternative would have been to add Timeout params to these three functions, but I reckon the API is cleaner this way, particularly considering that rollback doesn't actually do a call - it does a cast and hence doesn't require a timeout - so in the alternative API we'd either have to expose that fact indirectly by not having a Timeout param, or have a bogus Timeout param, neither of which is particularly appealing. I considered making the functions take sets instead of lists, since that's what the channel code produces, plus sets have a more efficient length operation. However, API-wise I reckon lists are nicer, plus it means I can give a more precise type to dialyzer - sets would be opaque and non-polymorphic. --- src/rabbit_amqqueue.erl | 61 +++++++++++++++++++++++++++++++++++++------------ src/rabbit_channel.erl | 52 +++++++++++++---------------------------- 2 files changed, 63 insertions(+), 50 deletions(-) diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 7ce350d8..bcb724ea 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -28,12 +28,12 @@ -export([start/0, recover/0, declare/4, delete/3, purge/1, internal_delete/1]). -export([pseudo_queue/2]). -export([lookup/1, with/2, with_or_die/2, list_vhost_queues/1, - stat/1, stat_all/0, deliver/5, redeliver/2, requeue/3, ack/4, - commit/2, rollback/2]). + stat/1, stat_all/0, deliver/5, redeliver/2, requeue/3, ack/4]). -export([add_binding/4, delete_binding/4, binding_forcibly_removed/2]). -export([claim_queue/2]). -export([basic_get/3, basic_consume/7, basic_cancel/4]). --export([notify_sent/2, notify_down/2]). +-export([notify_sent/2]). +-export([commit_all/2, rollback_all/2, notify_down_all/2]). -export([on_node_down/1]). -import(mnesia). @@ -44,6 +44,8 @@ -include("rabbit.hrl"). -include_lib("stdlib/include/qlc.hrl"). +-define(CALL_TIMEOUT, 5000). + %%---------------------------------------------------------------------------- -ifdef(use_specs). @@ -53,6 +55,9 @@ -type(qfun(A) :: fun ((amqqueue()) -> A)). -type(bind_res() :: {'ok', non_neg_integer()} | {'error', 'queue_not_found' | 'exchange_not_found'}). +-type(ok_or_errors() :: + 'ok' | {'error', [{'error' | 'exit' | 'throw', any()}]}). + -spec(start/0 :: () -> 'ok'). -spec(recover/0 :: () -> 'ok'). -spec(declare/4 :: (queue_name(), bool(), bool(), amqp_table()) -> @@ -81,9 +86,9 @@ -spec(redeliver/2 :: (pid(), [{message(), bool()}]) -> 'ok'). -spec(requeue/3 :: (pid(), [msg_id()], pid()) -> 'ok'). -spec(ack/4 :: (pid(), maybe(txn()), [msg_id()], pid()) -> 'ok'). --spec(commit/2 :: (pid(), txn()) -> 'ok'). --spec(rollback/2 :: (pid(), txn()) -> 'ok'). --spec(notify_down/2 :: (amqqueue(), pid()) -> 'ok'). +-spec(commit_all/2 :: ([pid()], txn()) -> ok_or_errors()). +-spec(rollback_all/2 :: ([pid()], txn()) -> ok_or_errors()). +-spec(notify_down_all/2 :: ([amqqueue()], pid()) -> ok_or_errors()). -spec(binding_forcibly_removed/2 :: (binding_spec(), queue_name()) -> 'ok'). -spec(claim_queue/2 :: (amqqueue(), pid()) -> 'ok' | 'locked'). -spec(basic_get/3 :: (amqqueue(), pid(), bool()) -> @@ -287,14 +292,29 @@ requeue(QPid, MsgIds, ChPid) -> ack(QPid, Txn, MsgIds, ChPid) -> gen_server:cast(QPid, {ack, Txn, MsgIds, ChPid}). -commit(QPid, Txn) -> - gen_server:call(QPid, {commit, Txn}). - -rollback(QPid, Txn) -> - gen_server:cast(QPid, {rollback, Txn}). - -notify_down(#amqqueue{ pid = QPid }, ChPid) -> - gen_server:call(QPid, {notify_down, ChPid}). +commit_all(QPids, Txn) -> + Timeout = length(QPids) * ?CALL_TIMEOUT, + safe_pmap_ok( + fun (QPid) -> gen_server:call(QPid, {commit, Txn}, Timeout) end, + QPids). + +rollback_all(QPids, Txn) -> + safe_pmap_ok( + fun (QPid) -> gen_server:cast(QPid, {rollback, Txn}) end, + QPids). + +notify_down_all(QPids, ChPid) -> + Timeout = length(QPids) * ?CALL_TIMEOUT, + safe_pmap_ok( + fun (QPid) -> + rabbit_misc:with_exit_handler( + %% we don't care if the queue process has terminated + %% in the meantime + fun () -> ok end, + fun () -> gen_server:call(QPid, {notify_down, ChPid}, + Timeout) end) + end, + QPids). binding_forcibly_removed(BindingSpec, QueueName) -> rabbit_misc:execute_mnesia_transaction( @@ -367,3 +387,16 @@ pseudo_queue(QueueName, Pid) -> arguments = [], binding_specs = [], pid = Pid}. + +safe_pmap_ok(F, L) -> + case lists:filter(fun (R) -> R =/= ok end, + rabbit_misc:upmap( + fun (V) -> + try F(V) + catch Class:Reason -> {Class, Reason} + end + end, L)) of + [] -> ok; + Errors -> {error, Errors} + end. + diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 5cc07aed..a9278898 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -707,21 +707,6 @@ ack(ProxyPid, TxnKey, UAQ) -> make_tx_id() -> rabbit_misc:guid(). -safe_pmap_set_ok(F, S) -> - case lists:filter(fun (R) -> R =/= ok end, - rabbit_misc:upmap( - fun (V) -> - try F(V) - catch Class:Reason -> {Class, Reason} - end - end, sets:to_list(S))) of - [] -> ok; - Errors -> {error, Errors} - end. - -notify_participants(F, TxnKey, Participants) -> - safe_pmap_set_ok(fun (QPid) -> F(QPid, TxnKey) end, Participants). - new_tx(State) -> State#ch{transaction_id = make_tx_id(), tx_participants = sets:new(), @@ -729,8 +714,8 @@ new_tx(State) -> internal_commit(State = #ch{transaction_id = TxnKey, tx_participants = Participants}) -> - case notify_participants(fun rabbit_amqqueue:commit/2, - TxnKey, Participants) of + case rabbit_amqqueue:commit_all(sets:to_list(Participants), + TxnKey) of ok -> new_tx(State); {error, Errors} -> exit({commit_failed, Errors}) end. @@ -743,8 +728,8 @@ internal_rollback(State = #ch{transaction_id = TxnKey, [self(), queue:len(UAQ), queue:len(UAMQ)]), - case notify_participants(fun rabbit_amqqueue:rollback/2, - TxnKey, Participants) of + case rabbit_amqqueue:rollback_all(sets:to_list(Participants), + TxnKey) of ok -> NewUAMQ = queue:join(UAQ, UAMQ), new_tx(State#ch{unacked_message_q = NewUAMQ}); {error, Errors} -> exit({rollback_failed, Errors}) @@ -767,23 +752,18 @@ fold_per_queue(F, Acc0, UAQ) -> Acc0, D). notify_queues(#ch{proxy_pid = ProxyPid, consumer_mapping = Consumers}) -> - safe_pmap_set_ok( - fun (QueueName) -> - case rabbit_amqqueue:with( - QueueName, - fun (Q) -> - rabbit_amqqueue:notify_down(Q, ProxyPid) - end) of - ok -> - ok; - {error, not_found} -> - %% queue has been deleted in the meantime - ok - end - end, - dict:fold(fun (_ConsumerTag, QueueName, S) -> - sets:add_element(QueueName, S) - end, sets:new(), Consumers)). + rabbit_amqqueue:notify_down_all( + [QPid || QueueName <- + sets:to_list( + dict:fold(fun (_ConsumerTag, QueueName, S) -> + sets:add_element(QueueName, S) + end, sets:new(), Consumers)), + case rabbit_amqqueue:lookup(QueueName) of + {ok, Q} -> QPid = Q#amqqueue.pid, true; + %% queue has been deleted in the meantime + {error, not_found} -> QPid = none, false + end], + ProxyPid). is_message_persistent(#content{properties = #'P_basic'{ delivery_mode = Mode}}) -> -- cgit v1.2.1 From 61d631e74034074cb6fca2e542f1c014431e134f Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Tue, 30 Sep 2008 14:35:46 +0100 Subject: oops --- src/rabbit_amqqueue.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index bcb724ea..193b1076 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -88,7 +88,7 @@ -spec(ack/4 :: (pid(), maybe(txn()), [msg_id()], pid()) -> 'ok'). -spec(commit_all/2 :: ([pid()], txn()) -> ok_or_errors()). -spec(rollback_all/2 :: ([pid()], txn()) -> ok_or_errors()). --spec(notify_down_all/2 :: ([amqqueue()], pid()) -> ok_or_errors()). +-spec(notify_down_all/2 :: ([pid()], pid()) -> ok_or_errors()). -spec(binding_forcibly_removed/2 :: (binding_spec(), queue_name()) -> 'ok'). -spec(claim_queue/2 :: (amqqueue(), pid()) -> 'ok' | 'locked'). -spec(basic_get/3 :: (amqqueue(), pid(), bool()) -> -- cgit v1.2.1 From 581757b0122d58aaac458c7f03e7576ac928453e Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 1 Oct 2008 12:39:26 +0100 Subject: cosmetic refactoring --- src/rabbit_amqqueue.erl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 193b1076..bd64f1e4 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -389,13 +389,13 @@ pseudo_queue(QueueName, Pid) -> pid = Pid}. safe_pmap_ok(F, L) -> - case lists:filter(fun (R) -> R =/= ok end, - rabbit_misc:upmap( - fun (V) -> - try F(V) - catch Class:Reason -> {Class, Reason} - end - end, L)) of + case [R || R <- rabbit_misc:upmap( + fun (V) -> + try F(V) + catch Class:Reason -> {Class, Reason} + end + end, L), + R =/= ok] of [] -> ok; Errors -> {error, Errors} end. -- cgit v1.2.1 From 9566f56e6e3ebb0cd34538a54072d441ef155e69 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 3 Oct 2008 13:47:01 +0100 Subject: propagate channel/connection errors when in closing state --- src/rabbit_reader.erl | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index bfd1ea72..7e68b3ed 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -94,10 +94,18 @@ %% terminate_channel timeout -> remove 'closing' mark, *closing* %% handshake_timeout -> ignore, *closing* %% heartbeat timeout -> *throw* -%% channel exit -> -%% if abnormal exit then log error -%% if last channel to exit then send connection.close_ok, start -%% terminate_connection timer, *closing* +%% channel exit with hard error +%% -> log error, wait for channels to terminate forcefully, start +%% terminate_connection timer, send close, *closed* +%% channel exit with soft error +%% -> log error, start terminate_channel timer, mark channel as +%% closing +%% if last channel to exit then send connection.close_ok, +%% start terminate_connection timer, *closed* +%% else *closing* +%% channel exits normally +%% -> if last channel to exit then send connection.close_ok, +%% start terminate_connection timer, *closed* %% closed: %% socket close -> *terminate* %% receive connection.close_ok -> self() ! terminate_connection, @@ -291,24 +299,13 @@ terminate_channel(Channel, Ref, State) -> end, State. -handle_dependent_exit(Pid, Reason, - State = #v1{connection_state = closing}) -> - case channel_cleanup(Pid) of - undefined -> exit({abnormal_dependent_exit, Pid, Reason}); - Channel -> - case Reason of - normal -> ok; - _ -> log_channel_error(closing, Channel, Reason) - end, - maybe_close(State) - end; handle_dependent_exit(Pid, normal, State) -> channel_cleanup(Pid), - State; + maybe_close(State); handle_dependent_exit(Pid, Reason, State) -> case channel_cleanup(Pid) of undefined -> exit({abnormal_dependent_exit, Pid, Reason}); - Channel -> handle_exception(State, Channel, Reason) + Channel -> maybe_close(handle_exception(State, Channel, Reason)) end. channel_cleanup(Pid) -> @@ -365,13 +362,15 @@ wait_for_channel_termination(N, TimerRef) -> exit(channel_termination_timeout) end. -maybe_close(State) -> +maybe_close(State = #v1{connection_state = closing}) -> case all_channels() of [] -> ok = send_on_channel0( State#v1.sock, #'connection.close_ok'{}), close_connection(State); _ -> State - end. + end; +maybe_close(State) -> + State. handle_frame(Type, 0, Payload, State = #v1{connection_state = CS}) when CS =:= closing; CS =:= closed -> -- cgit v1.2.1 From 9f13a84c4e2032753f7f0981973b4f3422a32784 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 13 Oct 2008 21:05:02 +0100 Subject: don't log errors during delivery If the target queue died normally we don't care, and if it died abnormally the reason is logged by the queue supervisor. In both cases we treat the message as unrouted. --- src/rabbit_router.erl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/rabbit_router.erl b/src/rabbit_router.erl index 41a8d64c..a2337647 100644 --- a/src/rabbit_router.erl +++ b/src/rabbit_router.erl @@ -150,11 +150,9 @@ run_bindings(QPids, IsMandatory, IsImmediate, Txn, Message) -> fun (QPid, {Routed, Handled}) -> case catch rabbit_amqqueue:deliver(IsMandatory, IsImmediate, Txn, Message, QPid) of - true -> {true, [QPid | Handled]}; - false -> {true, Handled}; - {'EXIT', Reason} -> rabbit_log:warning("delivery to ~p failed:~n~p~n", - [QPid, Reason]), - {Routed, Handled} + true -> {true, [QPid | Handled]}; + false -> {true, Handled}; + {'EXIT', _Reason} -> {Routed, Handled} end end, {false, []}, -- cgit v1.2.1