server 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. MAXLOAD="50"
  3. case $1 in
  4. status )
  5. case $2 in
  6. html )
  7. if ps -p $(cat mtm_db/pids/$3.pid) > /dev/null
  8. then
  9. echo "<div style='display:inline;color:#00ff00;'>Running</div>"
  10. else
  11. echo "<div style='display:inline;color:#ff0000;'>Stopped</div>"
  12. fi
  13. ;;
  14. return )
  15. if ps -p $(cat mtm_db/pids/$3.pid) > /dev/null
  16. then
  17. echo "1"
  18. else
  19. echo "0"
  20. fi
  21. ;;
  22. esac
  23. ;;
  24. start-minetest )
  25. ((./mtm_db/worlds/$2/bin/minetestserver --logfile mtm_db/users/$2.slog --config mtm_db/worlds/$2/minetest.conf --world `pwd`/mtm_db/worlds/$2/worlds/world) & jobs -p > mtm_db/pids/$2.pid) &
  26. sleep 10
  27. ./setcpulimit $(cat mtm_db/pids/$2.pid) $MAXLOAD > /dev/null &
  28. mkdir -p mtm_db/worlds/$2/worlds/world/worldmods
  29. ;;
  30. start-multicraft )
  31. ((./mtm_db/worlds/$2/bin/multicraftserver --logfile mtm_db/users/$2.slog --config mtm_db/worlds/$2/minetest.conf --world `pwd`/mtm_db/worlds/$2/worlds/world) & jobs -p > mtm_db/pids/$2.pid) &
  32. sleep 20
  33. ./setcpulimit $(cat mtm_db/pids/$2.pid) $MAXLOAD > /dev/null &
  34. mkdir -p mtm_db/worlds/$2/worlds/world/worldmods
  35. ;;
  36. stopall )
  37. killall minetestserver
  38. killall multicraftserver
  39. ;;
  40. stop )
  41. kill -15 $(cat mtm_db/pids/$2.pid)
  42. sleep 15
  43. if ps -p $(cat mtm_db/pids/$2.pid) > /dev/null
  44. then
  45. kill -9 $(cat mtm_db/pids/$2.pid)
  46. fi
  47. ;;
  48. set-gamemode )
  49. echo "gameid = $3" >> mtm_db/worlds/$2/worlds/world/world.mt
  50. cp -a games/$3 mtm_db/worlds/$2/games/.
  51. ;;
  52. del )
  53. kill -9 $(cat mtm_db/pids/$2.pid)
  54. rm -r mtm_db/worlds/$2
  55. rm mtm_db/pids/$2.pid
  56. echo "false" > mtm_db/users/$2.pid.statuscode
  57. echo "<div style='display:inline;color:#ff0000;'>Stopped</div>" > mtm_db/users/$2.pid.status
  58. ;;
  59. del-debug ) rm mtm_db/worlds/$2/debug.txt;;
  60. mkmoddir ) mkdir mtm_db/worlds/$2/worlds/world/worldmods;;
  61. * )
  62. echo "Usage: machine {start-mini|start-large|status|stop|stopall} {_|html|return} [vm id]";;
  63. esac