Skip to content

Instantly share code, notes, and snippets.

View pranavcode's full-sized avatar

Pranav Kulkarni pranavcode

View GitHub Profile
@pranavcode
pranavcode / django-consul.sh
Created April 1, 2019 09:41
Velotio - HashiCorp Consul Part 2 - Django Web Application - Run Consul agent on a Django node
consul agent -bind 33.10.0.10 \
-advertise 33.10.0.10 \
-join consul_server \
-node web_1 \
-dns-port 53 \
-data-dir /data \
-config-dir /etc/consul.d \
-enable-local-script-checks
@pranavcode
pranavcode / django.json
Created April 1, 2019 09:10
Velotio - HashiCorp Consul Part 2 - Django Web Application Service Definition
{
"service": {
"name": "web",
"port": 8000,
"tags": [
"web",
"application",
"urlprefix-/web"
],
"check": {
@pranavcode
pranavcode / mongo-consul.sh
Created April 1, 2019 08:44
Velotio - HashiCorp Consul Part 2 - MongoDB Replica Set - Run Consul agent on a MongoDB node
consul agent -bind 33.10.0.3 \
-advertise 33.10.0.3 \
-join consul_server \
-node mongo_1 \
-dns-port 53 \
-data-dir /data \
-config-dir /etc/consul.d \
-enable-local-script-checks
@pranavcode
pranavcode / mongo_secondary_check.sh
Created April 1, 2019 05:28
Velotio - HashiCorp Consul Part 2 - MongoDB Replica Set - Check Secondary instance using shell script
#!/bin/bash
mongo_secondary=$(mongo --quiet --eval 'JSON.stringify(db.isMaster())' | jq -r .secondary 2> /dev/null)
if [[ $mongo_secondary == false ]]; then
exit 1
fi
echo "Mongo secondary healthy and reachable"
@pranavcode
pranavcode / mongo_primary_check.sh
Created April 1, 2019 05:25
Velotio - HashiCorp Consul Part 2 - MongoDB Replica Set - Check Primary instance using shell script
#!/bin/bash
mongo_primary=$(mongo --quiet --eval 'JSON.stringify(db.isMaster())' | jq -r .ismaster 2> /dev/null)
if [[ $mongo_primary == false ]]; then
exit 1
fi
echo "Mongo primary healthy and reachable"
@pranavcode
pranavcode / mongo_secondary.json
Created April 1, 2019 05:20
Velotio - HashiCorp Consul Part 2 - MongoDB Replica Set Secondary Instance Service Definition
{
"service": {
"name": "mongo-secondary",
"port": 27017,
"tags": [
"nosql",
"database"
],
"check": {
"id": "mongo_secondary_status",
@pranavcode
pranavcode / mongo_primary.json
Created April 1, 2019 05:15
Velotio - HashiCorp Consul Part 2 - MongoDB Replica Set Primary Instance Service Definition
{
"service": {
"name": "mongo-primary",
"port": 27017,
"tags": [
"nosql",
"database"
],
"check": {
"id": "mongo_primary_status",
@pranavcode
pranavcode / checks_toggler.sh
Created April 1, 2019 05:09
Velotio - HashiCorp Consul Part 2 - MongoDB Primary and Secondary instance service registration and deregistration
#!/bin/bash
# Wait until Mongo starts
while [[ $(ps aux | grep [m]ongod | wc -l) -ne 1 ]]; do
sleep 5
done
REGISTER_MASTER=0
REGISTER_SECONDARY=0
@pranavcode
pranavcode / django.json
Created March 30, 2019 20:26
Velotio - HashiCorp Consul Part 2 - Django app service definition with Fabio indentifiable tag
{
"service": {
"name": "web",
"port": 8000,
"tags": [
"web",
"application",
"urlprefix-/web"
],
"check": {
@pranavcode
pranavcode / django-wsgi-http-server-run.sh
Created March 30, 2019 19:36
Velotio - HashiCorp Consul Part 2 - Run Django app with Gunicorn WSGI HTTP server
gunicorn --bind 0.0.0.0:8000 --access-logfile - tweeter.wsgi:application