Sorry no. The script was not that long so I will try and get it printed out and copied over. For now here is an outline of what it did (from memory).
The general strategy I ended up using was to pull the expected members from the Marathon API, sort them and then use that list to:
0) Start a script in the background to seed the replica set.
1) Exec the mongod process (without --fork or putting it in the background so mesos tracks the mongod process).
For the forked script:
0) Wait for the socket to open for the member we are starting.
1) Iterate through the list looking for a primary.
1.a) If a primary is found add all of the other members to the primary in sorted order.
1.b) If all of the adds worked: goto 4. If not goto 1.
2) If no primary is found look for a secondary.
2.a) For each secondary we find that thinks it knows who the primary is try and add the members to that primary.
2.b) If all of the adds worked: goto 4. If not goto 1.
3) If we did not find a valid primary then we probably dropped quorum. For my system it is more important to get the replica set running with some data than to find the latest data or an optimal set.
3.a) Find the first node. If it thinks it is a secondary (was a member before then) force a configuration change where it is the only member. (This could be made smarter to find the set of running nodes and try to figure out which has the most up to date data.)
3.b) Goto 1.
4) Determine the members of the replica set that should be removed based on the list in Marathon's API and from the primary. Remove any members from the replica set that should not be there.
Other things I remember:
Make sure your marathon settings are set so that only one member of the replica set is restarted at a time and that a new member is added before the old member is removed.
Also I wrote a custom script health check to check if the member is a primary or secondary before declaring the member "alive" that ensures that the members are fully sync'd before restarting the next member. I'll grab that script too.
Rob.