civet.lua 919 B

123456789101112131415161718192021222324252627282930313233343536
  1. local civet = {}
  2. civet.port=12345
  3. function civet.start(docroot)
  4. -- TODO: use a property
  5. docroot = docroot or 'test/ci_tests/01_basic/docroot'
  6. assert(io.popen('./civetweb'
  7. .. " -listening_ports " .. civet.port
  8. .. " -document_root " .. docroot
  9. .. " > /dev/null 2>&1 &"
  10. ))
  11. -- wait until the server is listening (TODO: Linux only)
  12. while true do
  13. local f = assert(io.popen('netstat -an | grep '
  14. .. civet.port .. ' | grep -i listen'))
  15. local out = f:read('*all')
  16. if string.match(out, civet.port) then break end
  17. f:close()
  18. end
  19. end
  20. function civet.stop()
  21. os.execute('killall civetweb')
  22. -- wait until the server is listening (TODO: Linux only)
  23. while true do
  24. local f = assert(io.popen('netstat -an | grep '
  25. .. civet.port .. ' | grep -i listen'))
  26. local out = f:read('*all')
  27. if not string.match(out, civet.port) then break end
  28. f:close()
  29. end
  30. end
  31. return civet