Weird (not swarm) leader election challenge

Dear all,

I am not able to figure out how solve following swarm problem.

I have a master-slave application.
the master must be one
slaves can be many but cannot run on the same node as master
when the master dies, one of the slave nodes must kill a slave service and spawn another master (they use the same data volume so I have continuity).

I was trying to set up a keepalived cluster in my swarm cluster and make notification script set the tags respectively using docker in the container. This setup would let me use any chose nodes of the swarm to perform my task.
Unfortunately without much success

I was trying to run every few seconds a probe on each node to check if “I am the swarm leader” and set the tags on that basis. This actually works but I am stuck with swarm managers as the working nodes.

is there any other technique I am not aware of where I could define cluster on a subset of swarm nodes, lect leader on this sub-cluster and set tags respectively?

any ideas?

I guess constraint on leader could work too but it is not available in the swarm yet