Amazon SSM Agent not syncing a log starting with empty line - amazon-cloudwatch

I have a Windows EC2 machine running legacy software and a need to sync file logs from it to CloudWatch.
Relevant configuration in AWS.EC2.Windows.CloudWatch.json is as follows:
...
{
"FullName": "AWS.EC2.Windows.CloudWatch.CustomLog.CustomLogInputComponent,AWS.EC2.Windows.CloudWatch",
"Id": "LegacyLogs",
"Parameters": {
"CultureName": "en-US",
"Encoding": "UTF-8",
"Filter": "*.log",
"LineCount": "10",
"LogDirectoryPath": "C:\\Program Files\\LegacyApp\\log\\",
"TimeZoneKind": "Local",
"TimestampFormat": "HH:mm:ss"
}
},
...
Legacy software outputs log file starting with empty line followed by time:
14:09:37 * Open log file
on 'WHATEVER'
When empty line is removed log will sync to CloudWatch. Otherwise, file is silently ignored.
Any ideas on how to configure the agent to sync the logs when there are empty lines at the start of the log file?

I have managed to mitigate the problem. In case this might be of interest there is an issue open on Github now.
https://github.com/aws/amazon-ssm-agent/issues/251

Related

How do I get Windows 10 Terminal to launch WSL?

