How to programmatically discover location of rabbitmq.config?

262 views
Skip to first unread message

vitaly numenta

unread,
May 17, 2016, 3:14:01 AM5/17/16
to rabbitmq-users
I need to modify rabbitmq.config in an environment where rabbitmq is already installed and running. Rabbitmq may be installed by an external environment, such as Travis-ci (linux or OS X), AppVeyor, etc. According to https://www.rabbitmq.com/configure.html, the location of the config file differs depending on the package that was used to install rabbitmq, so I can't assume that it's going to be in a specific location by OS.

I noticed that the Management web GUI displays the path of rabbitmq.config in the Overview tab (it might be suffixed with "(not found)", if the config file hasn't been created).

Because I don't control how rabbitmq is installed on the system, I don't know the proper location where the running rabbitmq broker expects to find its rabbitmq.config file. For this reason, I need to query the running rabbitmq for the location of rabbitmq.config programmatically. I need to be able to do this from a bash script. The assumption is that the locations of rabbitmq-server and rabbitmqctl are in in PATH env var.

Please help.

Thank you,
Vitaly

Michael Klishin

unread,
May 17, 2016, 3:23:10 AM5/17/16
to rabbitm...@googlegroups.com
rabbitmqctl eval '{ok, [Paths]} = init:get_argument(config), hd(Paths).'

should work well enough, hopefully in master as well.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
MK

Staff Software Engineer, Pivotal/RabbitMQ

vitaly numenta

unread,
May 17, 2016, 4:41:00 PM5/17/16
to rabbitmq-users
Thanks Michael: I tried the command on my OS X El Capitan with RabbitMQ 3.6.1, but it failed:

$ rabbitmqctl eval '{ok, [Paths]} = init:get_argument(config), hd(Paths).'
Error: {{badmatch,error},[{erl_eval,expr,3,[]}]}

Michael Klishin

unread,
May 17, 2016, 4:49:58 PM5/17/16
to rabbitmq-users
Try just init:get_argument(config). It probably returns something other than what I get.

Michael Klishin

unread,
May 17, 2016, 4:53:41 PM5/17/16
to rabbitmq-users
Try just init:get_argument(config). It probably returns something other than what I get.

On Tuesday, May 17, 2016 at 11:41:00 PM UTC+3, vitaly numenta wrote:

Michael Klishin

unread,
May 17, 2016, 4:55:05 PM5/17/16
to rabbitmq-users
I'm not 100% sure about your expectations. RabbitMQ does not know where its config file is supposed
to be by default. That is entirely package-dependent. RabbitMQ can only report the config it uses or
that no config was provided.

Config file location is just a convention documented in http://www.rabbitmq.com/relocate.html.

So what you are trying to get RabbitMQ to report may or may not be at all possible.

Michael Klishin

unread,
May 17, 2016, 4:58:19 PM5/17/16
to rabbitm...@googlegroups.com
Small clarification: the config file *path* it was given (or that none was).

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Laing, Michael

unread,
May 17, 2016, 4:59:24 PM5/17/16
to rabbitm...@googlegroups.com
Hmm - I just tried on my OS X El Capitan 10.11.4 with RabbitMQ 3.6.1.903, Erlang 17.5 and it worked fine.

$ rabbitmqctl eval '{ok, [Paths]} = init:get_argument(config), hd(Paths).'
"/usr/local/etc/rabbitmq/rabbitmq"

--

vitaly numenta

unread,
May 17, 2016, 8:02:53 PM5/17/16
to rabbitmq-users
Sorry guys, I am not an erl-head, so all this is foreign to me. I already reported the error that I get when executing `rabbitmqctl eval '{ok, [Paths]} = init:get_argument(config), hd(Paths).'` on RabbitMQ 3.6.1 with Erlang 18.3.

Michale, I tried just the following per your suggestion (if I understood you correctly), and it returned Error:

$ rabbitmqctl eval 'init:get_argument(config).'
error

It looks to me like RabbitMQ has to know where to look for rabbitmq.config, otherwise how would it know where to find it? For example, when I look at the RabbitMQ Management GUI on my MacBookPro (see attachment), it shows the location of the file with the suffix of "(not found)". So, it clearly knows the location it expects the file to be.

Screen Shot 2016-05-17 at 4.51.46 PM.png

Michael Klishin

unread,
May 18, 2016, 1:39:21 AM5/18/16
to rabbitm...@googlegroups.com
No, it does not. Packages and shell scripts set up a path, and it can be overridden with RABBITMQ_CONFIG_FILE,
but RabbitMQ is absolutely unaware of what that path should be by default.

init:get_argument/1 is the main function that is used to determine config file location. What you see in the management UI
basically uses that function and prints (not found) is the file does not exist.


--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

vitaly numenta

unread,
May 18, 2016, 2:15:43 AM5/18/16
to rabbitmq-users
Thanks Michael, I agree that packages and shell scripts set up a path and that RABBITMQ_CONFIG_FILE may override it. So, once the the package or shell script sets the path or RABBITMQ_CONFIG_FILE is used to override it and rabbitmq is started, rabbitmq uses that information to know the path of the config file.

I just want to find out the config path that the running rabbitmq learned from the package or shell script or RABBITMQ_CONFIG_FILE, just like the management plugin gets and displays that path, even if the config file doesn't exist.

Unfortunately, when I try to run the command that you shared with me, it fails on rabbitmq 3.6.1 and erlang 18.3

Michael Klishin

unread,
May 18, 2016, 2:16:50 AM5/18/16
to rabbitm...@googlegroups.com
Perhaps I should be a bit more clear:

 * RabbitMQ shell scripts — which are package-specific — use a set of conventions to compute default config file location
 * In 3.7.0, they generate a config in the classic format from a sysctl one.
 * It gets passed as a -config value to the Erlang VM
 * RabbitMQ is aware of config paths and can verify if they exist and are readable
 * RabbitMQ has no idea of what default config location is, only knows about the effective one (which can be overridden)

Michael Klishin

unread,
May 18, 2016, 2:20:17 AM5/18/16
to rabbitm...@googlegroups.com
I see.

rabbitmqctl eval 'case init:get_argument(config) of error -> "none"; {ok, [Paths]} -> hd(Paths) end.'

should handle missing config files and output "none".

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

vitaly numenta

unread,
May 18, 2016, 3:08:38 AM5/18/16
to rabbitmq-users
Now, when I run `rabbitmqctl eval 'case init:get_argument(config) of error -> "none"; {ok, [Paths]} -> hd(Paths) end.'` on my own dev laptop, it indeed returns "none". 

However, the Management web GUI displays "Config file /usr/local/etc/rabbitmq/rabbitmq.config (not found)", so somehow it knows the path "/usr/local/etc/rabbitmq/rabbitmq.config", even though the file hasn't been created. I need to be able to get this path ("/usr/local/etc/rabbitmq/rabbitmq.config" in the case of my dev laptop) instead of "none", just like Management web GUI gets it.

Michael Klishin

unread,
May 18, 2016, 3:56:52 AM5/18/16
to rabbitm...@googlegroups.com
Here is the function that rabbitmq-management-agent uses to display what you see in the UI:


so it does what the provided eval snippet does except for one thing: it falls back to


which also consults the value of RABBITMQ_CONFIG_FILE and a (Windows-specific) VM property
also configured by startup scripts.

On Wed, May 18, 2016 at 10:08 AM, vitaly numenta <vitaly.kru...@gmail.com> wrote:
Now, when I run `rabbitmqctl eval 'case init:get_argument(config) of error -> "none"; {ok, [Paths]} -> hd(Paths) end.'` on my own dev laptop, it indeed returns "none". 

However, the Management web GUI displays "Config file /usr/local/etc/rabbitmq/rabbitmq.config (not found)", so somehow it knows the path "/usr/local/etc/rabbitmq/rabbitmq.config", even though the file hasn't been created. I need to be able to get this path ("/usr/local/etc/rabbitmq/rabbitmq.config" in the case of my dev laptop) instead of "none", just like Management web GUI gets it.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

vitaly numenta

unread,
May 19, 2016, 3:52:12 PM5/19/16
to rabbitmq-users
Many thanks Michael! I ran on my OS X machine: rabbitmqctl eval 'rabbit:config_files().' and got this result ["/usr/local/etc/rabbitmq/rabbitmq.config (not found)"]

The plural name rabbit:config_files would seem to imply that this function might return more than one config file path in the array? How is this possible? Can there really be more than one rabbitmq.config file?

Michael Klishin

unread,
May 19, 2016, 4:02:41 PM5/19/16
to rabbitm...@googlegroups.com
It is possible in Erlang. It is also possible in RabbitMQ master.

On Thu, May 19, 2016 at 10:52 PM, vitaly numenta <vitaly.kru...@gmail.com> wrote:
Many thanks Michael! I ran on my OS X machine: rabbitmqctl eval 'rabbit:config_files().' and got this result ["/usr/local/etc/rabbitmq/rabbitmq.config (not found)"]

The plural name rabbit:config_files would seem to imply that this function might return more than one config file path in the array? How is this possible? Can there really be more than one rabbitmq.config file?

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

vitaly numenta

unread,
May 19, 2016, 5:27:16 PM5/19/16
to rabbitmq-users
Thank you. I am guessing that the multiple config files might be the result of the extended sys.config syntax that permits additional config files to be specified in sys.config per http://erlang.org/doc/man/config.html? E.g., 
[{Application, [{Par, Val}]} | File].

Michael Klishin

unread,
May 20, 2016, 3:15:47 AM5/20/16
to rabbitm...@googlegroups.com
I'd rather not have to explain how releases, embedded mode, and so on, works. In RabbitMQ master you the user can configure
more than one file.

On Fri, May 20, 2016 at 12:27 AM, vitaly numenta <vitaly.kru...@gmail.com> wrote:
Thank you. I am guessing that the multiple config files might be the result of the extended sys.config syntax that permits additional config files to be specified in sys.config per http://erlang.org/doc/man/config.html? E.g., 
[{Application, [{Par, Val}]} | File].

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages