Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions bin/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ def get_environ(key, default):
SESSION_NAME = get_environ('SESSION_NAME', 'mongodb-replica-set-lock')
SESSION_TTL = int(get_environ('SESSION_TTL', 60))

# consts for node state
PRIMARY = 'mongodb-replicaset'
#SECONDARY = 'mongodb-secondary'
# name of containerpilot job, consul service, and mongo replicaset
SERVICE_NAME = get_environ('REPLICASET', 'mongodb-replicaset')

# key where primary will be stored in consul
PRIMARY_KEY = get_environ('PRIMARY_KEY', 'mongodb-primary')
Expand Down Expand Up @@ -335,7 +334,7 @@ def mongo_update_replset_config(local_mongo, hostname):
repl_config = repl_config['config']

# use consul health to get our healthy services
index, consul_services = consul.health.service(PRIMARY)
index, consul_services = consul.health.service(SERVICE_NAME)

# translate the name stored by consul to be the "host" name stored
# in mongo config, skipping any non-mongo services
Expand Down Expand Up @@ -388,9 +387,7 @@ def mongo_update_replset_config(local_mongo, hostname):
sys.exit(1)

def consul_to_mongo_hostname(service):
# if name.startswith(SECONDARY + '-'):
# prefix = SECONDARY + '-'
if service['ID'].startswith(PRIMARY + '-'):
if service['ID'].startswith(SERVICE_NAME + '-'):
return service['Address'] + ':' + str(service['Port'])
else:
return None
Expand Down
10 changes: 5 additions & 5 deletions etc/containerpilot.json5
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
},
{{ end }}
{
name: "mongodb-replicaset",
name: "{{ .REPLICASET | default "mongodb-replicaset" }}",
port: 27017,
exec: "mongod --replSet={{ if .REPLICASET }}{{ .REPLICASET }}{{ else }}joyent{{ end }}",
exec: "mongod --replSet={{ .REPLICASET | default "mongodb-replicaset" }}",
when: {
source: "preStart",
once: "exitSuccess"
Expand All @@ -41,17 +41,17 @@
},
},
{
name: "onchange-mongo",
name: "onchange-{{ .REPLICASET | default "mongodb-replicaset" }}",
exec: "python /usr/local/bin/manage.py on_change",
when: {
source: "watch.mongodb-replicaset",
source: "watch.{{ .REPLICASET | default "mongodb-replicaset" }}",
each: "changed"
}
},
],
watches: [
{
name: "mongodb-replicaset",
name: "{{ .REPLICASET | default "mongodb-replicaset" }}",
interval: 2
}
]
Expand Down