Skip to content

Instantly share code, notes, and snippets.

@amfred
Last active August 29, 2015 14:01
Show Gist options
  • Save amfred/cdf321ff883acbc3897a to your computer and use it in GitHub Desktop.
Save amfred/cdf321ff883acbc3897a to your computer and use it in GitHub Desktop.
A script that uses Chef to install a Eureka server on a SoftLayer Ubuntu compute instance.
#!/bin/bash
#=======================================================================
# bootstrapEurekaChefSoftLayer.sh
# © Copyright IBM Corporation 2014.
# LICENSE: MIT (http://opensource.org/licenses/MIT)
#=======================================================================
# Tested: Ubuntu 12.04 LTS Precise Pangolin Minimal Install 64 bit CCI
# http://knowledgelayer.softlayer.com/faqs/199
# What are the SoftLayer name server addresses?
# We have two addresses for Authoritative Name Servers and two addresses for Resolving Name Servers.
# Authoritative Name Servers
# ns1.softlayer.com 67.228.255.4
# ns2.softlayer.com 67.228.255.5
# Resolving Name Servers
# rs1.service.softlayer.com 10.0.80.11
# rs2.service.softlayer.com 10.0.80.12
cp /etc/resolv.conf /etc/resolv.conf.bak
echo 'nameserver 67.228.254.4
nameserver 67.228.255.5' >> /etc/resolv.conf
cp /etc/network/interfaces /etc/network/interfaces.bak
# Add an additional IP address for Eureka to use.
# Change the address, netmask, and gateway value for each new server.
# Use an address, netmask, and gateway from a private portable subnet here.
# You can order private portable subnets from SoftLayer.
# Wishlist: automate this info instead of hardcoding it into the script.
echo '
auto eth0:0
iface eth0:0 inet static
address 10.xxx.xxx.xxx
netmask 255.255.255.xxx
gateway 10.xxx.xxx.xxx
dns-nameservers 67.228.254.4 67.228.255.5' >> /etc/network/interfaces
ifdown eth0
ifup eth0
# A reboot is sometimes but not always needed here, for networking updates.
# install Chef and a few developer tools
cd $HOME
sudo apt-get update
sudo apt-get install git -y
sudo apt-get install curl -y --fix-missing
sudo apt-get install vim -y
sudo apt-get install sshpass -y
sudo curl -L https://www.opscode.com/chef/install.sh | sudo bash
cd $HOME
git clone git://github.com/opscode/chef-repo.git
mkdir -p chef-repo/.chef
CHEF_DIR="$HOME/chef-repo"
CHEF_CONF_DIR="$CHEF_DIR/.chef"
COOKBOOK_DIR="$CHEF_DIR/cookbooks"
NODE_DIR="$CHEF_DIR/nodes"
NODE_FILE_LOC="$NODE_DIR/eureka_server_1.json"
ROLE_DIR="$CHEF_DIR/roles"
ROLE_FILE_LOC="$ROLE_DIR/eureka_server.json"
SOLO_FILE_LOC="$CHEF_DIR/solo.rb"
mkdir -p $NODE_DIR
mkdir -p $ROLE_DIR
cd $COOKBOOK_DIR
git clone https://github.com/phillip/chef-eureka.git eureka
git clone https://github.com/socrata-cookbooks/java.git
git clone https://github.com/opscode-cookbooks/tomcat.git
git clone https://github.com/opscode-cookbooks/openssl.git
# Rather than forking git, just change 1 line in the recipe
# to use the IBM SoftLayer Eureka instead of the Netflix one
sed -i 's#git clone https://github.com/Netflix/eureka.git#https://github.com/EmergingTechnologyInstitute/eureka.git#g' $COOKBOOK_DIR/eureka/recipes/default.rb
# Use your own domain_name below instead of mydomain.com
echo '{
"json_class": "Chef::Role",
"name":"eureka_server",
"description":"Eureka server role",
"chef_type": "role",
"default_attributes": {
"java": {
"jdk_version": "7"
},
"tomcat": {
"base_version": "7"
},
"eureka": {
"name": "eureka-server",
"server_url": "",
"git_id": "master",
"port": "8080",
"service_url": {
"default": "http://localhost:8080/eureka/v2/"
},
"domain_name": "mydomain.com"
}
},
"run_list": [ "recipe[eureka]" ]
}' > $ROLE_FILE_LOC
# Wishlist: use a dynamic/calculated node name here instead of hardcoding it.
# Chef Solo pretty much ignores node names, so it's OK for now.
echo '{
"name":"eureka_server_1",
"run_list": [ "role[eureka_server]" ]
}' > $NODE_FILE_LOC
echo '
file_cache_path "'$CHEF_DIR'"
cookbook_path "'$COOKBOOK_DIR'"
' > $SOLO_FILE_LOC
# Wishlist: use a dynamic/calculated node-name here instead of hardcoding it.
# Chef Solo pretty much ignores node names, so it's OK for now.
sudo chef-solo -c $SOLO_FILE_LOC --node-name eureka_server_1 --json-attributes $NODE_FILE_LOC
@amfred
Copy link
Author

amfred commented May 14, 2014

See my other SoftLayer bootstrap scripts at https://github.com/amfred/softlayerbootstrap. They are listed in the README.md file. MIT license, strictly AS-IS, use at your own risk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment