1 -include ../config/default
2 -include ../config/$(shell hostname)
4 # Guess where lxc data is and default to /usr/share/lxc
5 LXC_DATA:=$(shell [ -d /usr/share/lxc ] && echo /usr/share/lxc || ([ -d /usr/lib/lxc ] && echo /usr/lib/lxc))
6 LXC_DATA:=$(shell [ -z "$(LXC_DATA)" ] && echo /usr/share/lxc || echo "$(LXC_DATA)")
7 TEMPLATELIST:=$(LXC_DATA)/templates/lxc-debian7 $(LXC_DATA)/templates/lxc-debian6 $(LXC_DATA)/templates/lxc-centos5 $(LXC_DATA)/templates/lxc-centos6
9 default: checkdepends installtemplate
12 @echo "read the Makefile to see available targets"
15 [ -d /cgroup ] || ( if [ $(shell id -u) != "0" ] then; echo "you should be root to run this" ; else; mkdir /cgroup; fi
17 checkmount: checkfstab /cgroup
18 grep -q 0 /cgroup/cpuset.cpus || mount /cgroup
21 @grep ^cgroup /etc/fstab || (echo "You need to add cgroup entry to fstab 'cgroup /cgroup cgroup defaults 0 0'" && false)
23 checkdepends: $(LXC_DATA) /lib/bridge-utils /usr/bin/netmask /usr/sbin/rinse /usr/sbin/tunctl
26 @[ -d $@ ] || sudo apt-get install lxc
29 @[ -d $@ ] || sudo apt-get install bridge-utils
32 @[ -f $@ ] || sudo apt-get install netmask
35 @[ -f $@ ] || sudo apt-get install rinse
38 @[ -f $@ ] || sudo apt-get install uml-utilities
41 @grep -q '^iface br0 inet' /etc/network/interfaces || (echo "Please setup network bridging" && false)
44 [ -e ssh ] || (echo "You need a ssh dir containing host keys like /etc/ssh_host_*" && false)
47 echo "debian7.local" > $(VMROOT)/rootfs/etc/hostname
48 grep -q debian7.local $(VMROOT)/rootfs/etc/hosts || echo "$(IPDEBBASE).$(VEIDDEB) debian7.local debian7" >> $(VMROOT)/rootfs/etc/hosts
51 @[ $(shell id -u) = "0" ] || (echo "you should be root to run this" ; exit 1)
59 installtemplate: $(TEMPLATELIST)
64 $(LXC_DATA)/templates/lxc-debian6: lxc-debian6 $(LXC_DATA) Makefile
65 cat lxc-debian6 | sed 's!http://cdn.debian.net/debian/!$(DEBMIRROR)!' > $(LXC_DATA)/templates/lxc-debian6
66 chmod 755 $(LXC_DATA)/templates/lxc-debian6
68 $(LXC_DATA)/templates/lxc-debian7: lxc-debian7 $(LXC_DATA) Makefile
69 cat lxc-debian7 | sed 's!http://cdn.debian.net/debian/!$(DEBMIRROR)!' > $(LXC_DATA)/templates/lxc-debian7
70 chmod 755 $(LXC_DATA)/templates/lxc-debian7
72 $(LXC_DATA)/templates/lxc-centos5: lxc-centos5 $(LXC_DATA) Makefile
73 cp lxc-centos5 $(LXC_DATA)/templates/
75 $(LXC_DATA)/templates/lxc-centos6: lxc-centos6 $(LXC_DATA) Makefile
76 cp lxc-centos6 $(LXC_DATA)/templates/
78 /usr/share/lxc/templates/lxc-centos5: lxc-centos5 /usr/share/lxc
79 cp lxc-centos5 /usr/share/lxc/templates/
82 sudo /usr/bin/lxc-create -n dhdebian6.local -f config.debian6 -t debian6
83 sudo /usr/bin/lxc-create -n dhdebian7.local -f config.debian7 -t debian7
85 createcos: /usr/bin/netmask /usr/bin/rinse
86 sudo /usr/bin/lxc-create -n dhcentos5.local -f config.centos5 -t centos5
89 sudo LANG=C /usr/bin/lxc-start -n dhdebian7.local -d
92 sudo LANG=C /usr/bin/lxc-stop -n dhdebian7.local
95 sudo LANG=C /usr/bin/lxc-start -n dhcentos5.local -d
98 sudo LANG=C /usr/bin/lxc-stop -n dhcentos5.local
101 sudo LANG=C /usr/bin/lxc-stop -n dhdebian7.local
102 sudo LANG=C /usr/bin/lxc-destroy -n dhdebian7.local
105 sudo LANG=C /usr/bin/lxc-stop -n dhcentos5.local
106 sudo LANG=C /usr/bin/lxc-destroy -n dhcentos5.local