I'm using the new Windows Terminal, and trying to get it to launch my WSL terminal. This is the setting that I'm trying to use:
{
"acrylicOpacity" : 0.75,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "%LOCALAPPDATA%/wsltty/bin/mintty.exe --WSL= --configdir='%APPDATA%/wsltty' -~ ",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 10,
"guid" : "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
"name" : "wsl",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : true
}
But all it's doing is opening some sort of CMD.
What's the correct command to run the WSL terminal
Edit:
I did notice that the GUID was the same thing as the regular CMD, so I changed that. Then it did launch an external shell.
You need to do following things first.
1. Install Linux (e.g. Ubuntu)
Search "Ubuntu" in the Microsoft store, then buy and install. This is actually WSL (Windows Subsystem for Linux).
Of course, you want to experience other versions of Linux, as well as Debian:
2. Enable WSL permissions
After installing the WSL version of Linux, you also need to enable WSL permissions:
Open another PowerShell window with "Run as Administrator".
Then enter the following command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
After the command is completed, you can execute the Linux command in the built-out Terminal.
First enter ubuntu in cmd, take a little time to start Ubuntu, set the username and password.
Then you can play with Ubuntu happily. Below I entered a few common commands such as ps, touch, ls etc., as shown below.
3. Change settings
Click "Settings" in right top corner of above image, the file profile.json file will be opened. Then inside the word "profiles" in profile.json file, add below snippet.
{
"guid": "{78e390db-1bff-4533-9d7c-20f53d8bafa1}",
"name": "WSL",
"colorscheme": "Campbell",
"historySize": 9001,
"snapOnInput": true,
"cursorColor": "#FFFFFF",
"cursorShape": "bar",
"commandline": "wsl ~",
"fontFace": "Consolas",
"fontSize": 12,
"acrylicOpacity": 0.75,
"useAcrylic": true,
"closeOnExit": false,
"padding": "0, 0, 0, 0"
}
Near the word "schemes" in profile.json file, you need to update below:
"schemes": [
{
"name": "Campbell",
"foreground": "#A7B191",
"background": "#0C0C0C",
"colors": [
"#0C0C0C",
"#C50F1F",
"#13A10E",
"#C19C00",
"#0037DA",
"#881798",
"#3A96DD",
"#CCCCCC",
"#767676",
"#E74856",
"#16C60C",
"#F9F1A5",
"#3B78FF",
"#B4009E",
"#61D6D6",
"#F2F2F2"
]
}
The complete setting file (profile.json) which can be obtained here.
Actually, the WSL here is Ubuntu.
4. Add icons to different types of tabs
You can add icons for Tab to this location:
%LOCALAPPDATA%\packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState
I put some 32x32 PNG in this folder, and then in profile.json I can reference the image resource with the path starting with ms-appdata:// .
The icon is available here:
Icons
Then replace the contents of the new profile-withIcons.json file below with the previous settings.
profile-withIcons.json
After finishing the contents of the folder is like this:
The final result is:
To launch any distribution, you can also use this for commandline:
wsl.exe -d <name_of_the_distribution>
Like :
wsl.exe -d Ubuntu-18.04
You can list all distributions with :
wsl.exe -l
.
PS : Tux icon for Linux :
ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png
Turns out that all I needed to do was change the commandline to ubuntu1804.exe. Like this:
{
"acrylicOpacity" : 0.75,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline": "ubuntu1804.exe",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 10,
"guid" : "{0caa0dad-35be-5f56-a8ff-abceeeaa6101}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
"name" : "wsl",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : false
}
While my answer is off-question (since answered by the O.P.) I found this question while searching for adding a Windows Terminal (WT) profile for my recent Ubuntu installation, since I had recently re-imaged my laptop.
Updated 19/10/03: Installation order does not matter. My profile for “ubuntu” appears after installing ubuntu, and then launching the ubuntu instance in PowerShell and establish my user account and password. THEN Windows Terminal adds the appropriate shell profile for WSL.
I have developed a tool for tweaking the terminal configurations here :
Windows Terminal Tweaker 🚀⚡
It lets you add different profiles , gives color pickers to choose color schemes and provides options to tweak every single thing while applying the settings live.
Open settings
Change the "Default Profile" in the drop down.
Click "Save" on the bottom right.
Create a new profile in the windows terminal settings and select the following command line
C:\Windows\system32\wsl.exe -d Ubuntu-20.04
where -d selects the distribution to be run.
Windows Terminal allows you to open the settings and change things there. If you already have ubuntu installed, it should be an option to set the ubuntu profile as your default config.
Copy paste the guid for ubuntu into the defaultProfile and it will automatically launch WSL ubuntu instead of powershell by default.
The premise of the question was fouled by the mistake with the GUID, as the OP says the sample code was actually correct. So, the question could be re-interpreted as--
What is the minimum required change to the default settings.json to point to an application of your choosing? (which is what got me here)
guid - has to be unique. I've had success with changing just the last number for each customization.
commandline - From within Bravo Yeung's answer is a link to a sample settings.json file: "commandline": "wsl ~"
This little bitty value is made possible by setting a default distro: "The default WSL distribution is the one that runs when you run wsl on a command line:"
wsl --setdefault <DistributionName>
However, seems commandline:wsl doesn't work with startingDirectory.
I've successfully omitted commandline in favor of source + startingDirectory:
// Make changes here to the cmd.exe profile.
"guid": "{long-guid-here}",
"hidden": false,
"name": "Debian",
"tabTitle" : "WSL (Debian)",
"source": "Windows.Terminal.Wsl",
"startingDirectory" : "C:\\Users\\myuser"
Here is a good link which got me started the first time I installed Windows Terminal and customized the settings, Easily add Anaconda Prompt to Windows Terminal to make life better
Recent versions of Windows Terminal include support for Dynamic Profiles, in which new WSL distros will automatically be added to the list of available profiles.
However, if Windows Terminal is running when you install the new distro, it will not currently get added while running. You must exit and re-start Windows Terminal, and the new profile will automatically appear.
Once it is added, you can edit/move it using the Settings dialog or by editing settings.json as usual. Each WSL distro is identified using a GUID which will have been auto-populated.
As described in the linked article, Dynamic Profiles can be turned off by disabling their source(s) such as the following in settings.json:
"disabledProfileSources": ["Windows.Terminal.Wsl", "Windows.Terminal.Azure", "Windows.Terminal.PowershellCore"]

How to manage a project folder via ssh?

Developing full-stack web apps, I would like to have all my code and build logic on a linux machine (i.e. git, docker containers and other terminal commands), but all my development workflow on my windows machine (so my IDE, web browser and REST client) accessing it via SSH.
I've managed to do all of that except for the IDE, I could only edit individual files via SSH instead of managing a folder as a project. So right now I use VSCode on the linux machine (Ubuntu), and it's the last thing preventing me for dropping the graphical interface and install Ubuntu Server on it.
And no, I don't want to use Vim or Emacs. I want to use VSCode, or another modern IDE, but preferably VSCode.
Try using the Remote VSCode plugin as explained here: Using Remote VSCode
This discussion is exactly about your problem: VSCode 13643 issue Github
EDIT: I have recently found a new VSCode plugin on Github: vs-deploy. It was designed to deploy files and folders remotely very quickly. It seems to be working and I haven't found any bugs so far. It works with FTP, SFTP (SSH) and many other protocols.
The SSH.NET nuget Package can be used quite nicly to copy files and folders.
Here is an example:
var host = "YourServerIpAddress";
var port = 22;
var user = "root"; // TODO: fix
var yourPathToAPrivateKeyFile = #"C:\Users\Bob\mykey"; // Use certificate for login
var authMethod = new PrivateKeyAuthenticationMethod(user, new PrivateKeyFile(yourPathToAPrivateKeyFile));
var connectionInfo = new ConnectionInfo(host, port, user, authMethod);
using (var client = new SftpClient(connectionInfo))
{
client.Connect();
if (client.IsConnected)
{
//TODO: Copy folders recursivly etc.
DirectoryInfo source = new DirectoryInfo(#"C:\your\probject\publish\path");
foreach (var file in source.GetFiles())
{
client.UploadFile(File.OpenRead(file.FullName), $"/home/yourUploadPath/{file.Name}", true);
}
}
}
When you create a upload console application using the code above your should be able to automatically trigger an upload by using postbuild events by adding a section to your Project.
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="path to execute your script or application" />
</Target>
If you prefer to do the same but more manual you can perform a
dotnet build --configuration Release
followed by a
dotnet publish ~/projects/app1/app1.csproj
and then use the code above to perform an upload.
Search for the extension SSHExtension developed by Vitaly Kondratiev
Install the extension.
And edit the serverlist json with the server details.
ex:
"sshextension.serverList": [
{
"name": "Kuberntes 212",
"host": "10.64.234.54",
"port": 22,
"username": "root",
"password": "byebye"
}
]
save the file
Then log in using ctrl+shift+p and choose sshextension open ssh extension category. It shall create a session for you.
More Easily if u need the entire directory structure into ur local workspace.
Use extension ftp-simple in vscode. It works as a wonder, trust me.
Install ftp-simple in vscode
ctrl+shift+p
select ftp-simple:config.
Configure your settings
[
{
"name": "Kubernetes 212",
"host": "10.75.64.2",
"port": 22,
"type": "sftp",
"username": "root",
"password": "byebye",
"path": "/home/vinod/",
"autosave": true,
"confirm": true
}]
save the file.
Now ctrl+shift+p
and select ftp-simple:remote directory to workspace.
Viola Your work is done, Life is simple

Running custom script extension on deployed scale set instances

currently I'm using custom script extension to run scripts on demand on my azure vm server as part of our software solution, our other dev team is moving an application to a scale set and i am no longer capable of deploying custom script extension on demand to the scale set instances. the only solution i have found for running custom script extension on scale set instances is to reconfigure the deployment template with it, this method is not good for me as the scripts should be run on demand and are changed frequently and updating the template every time is bad practice.
Is there anyway to configure custom script extension on scale set instances on demand like on regular virtual machines?
powershell example for regular on demand script deployment on vm:
Set-AzureRmVMCustomScriptExtension -ResourceGroupName myResourceGroup `
-VMName myVM `
-Location myLocation `
-FileUri myURL `
-Run 'myScript.ps1' `
-Name DemoScriptExtension
I found a workaround for this using PowerShell and ARM JSON templates (I'm using Powershell version 5.1). In commandToExecute under virtualMachineProfile in your json template, specify a value that almost always changes and it will force the command to re-execute to run every time your template is deployed. You will see in my template that I added: ' -Date ', deployment().name to the commandToExecute. The value for deployment().name is specified in my New-AzureRmResourceGroupDeployment command as:
-Name $($(Get-Date -format "MM_dd_yyyy_HH_mm"))
The deployment name is based on the date and time, which will be different per minute.
PowerShell Command:
New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile $PathToJsonTemplate -TemplateParameterFile $PathToParametersFile -Debug -Name $($(Get-Date -format "MM_dd_yyyy_HH_mm")) -force
The custom script extension section under virtualMachineProfile in my script appears as such (pay attention to the commandToExecute):
"virtualMachineProfile": {
"extensionProfile": {
"extensions": [
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "MyExtensionName",
"location": "[parameters('location')]",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.8",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"[concat(parameters('customScriptExtensionSettings').storageAccountUri, '/scripts/MyScript.ps1')]"
],
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File MyScript.ps1', ' -Date ', deployment().name)]"
},
"protectedSettings": {
"storageAccountName": "[parameters('customScriptExtensionSettings').storageAccountName]",
"storageAccountKey": "[listKeys(variables('accountid'),'2015-05-01-preview').key1]"
}
}
},
This will allow you to update a Custom Script Extension on a Virtual Machine Scale Set that has already been deployed. I hope this helps!
Is there anyway to configure custom script extension on scale set
instances on demand like on regular virtual machines?
For now, Azure does not support this.
We only can use VMSS custom script to install software at the time the scale set is provisioned.
More information about VMSS extension, please refer to this link.

VSCode: How to run a command after each terminal open?

On Windows I have to run the command start-ssh-agent.cmd on each new terminal session I open. My development environment is VSCode, and I open a dozen new terminals each day. After each terminal open, I have to manually run this command.
Is there is a way to run this command on the terminal each time I open one ?
This may take the form of a VSCode extension, VSCode configuration (settings) or a Windows environment configuration.
Any idea?
On Linux systems you should use:
"terminal.integrated.shellArgs.linux"
On Windows and OSX:
terminal.integrated.shellArgs.windows
and
terminal.integrated.shellArgs.osx
respectively.
If you want to apply shellArgs setting on a per-workspace basis - you can, despite the fact that documentation says:
The first time you open a workspace which defines any of these settings, VS Code will warn you and subsequently always ignore the values after that
At least version 1.42 of VSCode asks you something like:
"This workspace wants to set shellArgs, do you want to allow it?"
See issue 19758
On Linux, if you are using bash (default for shell in VSCode), there are some subtleties:
"terminal.integrated.shellArgs.linux": ["your_init_script.sh"]
will execute the script and close terminal right away. To prevent this you'll have to end the script with $SHELL command.
#!/bin/bash
echo "init"
export PATH=$PATH:/xxx/yyy/zzz # or do whatever you want
$SHELL
But that way you end up in a subshell. Sometimes it's unacceptable (Read 1) (Read 2).
"terminal.integrated.shellArgs.linux": ["--init-file", "your_init_script.sh"]
will leave you in the initial shell, but will not execute the .bashrc init file. So you may want to source ~/.bashrc inside your_init_script.sh
#!/bin/bash
source ~/.bashrc
echo "init"
export PATH=$PATH:/xxx/yyy/zzz # or do whatever you want
And if you already have some_init_script.sh in a repository, and for some reason don't feel like adding source ~/.bashrc into it, you can use this:
"terminal.integrated.shellArgs.linux": ["--init-file", "your_init_script.sh"]
your_init_script.sh:
#!/bin/bash
source ~/.bashrc
source some_init_script.sh
some_init_script.sh:
#!/bin/bash
echo "init"
export PATH=$PATH:/xxx/yyy/zzz # or do whatever you want
Outside of VSCode you can do without creating extra file. Like this
bash --init-file <(echo "source ~/.bashrc; source some_init_script.sh")
But I could not pass this string into terminal.integrated.shellArgs.linux - it needs to be split into array somehow. And none of the combinations I've tried worked.
Also, you can open terminal at a specific folder:
terminal.integrated.cwd
Change env:
"terminal.integrated.env.linux"
"terminal.integrated.env.windows"
"terminal.integrated.env.osx"
And even change terminal to your liking with
terminal.integrated.shell.linux
terminal.integrated.shell.windows
terminal.integrated.shell.osx
Or
terminal.external.linuxExec
terminal.external.osxExec
terminal.external.windowsExec
I actually found a pretty neat Linux solution for this. It should also work on Windows if you use a shell like Bash. I'm not sure if it's possible using vanilla CMD.
Add something like this to your .bashrc or .zshrc:
#
# Allow parent to initialize shell
#
# This is awesome for opening terminals in VSCode.
#
if [[ -n $ZSH_INIT_COMMAND ]]; then
echo "Running: $ZSH_INIT_COMMAND"
eval "$ZSH_INIT_COMMAND"
fi
Now, in your VSCode workspace setting, you can set an environment variable like this:
"terminal.integrated.env.linux": {
"ZSH_INIT_COMMAND": "source dev-environment-setup.sh"
}
Now the script "dev-environment-setup.sh" will be automatically sourced in all new VSCode terminal windows.
You can do the following:
"terminal.integrated.shellArgs.windows": ["start-ssh-agent.cmd"]
Modified from: https://code.visualstudio.com/docs/editor/integrated-terminal#_shell-arguments
The other answer are great but a little outdated. You will get a warning in VSCode. Here is what I'm doing in my XXX.code-workspace file on linux:
"terminal.integrated.profiles.linux": {
"BashWithStartup": {
"path": "bash",
"args": [
"--init-file",
"./terminal_startup.sh"
]
}
},
"terminal.integrated.defaultProfile.linux": "BashWithStartup"
Be sure to make sure your terminal_startup.sh script is executable:
chmod u+x terminal_startup.sh
For anyone using the wonderful cmder, you'll need something akin to the following in your settings.json
{
"terminal.integrated.shell.windows": "cmd.exe",
"terminal.integrated.env.windows": {
"CMDER_ROOT": "C:\\path\\to\\cmder"
},
"terminal.integrated.shellArgs.windows": [
"/k",
"%CMDER_ROOT%\\vendor\\bin\\vscode_init.cmd"
],
}
And then you can add any aliases into the user_aliases.cmd file that should already exist in %CMDER_ROOT%\\config\\user_aliases.cmd
I use the following for powershell on Windows:
{
"terminal.integrated.shellArgs.windows": [
"-NoExit",
"-Command", "conda activate ./env"
]
}
After much trial and error, the following worked for me on OSX:
"terminal.integrated.shellArgs.osx": [
"-l",
"-c",
"source script.sh; bash"
],
For context, I'm using this with a jupyter notebook to set environment variables that cannot simply be defined using terminal.integrated.env.osx
After the April 2021 update the configuration structure has been changed.
Check the documentation.
There's a distinction even between terminal instances. To run a file on Windows:
PowerShell
{
"terminal.integrated.profiles.windows": {
"My PowerShell": {
"path": "pwsh.exe",
"args": ["-noexit", "-file", "${env:APPDATA}PowerShellmy-init-script.ps1"]
}
},
"terminal.integrated.defaultProfile.windows": "My PowerShell"
}
Command Prompt
{
"terminal.integrated.profiles.windows": {
"cmder": {
"path": "C:\\WINDOWS\\System32\\cmd.exe",
"args": ["/K", "C:\\cmder\\vendor\\bin\\vscode_init.cmd"]
}
},
"terminal.integrated.defaultProfile.windows": "cmder"
}
I did this for accessing x64 Native Tools Command Prompt for 2022:
{
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"x64 Native": {
"path": [
"${env:windir}\\System32\\cmd.exe"
],
"args": [
"/K",
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat",
],
"icon": "terminal-cmd"
},
},
"terminal.integrated.defaultProfile.windows": "x64 Native",
}
If you use PowerShell you can add a PowerShell Script to your your profile in which you can execute what you want. Each development environment has 4 Profiles, stored in $Profile:
AllUsersAllHosts
AllUsersCurrentHost
CurrentUserAllHosts
CurrentUserCurrentHost
Eg create a profile in VSCode with
code $profile.CurrentUserAllHosts
Some more details

Define RabbitMQ policies in configuration file

I'd like to define mirroring for all my queues by default. I currently have to use rabbitmqctl once the node is up:
rabbitmqctl set_policy ha-all "" '{"ha-mode":"all"}'
If one of my nodes fail, I'd have to remember to re-execute that code on restart.
Is there a way to automatically configure my node to use mirrored queues?
Policy CAN be specified in a definition file, which can be referred to from your config file.
Example of how I have set a specific policy (not sure if ha can be specified in policy):
/etc/rabbitmq/rabbitmq.config
[
{rabbit,
[{vm_memory_high_watermark, 0.8}]
},
{rabbitmq_management,
[{listener, [{port, 15672}]},
{load_definitions, "/etc/rabbitmq/rabbitmq_definitions.json"},
{http_log_dir, "/var/log/rabbitmq/management_http.log"}]
}
].
/etc/rabbitmq/rabbitmq_definitions.json
{ "users":[
{"name":"rabbot","password_hash":"Cvse5iGOg20UqUq7Za9D1tatOJnMVDru4GHtxqc02g7zj5ur","tags":""},
{"name":"rabnet","password_hash":"CqqG2fwvH6xz64NpibGJx2M7ZCyFnR1BQBM+C0KH2qRPmVxF","tags":"administrator"}],
"vhosts":[
{"name":"/"}],
"permissions":[
{"user":"viabot","vhost":"VIA","configure":".*","write":".*","read":".*"},
{"user":"vianet","vhost":"VIA","configure":".*","write":".*","read":".*"}],
"parameters":[],
"policies":[
{"vhost":"VIA","name":"DLX","pattern":".*","apply-to":"queues","definition":{"dead-letter-exchange":"dead_letter"},"priority":0}
],
"queues":[
{"name":"store_to_es","vhost":"VIA","durable":true,"auto_delete":false,"arguments":{}},
{"name":"store_to_mongodb","vhost":"VIA","durable":true,"auto_delete":false,"arguments":{}}
],
"exchanges":[
{"name":"data_incoming","vhost":"VIA","type":"fanout","durable":true,"auto_delete":false,"internal":false,"arguments":{}},
{"name":"sms_incoming","vhost":"VIA","type":"fanout","durable":true,"auto_delete":false,"internal":false,"arguments":{}}
],
"bindings":[
{"source":"data_incoming","vhost":"VIA","destination":"store_to_es","destination_type":"queue","routing_key":"","arguments":{}},
{"source":"sms_incoming","vhost":"VIA","destination":"store_to_mongodb","destination_type":"queue","routing_key":"","arguments":{}}
]
}
I am sharing this config file and definitions file as it was impossible to figure it out from the RabbitMQ web site.
Note: This config worked on RabbitMQ 3.6.1 running on Ubuntu 14.04
To add more details to IvanD's answer, this is how I did it.
First: sudo nano /etc/rabbitmq/rabbitmq.config (this command might be different depending on your OS)
[
{rabbit,
[
{default_vhost,<<"/">>},
{default_user,<<"someuser">>},
{default_pass,<<"somepassword">>},
{default_permissions, [<<".*">>, <<".*">>, <<".*">>]},
{default_user_tags, [administrator]}
]
},
{rabbitmq_management,
[{listener, [{port, 15672}]},
{load_definitions, "/etc/rabbitmq/rabbitmq_definitions.json"},
{http_log_dir, "/var/log/rabbitmq/management_http.log"}]
}
].
Then create the additional json: sudo nano /etc/rabbitmq/rabbitmq_definitions.json (this command might be different depending on your OS).
Its content:
{
"vhosts":[
{"name":"/"}
],
"policies":[
{"vhost":"/","name":"ha","pattern":"", "definition":{"ha-mode":"all","ha-sync-mode":"automatic","ha-sync-batch-size":5}}
]
}
IMPORTANT NOTE: The ha-sync-batch-size is only supported in RabbitMQ versions above 3.6.0! https://www.rabbitmq.com/ha.html#sync-batch-size
If your Rabbit is older than that, remove the setting from the rabbitmq_definitions.json.
I'm using Ubuntu 14.04 Trusty and RabbitMQ v.3.6.2.
Yes, You can load policies, queues, exchanges, bindings, users and much more directly on restart using definition import at load time.
Preconfigure you Rabbit
Go to http://localhost:15672 Admin -> Policies page and create a new policy you need:
You may also preconfigure queues and other things.
Dump definitions
curl -s -H "Accept:application/json" -u guest:guest http://localhost:15672/api/definitions > definitions.json
You can also dump your definitions using web interface. Open Overview tab, scroll down:
(!!!) Alter definitions.json, so as to keep things you need on restart only.
There will be section withing your policies, keep it:
...
"policies": [
{
"vhost": "/",
"name": "ha-all",
"pattern": "",
"apply-to": "all",
"definition": {
"ha-mode": "all"
},
"priority": 0
}
]
...
Load definitions on restart
Put that definitions.json nearby your rabbit and add this line to rabbit.conf. No need to use old format:
management.load_definitions = /path/to/definitions.json
So as to load something after restart use cli tools.
Paying tribute to #IvanD since my answer is pretty much the same as his own but reveals detailed steps and new config format usage. Not enough space in comment.
Policy can't be set in the rabbitmq.config file. One workaround is to start rmq using an init script and put the rabbitmqctl command inside there so that it is run whenever rmq starts or restarts.
Finally I found something which worked:
No need of configMap or rabbitmq.config files.
Under
containers:
...
...
...
lifecycle:
postStart:
exec:
command: ["/bin/sh","-c","rabbitmq-plugins --offline enable rabbitmq_management;until rabbitmqctl node_health_check; do sleep 5;done;rabbitmqctl set_policy ha-all \".\" '{\"ha-mode\":\"all\", \"ha-sync-mode\":\"automatic\"}' --apply-to all --priority 0;"]