Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- if [ $# -ne 2 ]; then
- echo "Usage: `basename $0` name ip"
- exit 1
- fi
- TEMPLATE=${TEMPLATE:-"alpine"}
- NAME=$1
- IP=$2
- LXC_PATH=/srv/virt/lxc/
- DHCP_HOSTS=/srv/virt/dhcp-hosts
- if [ -d $LXC_PATH/$NAME ]; then
- echo "$NAME already exists. Please choose another container name"
- exit 2
- fi
- if `grep -q $IP $DHCP_HOSTS`; then
- echo "$IP is already taken. Please choose another IP for $NAME"
- exit 2
- fi
- echo " → Creating LXC"
- lxc-create -n $NAME -t $TEMPLATE
- if [ $? -ne 0 ]; then
- echo "\`lxc-create -n $NAME -t $TEMPLATE\` failed."
- exit 3
- fi
- echo " → Configuring dnsmasq"
- HW_ADDR=`grep lxc.network.hwaddr $LXC_PATH/$NAME/config | sed 's/lxc.network.hwaddr = //'`
- echo "$HW_ADDR,$IP,$NAME" >> $DHCP_HOSTS
- echo "$IP $NAME" >> /etc/hosts
- service dnsmasq reload
- echo " → Creating service"
- ln -s lxc /etc/init.d/lxc.$NAME
- echo -e "\n type \`service lxc.$NAME start\` to start the LXC\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement