Skip to content

Instantly share code, notes, and snippets.

@Padam87
Last active April 5, 2016 11:33
Show Gist options
  • Save Padam87/4a294688b0067a96c71139a507f6fb0c to your computer and use it in GitHub Desktop.
Save Padam87/4a294688b0067a96c71139a507f6fb0c to your computer and use it in GitHub Desktop.
LXC scripts
#!/bin/bash -
#===============================================================================
#
# FILE: clone-sandbox.sh
#
# USAGE: ./clone-sandbox.sh
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Adam Prager (),
# ORGANIZATION:
# CREATED: 03/17/2016 17:42
# REVISION: ---
#===============================================================================
set -o nounset # Treat unset variables as an error
name="sandbox$1"
defaultIp=253
ip="10.0.3.$(($defaultIp-$1))"
ssh=$((22000+$1))
echo "Cloning sandbox with the following parameters:"
echo "Name: $name"
echo "Ip: $ip"
echo "Ssh port: $ssh"
lxc-stop -n sandbox-default
lxc-clone sandbox-default $name
echo "dhcp-host=$name,$ip" >> /etc/lxc/dnsmasq.conf
iptables -t nat -D PREROUTING -p tcp -i eth0 --dport $ssh -j DNAT --to-destination $ip:22
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport $ssh -j DNAT --to-destination $ip:22
/etc/init.d/iptables-persistent save
echo "server {
listen 80;
server_name $name.sf14.net;
location / {
proxy_pass http://$name.lxc;
proxy_set_header Host \$host;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header Accept-Encoding \"\";
}
}" > /etc/nginx/sites-available/$name
ln -s /etc/nginx/sites-available/$name /etc/nginx/sites-enabled/$name
service lxc stop
service network-manager restart
service dnsmasq restart
service lxc start
service nginx restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment