Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Fix mongo cattle template #92

Merged
merged 1 commit into from
Feb 27, 2017
Merged

Conversation

galal-hussein
Copy link
Contributor

Fix the way to fetch local IP address of the container.

@@ -3,11 +3,11 @@ DIG=/opt/rancher/bin/dig

function cluster_init {
sleep 10
MYIP=$(ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1 | sed -n 2p)
MYIP=$(ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you use giddyup ip myip in a new'ish version it returns the container ip from metadata.

$DIG A $MONGO_SERVICE_NAME +short > ips.tmp
mongo --eval "printjson(rs.initiate())"
for member in $(cat ips.tmp); do
if [ $member != $MYIP ]; then
if [ "$member" != $MYIP ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need quotes on MYIP as well?

@galal-hussein
Copy link
Contributor Author

@cloudnautique I removed the use of ip and dig and replaced it with giddyup.

labels:
io.rancher.container.hostname_override: container_name
io.rancher.container.start_once: true
image: rancher/mongodb-conf:v0.1.0
image: husseingalal/mongodb-conf:v0.2.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it lives here.. should be rancher.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cloudnautique yeah that's wrong, I was testing with my image and forgot to change it

@@ -16,6 +19,6 @@ function scaleup {
}

# Script starts here
if [ $($DIG A $MONGO_SERVICE_NAME +short | wc -l) -gt 3 ]; then
if [ $($GIDDYUP ip stringify --delimiter " " | wc -w) -gt 3 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are just getting the set scale? giddyup service scale should do it I think.

@@ -27,7 +30,7 @@ function find_master {
}
# Script starts here
# wait for mongo to start
while [ `$DIG A $MONGO_SERVICE_NAME +short | wc -l` -lt 3 ]; do
while [ `$GIDDYUP ip stringify --delimiter " " | wc -w` -lt 3 ]; do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want giddyup service wait scale... check the docs.. but essentially it gates until set scale and the number of containers that exist are equal.

@galal-hussein
Copy link
Contributor Author

@cloudnautique ^

@@ -1,13 +1,16 @@
#!/bin/bash
DIG=/opt/rancher/bin/dig

set -x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typically we don't deploy with -x.. if you want it, maybe put it behind a debug env var or something. CATTLE_SCRIPT_DEBUG I think is the convention...

MYIP=$(ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1 | sed -n 2p)
$DIG A $MONGO_SERVICE_NAME +short > ips.tmp
MYIP=$($GIDDYUP ip myip)
$GIDDYUP ip stringify --delimiter " " > ips.tmp
mongo --eval "printjson(rs.initiate())"
for member in $(cat ips.tmp); do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something more like this, to avoid writing/reading a file

for member in $(giddyup ip stringify --delimiter " "); do
  if [ "$member" != "$MYIP" ]; then
   ...
  fi
done

@@ -1,5 +1,7 @@
#!/bin/bash

set -x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

@@ -1,10 +1,13 @@
#!/bin/bash

set -x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

@galal-hussein
Copy link
Contributor Author

@cloudnautique ^

@brettneese
Copy link

brettneese commented Feb 9, 2017

please merge this!! :)

right now the mongo catalog item is broken

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants