Skip to content

Instantly share code, notes, and snippets.

@fgrehm
Last active December 20, 2015 14:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fgrehm/8084ac5442e9cb2b93fc to your computer and use it in GitHub Desktop.
Save fgrehm/8084ac5442e9cb2b93fc to your computer and use it in GitHub Desktop.
vagrant-lxc 0.5.0 goodies
# On your host
curl Vagrantfile ...
vagrant up vbox --provider=virtualbox
vagrant ssh vbox

# From the VBox VM
cd /vagrant
vagrant up lxc

# On your host
curl http://localhost:8081/unicorn
ssh vagrant@localhost -p 2000 
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define :vbox do |vb_config|
vb_config.vm.box = "quantal64"
vb_config.vm.box_url = 'https://github.com/downloads/roderik/VagrantQuantal64Box/quantal64.box'
vb_config.vm.hostname = 'vbox'
vb_config.vm.network :forwarded_port, guest: 80, host: 8081
vb_config.vm.network :forwarded_port, guest: 2221, host: 2000
# Comment out if you don't have plans to use https://github.com/fgrehm/vagrant-cachier
vb_config.cache.auto_detect = true
vb_config.vm.provision :shell, :inline => %[
wget -q -O - 'http://raw.github.com/gist/8084ac5442e9cb2b93fc/03-provision-vbox.sh' | bash
]
end
config.vm.define :lxc do |lxc_config|
lxc_config.vm.box = 'raring64'
lxc_config.vm.box_url = 'http://bit.ly/vagrant-lxc-raring64-2013-07-12'
lxc_config.vm.hostname = 'lxc'
lxc_config.vm.network :forwarded_port, guest: 22, host: 2221
# We need to use a directory outside of Vagrant's shared folders
lxc_config.vm.synced_folder '~/unicorns', '/home/vagrant/unicorns'
lxc_config.vm.provision :shell, inline: %[
wget -q -O - 'http://raw.github.com/gist/8084ac5442e9cb2b93fc/04-provision-lxc.sh' | bash
]
lxc_config.vm.provider :lxc do |lxc|
lxc.customize 'cgroup.memory.limit_in_bytes', '400M'
end
end
end
#!/usr/bin/env bash
set -e
if ! $(which lxc-create > /dev/null); then
apt-get update &&
apt-get upgrade -y &&
apt-get install -y lxc redir linux-image-generic linux-headers-generic curl
fi
if ! $(which nginx > /dev/null); then
apt-get install -y nginx
UNICORNS_DIR='/home/vagrant/unicorns'
mkdir -p ${UNICORNS_DIR}/{tmp,log}
cat <<-STR > ${UNICORNS_DIR}/nginx.conf
upstream unicorn_server {
server unix:${UNICORNS_DIR}/tmp/unicorn.sock fail_timeout=0;
}
server {
location /unicorn {
proxy_pass http://unicorn_server;
}
}
STR
chown -R vagrant:vagrant ${UNICORNS_DIR}
unlink /etc/nginx/sites-enabled/default
ln -s ${UNICORNS_DIR}/nginx.conf /etc/nginx/sites-enabled/rack-app
service nginx start
fi
if ! $(which vagrant > /dev/null); then
wget http://files.vagrantup.com/packages/7ec0ee1d00a916f80b109a298bab08e391945243/vagrant_1.2.7_x86_64.deb -O /tmp/vagrant.deb -q
dpkg -i /tmp/vagrant.deb
fi
if ! $(grep -q 'VAGRANT_DEFAULT_PROVIDER=lxc' /home/vagrant/.bashrc); then
echo 'export VAGRANT_DEFAULT_PROVIDER=lxc' >> /home/vagrant/.bashrc
fi
VAGRANT_HOME=/home/vagrant/.vagrant.d su -p vagrant -c '
if ! $(vagrant plugin list | grep -q lxc); then
vagrant plugin install vagrant-lxc
fi
'
if [ `uname -r` = 3.5.0-17-generic ]; then
echo ""
echo "Please restart the machine with 'vagrant reload vbox'"
fi
#!/usr/bin/env bash
set -e
if ! (gem list | grep -q 'unicorn'); then
apt-get update
apt-get install -y ruby1.9.1-dev build-essential
gem install unicorn foreman --no-ri --no-rdoc
fi
UNICORNS_DIR=/home/vagrant/unicorns
mkdir -p ${UNICORNS_DIR}/{tmp,log}
#touch ${UNICORNS_DIR}/tmp/unicorn.sock
if ! [ -f ${UNICORNS_DIR}/config.rb ]; then
cat <<-STR > ${UNICORNS_DIR}/config.rb
worker_processes 1
working_directory "${UNICORNS_DIR}"
listen "${UNICORNS_DIR}/tmp/unicorn.sock", :backlog => 64
pid "${UNICORNS_DIR}/tmp/unicorn.pid"
stderr_path "${UNICORNS_DIR}/log/unicorn.stderr.log"
stdout_path "${UNICORNS_DIR}/log/unicorn.stdout.log"
STR
fi
if ! [ -f ${UNICORNS_DIR}/Procfile ]; then
cat <<-STR > ${UNICORNS_DIR}/Procfile
web: unicorn -c config.rb
STR
fi
if ! [ -f ${UNICORNS_DIR}/config.ru ]; then
cat <<-STR > ${UNICORNS_DIR}/config.ru
run Proc.new {|env| [200, {"Content-Type" => "text/html"}, ["Hello LXC!\\n"]]}
STR
fi
chown -R vagrant:vagrant ${UNICORNS_DIR}
if ! [ -f /etc/init/unicorn.conf ]; then
cd $UNICORNS_DIR && sudo foreman export -a unicorn -u vagrant upstart /etc/init
start unicorn
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment