Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. if [ $# -ne 2 ]; then
  4. echo "Usage: `basename $0` name ip"
  5. exit 1
  6. fi
  7.  
  8. TEMPLATE=${TEMPLATE:-"alpine"}
  9. NAME=$1
  10. IP=$2
  11. LXC_PATH=/srv/virt/lxc/
  12. DHCP_HOSTS=/srv/virt/dhcp-hosts
  13.  
  14. if [ -d $LXC_PATH/$NAME ]; then
  15. echo "$NAME already exists. Please choose another container name"
  16. exit 2
  17. fi
  18.  
  19. if `grep -q $IP $DHCP_HOSTS`; then
  20. echo "$IP is already taken. Please choose another IP for $NAME"
  21. exit 2
  22. fi
  23.  
  24. echo " → Creating LXC"
  25. lxc-create -n $NAME -t $TEMPLATE
  26.  
  27. if [ $? -ne 0 ]; then
  28. echo "\`lxc-create -n $NAME -t $TEMPLATE\` failed."
  29. exit 3
  30. fi
  31.  
  32. echo " → Configuring dnsmasq"
  33. HW_ADDR=`grep lxc.network.hwaddr $LXC_PATH/$NAME/config | sed 's/lxc.network.hwaddr = //'`
  34. echo "$HW_ADDR,$IP,$NAME" >> $DHCP_HOSTS
  35. echo "$IP $NAME" >> /etc/hosts
  36. service dnsmasq reload
  37.  
  38. echo " → Creating service"
  39. ln -s lxc /etc/init.d/lxc.$NAME
  40. echo -e "\n type \`service lxc.$NAME start\` to start the LXC\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement