machine 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/bash
  2. MAXLOADMINI=10
  3. MAXLOADMEDIUM=25
  4. CMD="qemu-system-x86_64"
  5. MEMSMINI=54
  6. MEMSMEDIUM=212
  7. case $1 in
  8. status )
  9. case $2 in
  10. html )
  11. if ps -p $(cat svmm_db/pids/$3.pid) > /dev/null
  12. then
  13. echo "<div style='display:inline;color:#00ff00;'>Running</div>"
  14. else
  15. echo "<div style='display:inline;color:#ff0000;'>Stopped</div>"
  16. fi
  17. ;;
  18. return )
  19. if ps -p $(cat svmm_db/pids/$3.pid) > /dev/null
  20. then
  21. echo "1"
  22. else
  23. echo "0"
  24. fi
  25. ;;
  26. esac
  27. ;;
  28. start-mini )
  29. $CMD -enable-kvm -daemonize -display none -smp 1 -hda svmm_db/disks/$2.img -m ${MEMSMINI}M -net nic,model=pcnet -net user,hostfwd=tcp::${2}80-:80,hostfwd=tcp::${2}22-:22,hostfwd=tcp::${2}66-:6666,hostfwd=tcp::${2}21-:21,hostfwd=tcp::${2}67-:6667 -pidfile svmm_db/pids/$2.pid
  30. sleep 10
  31. ./setcpulimit $(cat svmm_db/pids/$2.pid) $MAXLOADMINI > /dev/null &
  32. #./setkilltimer $(cat svmm_db/pids/$2.pid) $2 > /dev/null &
  33. ;;
  34. start-medium )
  35. $CMD -enable-kvm -daemonize -display none -smp 1 -hda svmm_db/disks/$2.img -m ${MEMSMEDIUM}M -net nic,model=pcnet -net user,hostfwd=tcp::${2}80-:80,hostfwd=tcp::${2}22-:22,hostfwd=tcp::${2}66-:6666,hostfwd=tcp::${2}65-:25665,hostfwd=tcp::${2}21-:21,hostfwd=tcp::${2}67-:6667 -pidfile svmm_db/pids/$2.pid
  36. sleep 20
  37. ./setcpulimit $(cat svmm_db/pids/$2.pid) $MAXLOADMEDIUM > /dev/null &
  38. #./setkilltimer $(cat svmm_db/pids/$2.pid) $2 > /dev/null &
  39. ;;
  40. stopall )
  41. killall $CMD
  42. ;;
  43. stop )
  44. kill -TERM $(cat svmm_db/pids/$2.pid)
  45. ;;
  46. del )
  47. kill -TERM $(cat svmm_db/pids/$2.pid)
  48. rm svmm_db/disks/$2.img
  49. rm svmm_db/pids/$2.pid
  50. ;;
  51. * )
  52. echo "Usage: machine {start-mini|start-large|status|stop|stopall} {_|html|return} [vm id]";;
  53. esac