From 23bbb968285e01113f4561310fbebb01df6f64f1 Mon Sep 17 00:00:00 2001 From: Joel Kuzmarski Date: Fri, 26 Apr 2019 07:40:25 -0500 Subject: [PATCH] Use REPLICASET variable throughout /etc and /bin scripts --- bin/manage.py | 11 ++++------- etc/containerpilot.json5 | 10 +++++----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/bin/manage.py b/bin/manage.py index f032e8c..1506120 100644 --- a/bin/manage.py +++ b/bin/manage.py @@ -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') @@ -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 @@ -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 diff --git a/etc/containerpilot.json5 b/etc/containerpilot.json5 index 89ea64b..4333b71 100644 --- a/etc/containerpilot.json5 +++ b/etc/containerpilot.json5 @@ -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" @@ -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 } ]