Last active
July 28, 2016 11:26
-
-
Save mihok/ff38a9d885b017a886c920acd0834d8c to your computer and use it in GitHub Desktop.
Vagrant provision script and Upstart service files to install and run etcd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
description "etcd Service" | |
author "Matthew Mihok" | |
env ETCD_HOME=/opt/etcd-3.0.1 | |
env ETCD_DATA_DIR=/var/lib/etcd | |
env LOG_HOME=/var/log/etcd | |
# Run as etcd | |
setuid vagrant | |
setgid vagrant | |
# Make sure network and fs is up, and start in runlevels 2-5 | |
start on (net-device-up | |
and local-filesystems | |
and runlevel [2345]) | |
# Stop in runlevels 0,1 and 6 | |
stop on runlevel [016] | |
# automatically respawn, but if its respwaning too fast (5 times in 60 seconds, don't do that) | |
respawn | |
respawn limit 5 60 | |
# make sure node is there, the code directory is there | |
pre-start script | |
test -d $ETCD_DATA_DIR || { stop; exit 0; } | |
test -x $ETCD_HOME/etcd || { stop; exit 0; } | |
end script | |
# cd to code path and run node, with the right switches | |
script | |
export ETCD_NAME=`cat /etc/hostname` | |
exec etcd >> $LOG_HOME/etcd.log 2>&1 | |
end script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
env ETCD_DATA_DIR="/var/lib/etcd" | |
env ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" | |
env ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" | |
env ETCD_INITIAL_ADVERTISE_PEER_URLS="http://MY_IP:2380" | |
env ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379" | |
env ETCD_INITIAL_CLUSTER="MY_CLUSTER" | |
env ETCD_INITIAL_CLUSTER_STATE="MY_CLUSTER_STATE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -x; | |
# etcd | |
cd /opt/ | |
# Download the release | |
curl -L https://github.com/coreos/etcd/releases/download/v3.0.1/etcd-v3.0.1-linux-amd64.tar.gz -o etcd-3.0.1.tar.gz | |
# Create the directory the binaries will live in | |
mkdir /opt/etcd-3.0.1 | |
# Extract the contents of the release | |
tar -zxvf etcd-3.0.1.tar.gz -C etcd-3.0.1 --strip-components=1 | |
# Make symlinks so we can access the binaries | |
ln -s /opt/etcd-3.0.1/etcd /usr/local/bin/etcd | |
ln -s /opt/etcd-3.0.1/etcdctl /usr/local/bin/etcdctl | |
# Copy our Upstart script | |
cp /vagrant/etcd.conf /etc/init/etcd.conf | |
# Update our Upstart override files, and copy it into place | |
sed -e "s/MY_IP/$IP/g" -e "s/MY_CLUSTER_STATE/$CLUSTER_STATE/g" -e "s/MY_CLUSTER/$CLUSTER/g" </vagrant/etcd.override >/etc/init/etcd.override | |
# Creaate etcd's data director | |
mkdir /var/lib/etcd | |
chown vagrant:vagrant /var/lib/etcd | |
# Create etcd's logging directory | |
mkdir /var/log/etcd | |
chown vagrant:vagrant /var/log/etcd | |
# Start the service | |
start etcd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment