dragonflow/devstack/etcd_driver

79 lines
2.1 KiB
Bash

#!/bin/bash
#
#
# ``plugin.sh`` calls the following methods in the sourced driver:
#
# - nb_db_driver_install_server
# - nb_db_driver_install_client
# - nb_db_driver_start_server
# - nb_db_driver_stop_server
# - nb_db_driver_clean
function install_configure_etcd {
# Install etcd from package sources (=> our PPA).
install_package etcd
# Stop the etcd service:
sudo service etcd stop || true
# Delete any existing etcd database:
sudo rm -rf /var/lib/etcd/*
# Mount a RAM disk at /var/lib/etcd:
sudo mount -t tmpfs -o size=512m tmpfs /var/lib/etcd
# Add the following to the bottom of /etc/fstab so that the RAM
# disk gets reinstated at boot time:
# tmpfs /var/lib/etcd tmpfs nodev,nosuid,noexec,nodiratime,size=512M 0 0
IP=`hostname -I | awk '{print $1}'`
# Edit /etc/init/etcd.conf: Find the line which begins exec
# /usr/bin/etcd and edit it, substituting for <controller_fqdn>
# and <controller_ip> appropriately.
# Configure an etcd master node.
sudo sed -i "s/exec.*/exec \/usr\/bin\/etcd --name=\"$HOSTNAME\" \
--advertise-client-urls=\"http:\/\/$REMOTE_DB_IP:2379,http:\/\/$REMOTE_DB_IP:4001\" \
--listen-client-urls=\"http:\/\/$REMOTE_DB_IP:2379,http:\/\/$REMOTE_DB_IP:4001\" \
--listen-peer-urls \"http:\/\/0.0.0.0:2380\" \
--initial-advertise-peer-urls \"http:\/\/$REMOTE_DB_IP:2380\" \
--initial-cluster-token \"$TOKEN\" \
--initial-cluster \"$HOSTNAME=http:\/\/$REMOTE_DB_IP:2380\" \
--initial-cluster-state \"new\"/" /etc/init/etcd.conf
# Start the etcd service:
sudo service etcd start
}
function nb_db_driver_install_server {
sudo apt-add-repository -y ppa:project-calico/kilo-testing
REPOS_UPDATED=False
install_configure_etcd
}
function nb_db_driver_install_client {
pip_install -I git+git://github.com/projectcalico/python-etcd.git
}
function nb_db_driver_status_server
{
TEMP_PIDS=`ps cax | grep etcd`
if [ -z "$TEMP_PIDS" ]; then
return 1
fi
return 0
}
function nb_db_driver_start_server {
return 0
}
function nb_db_driver_stop_server {
sudo service etcd stop || true
sudo umount /var/lib/etcd
}