Question to the developers: Is it possible to use multiple "event_notification_commands" to run different scripts in "repmgr.conf"?
Closed this issue · 4 comments
Good time of the day!
I have a question about "Event Notifications" and how to configure it in repmgr.conf.
The question is - is it possible to add several "event_notification_command" commands to repmgr.conf that call different scripts for different events?
For example, can the following lines be added to the "repmgr.conf" configuration file?:
# Call the first "startlxc" script on events 'repmgrd_upstream_reconnect, standby_recovery':
event_notification_command='sudo /etc/keepalived/startlxc %n %e %s "%d"'
event_notifications='repmgrd_upstream_reconnect,standby_recovery'
##
# Call the second stbunreg script on the 'child_node_new_connect' event:
event_notification_command='sudo /etc/postgresql/12/main/stbunreg %n %e %s "%d"'
event_notifications='child_node_new_connect'
I have already tried to add such a configuration to the file, but the result is very strange - in some cases, when the specified events occurred, the repmgrd daemon started the scripts correctly.
But in some cases, the script located in the file at the top was started.
In general, does repmgr support such a configuration?
It is very necessary to run different scripts for different events!
I very much ask the developers to answer my question!!!
This won't work - repmgr
expects to find only one event_notification_command
in the file, and if more than one entry is present, the value of the last entry is used.
event_notifications
is slightly different - it's maintained internally as a list, and multiple event_notifications
entries will result in the contents of each entry being appended to the list of notifications.
In repmgr 5.2 and later you can see how repmgr
interprets the configuration file with the --dump-config
option; your settings would result in:
repmgr -f /tmp/node_2/repmgr.conf --dump-config | grep event_notification
event_notification_command|sudo /etc/postgresql/12/main/stbunreg %n %e %s "%d"
event_notifications|repmgrd_upstream_reconnect,standby_recovery,child_node_new_connect
Note: the configuration file parsing was rewritten for 5.2, you may get a different result in earlier versions.
The normal solution for this issue is to create a wrapper script which accepts the %e
option (as well as whatever other options you want to pass) and executes the appropriate script.
Thank you very much for your reply!
Are multiple "event_notification_command" entries expected in the future?
It would be quite useful to run different small scripts on different events, instead of one huge script.
Are multiple "event_notification_command" entries expected in the future?
There are no plans for this kind of feature.
It would be quite useful to run different small scripts on different events, instead of one huge script.
As mentioned, the simplest workaround is a small wrapper script which calls whatever script you want based on the event notification, something like this:
#!/bin/bash
set -x
set -u
EVENT=$1
THING=$2
OTHER_THING=$3
if [[ $EVENT == 'foo' ]]; then
/path/to/script1 $THING $OTHER_THING
elif [[ $EVENT == 'bar' ]]; then
/path/to/script2 $THING $OTHER_THING
fi
Yes. I understand your recommendations.
Thanks a lot! I close my question.