rabbitmq-server
rabbitmq-server copied to clipboard
RFE to change the default RABBITMQ_BASE path in Windows.
The default RABBITMQ_BASE path in windows is problematic. The service is configured by default to start with the Local Service account which has nothing to do with the user who installed it. It is not intuitive for a system wide application (as is the case with a Windows service installed in this fashion) to reference any data in a users own profile. That profile may be subject to removal by age or simply when logging off if configured to do so. For most corporate environments, this path may also be subject to roaming and replication as well.
The use of AppData is appropriate for a user running the server (not service) manually with the RabbitMQ Command Prompt as the output is user specific and not expected to be persisted (although it certainly may) when the user logs out or kills the RabbitMQ server instance.
This path needs to have a different location, an argument exist for one of %ProgramData%, %ProgramFiles% or %ProgramFiles(x86)% but a better option might be to ask the user when installing the service at application installation time and force the user to choose and populate RABBITMQ_BASE. That would remove the ambiguity when installed as a service.
Some links regarding the locations:
- https://msdn.microsoft.com/en-us/library/windows/desktop/mt674655%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
- https://msdn.microsoft.com/en-us/library/ms995853.aspx
- https://msdn.microsoft.com/en-ca/library/windows/apps/hh465094.aspx?f=255&MSPPError=-2147217396
@jcasale thank you for stepping up. We'll consider it for 3.7.0.
It's not recommended to use %ProgramFiles% for the application data, according to this guidelines. %ProgramData% is a better choice for service RABBITMQ_BASE.
In order to use users AppData for rabbitmq-server.bat data, we need to create a directory structure on each run, instead of installation.
This part is very problematic on Windows, so we invested a lot of time in creating a custom distribution (with predefined folders and patched .bat files) which:
- doesn't require install
- doesn't touch any user's folders
- doesn't use environment variables (they are really bad, believe me)
For real enterprise deployments these things are critical, so any improvements would be very welcome.
What directory is used and how are things configured then? And by "doesn't require install" you mean "installed via uncompressing an archive" or something similar?
Please refrain from using vague and meaningless terms such as "real enterprise deployments." Let's talk specific problems and improvements or I'm going to close this.
The idea of configuring RABBITMQ_BASE in an installer step makes sense. Upgrades will be tricky, however.
I didn't go into specifics, but if you asked... This is our scenario and works for us, maybe someone will find this usefull.
We distribute erlang and rabbitmq together in zip file with a folder structure:
- appdata
- erl
- rabbitmq_server
This folder structure is deployed to server to a specific folder, for example C:\dist We bundle all the plugins and already configured enabled_plugins file, and we have to patch erl.ini files in erlang dist to point to the actual folder erl will be deployed:
- Bindir=C:\dist\erl\erts-7.2.1\bin
- Rootdir=C:\dist\erl
We also patch rabbitmq-env.bat to call our .bat at the beginning, where we set following env variables:
- RABBITMQ_BASE="C:\dist\appdata"
- ERLANG_HOME="C:\dist\erl"
and we don't want to use .erlang.cookie from user's or c:\windows folder, that's why we store it in appdata folder and set environment variables: COOKIE_VALUE="C:\dist\appdata.erlang.cookie" RABBITMQ_SERVER_ERL_ARGS=%RABBITMQ_SERVER_ERL_ARGS% -setcookie %COOKIE_VALUE% RABBITMQ_CTL_ERL_ARGS=%RABBITMQ_CTL_ERL_ARGS% -setcookie %COOKIE_VALUE%
With this, we just unzip this folder and install service with rabbitmq-service.bat. (of course we configure it, set cookie and other things). If it's done the very first time, you must also execute: "C:\dist\erl\install.exe -s".
The end result:
- doesn't require install
- doesn't touch any user's folders
- doesn't use (system's) environment variables
- uses only one folder anywhere on disk with everything in it
And removing dist (or playing with other versions side-by-side) is as easy as uninstalling service and deleting C:\dist. We obviously didn't want to do all these custom things, but now our deployment is very easy. If you have a multi environment clustered setup, this helps a lot.
Thanks @biiiipy
Your description above helped me a lot and I’m almost there. I’m though still having problem with the erlang cookie (.erlang.cookie).
I created a bat file that adds “-setcookie %COOKIE_VALUE%” to the RABBITMQ_SERVER_ERL_ARGS and RABBITMQ_CTL_ERL_ARG environment variables and I call that bat file at the end of the rabbitmq-env.bat file. My %COOKIE_VALUE% is earlier sat to my %RABBITMQ_BASE%.erlang.cookie (for now my %RABBITMQ_BASE% is simply C:\RabbitMQ\appdata).
When I run the rabbitmq-service.bat to install the service I see that my “-setcookie …..” (added an echo) is there and correct. And then I start the RabbitMQ service. RabbitMQ is working and I can post messages and receive.
But…. I get no cookie in my %RABBITMQ_BASE% folder and neither in the, other vice standard, windows folder. The only cookie created is in my %home% directory (in my case redirected by some policy or other to K:). I’m also unable to use rabbitmqctl.bat that reports that the node is down and “Authentication failed (rejected by the remote node), please check the Erlang cookie”. But…. RabbitMQ IS working and I’m able to administrate it through the web interface. I have also tried to copy the cookie from %home% to %RABBITMQ_BASE% (where it should be) and to the Windows directory but the rabbitmqctl message is always the same.
Am I missing something here…? All hints appreciated!
I'm not sure I understand the case, but basically you don't really need a .erlang.cookie, you just have to provide value with -setcookie which you get from somewhere. In my case, I read the cookie's value from a file (I still call it .erlang.cookie, but it could be anything).
here's an example of bat files:
(before that put your cookie in C:\dist\appdata\.erlang.cookie)
rabbitmq-env.bat (part)
...
REM SCRIPT_DIR=`dirname $SCRIPT_PATH`
REM RABBITMQ_HOME="${SCRIPT_DIR}/.."
set SCRIPT_DIR=%TDP0%
set SCRIPT_NAME=%1
for /f "delims=" %%F in ("%SCRIPT_DIR%..") do set RABBITMQ_HOME=%%~dpsF%%~nF%%~xF
call "%SCRIPT_DIR%\custom-rabbitmq-env.bat"
REM If ERLANG_HOME is not defined, check if "erl.exe" is available in
...
custom-rabbitmq-env.bat (my bat skills are not so good)
@echo off
if "!ERLANG_HOME!"=="" (
set ERLANG_HOME="C:\dist\erl"
)
if "!RABBITMQ_BASE!"=="" (
set RABBITMQ_BASE="C:\dist\appdata"
)
if not exist "C:\dist\appdata\.erlang.cookie" (
echo. NOT FOUND C:\dist\appdata\.erlang.cookie
exit /B 1
)
set /p COOKIE_VALUE=<"C:\dist\appdata\.erlang.cookie"
if "!COOKIE_VALUE!"=="" (
set COOKIE_VALUE="ERROR_COOKIE_NOT_SET"
)
echo.%RABBITMQ_SERVER_ERL_ARGS% | findstr /C:"setcookie" 1>nul
if errorlevel 1 (
set "RABBITMQ_SERVER_ERL_ARGS=%RABBITMQ_SERVER_ERL_ARGS% -setcookie %COOKIE_VALUE%"
)
echo.%RABBITMQ_CTL_ERL_ARGS% | findstr /C:"setcookie" 1>nul
if errorlevel 1 (
set "RABBITMQ_CTL_ERL_ARGS=%RABBITMQ_CTL_ERL_ARGS% -setcookie %COOKIE_VALUE%"
)
Thanks a lot. You saved my day! In your bat I noticed “set /p COOKIE_VALUE=<"C:\dist\appdata.erlang.cookie", that is you put the content of the cookie file in your variable :). What I was doing was giving the -setcookie the path to the cookie file and that didn’t work. Now I modified according to your example (read the file content into the variable) and now everything works wonderfully :) I completely misunderstood how this -setcookie and the whole cookie business worked.
Many thanks!
When running the installer the program should go to %ProgramFiles% and the database should be created in %ProgramData% that is what the default paths should be on Windows.
Ok, for people that land here, the solution is to set the ENVVAR prior to running the installer, then logout, and login again and run the RabbitMQ installer. Now RabbitMQ will not store the data anymore in a user folder when installed as a windows service but in the C:\ProgramData* folder where it should store its data.
RABBITMQ_BASE=C:\ProgramData\RabbitMQ
[153367324]