setup.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. set -e
  3. # ADD /opendevin/plugins to PATH to make `jupyter_cli` available
  4. echo 'export PATH=$PATH:/opendevin/plugins/jupyter' >> ~/.bashrc
  5. export PATH=/opendevin/plugins/jupyter:$PATH
  6. # if user name is `opendevin`, add '/home/opendevin/.local/bin' to PATH
  7. if [ "$USER" = "opendevin" ]; then
  8. echo 'export PATH=$PATH:/home/opendevin/.local/bin' >> ~/.bashrc
  9. export PATH=$PATH:/home/opendevin/.local/bin
  10. fi
  11. # if user name is `root`, add '/root/.local/bin' to PATH
  12. if [ "$USER" = "root" ]; then
  13. echo 'export PATH=$PATH:/root/.local/bin' >> ~/.bashrc
  14. export PATH=$PATH:/root/.local/bin
  15. fi
  16. # Install dependencies
  17. pip install jupyterlab notebook jupyter_kernel_gateway
  18. # Create logs directory
  19. sudo mkdir -p /opendevin/logs && sudo chmod 777 /opendevin/logs
  20. # Run background process to start jupyter kernel gateway
  21. # write a bash function that finds a free port
  22. find_free_port() {
  23. local start_port="${1:-20000}"
  24. local end_port="${2:-65535}"
  25. for port in $(seq $start_port $end_port); do
  26. if ! ss -tuln | awk '{print $5}' | grep -q ":$port$"; then
  27. echo $port
  28. return
  29. fi
  30. done
  31. echo "No free ports found in the range $start_port to $end_port" >&2
  32. return 1
  33. }
  34. export JUPYTER_GATEWAY_PORT=$(find_free_port 20000 30000)
  35. jupyter kernelgateway --KernelGatewayApp.ip=0.0.0.0 --KernelGatewayApp.port=$JUPYTER_GATEWAY_PORT > /opendevin/logs/jupyter_kernel_gateway.log 2>&1 &
  36. export JUPYTER_GATEWAY_PID=$!
  37. echo "export JUPYTER_GATEWAY_PID=$JUPYTER_GATEWAY_PID" >> ~/.bashrc
  38. export JUPYTER_GATEWAY_KERNEL_ID="default"
  39. echo "export JUPYTER_GATEWAY_KERNEL_ID=$JUPYTER_GATEWAY_KERNEL_ID" >> ~/.bashrc
  40. echo "JupyterKernelGateway started with PID: $JUPYTER_GATEWAY_PID"
  41. # Start the jupyter_server
  42. export JUPYTER_EXEC_SERVER_PORT=$(find_free_port 30000 40000)
  43. echo "export JUPYTER_EXEC_SERVER_PORT=$JUPYTER_EXEC_SERVER_PORT" >> ~/.bashrc
  44. /opendevin/plugins/jupyter/execute_server > /opendevin/logs/jupyter_execute_server.log 2>&1 &
  45. export JUPYTER_EXEC_SERVER_PID=$!
  46. echo "export JUPYTER_EXEC_SERVER_PID=$JUPYTER_EXEC_SERVER_PID" >> ~/.bashrc
  47. echo "Execution server started with PID: $JUPYTER_EXEC_SERVER_PID"
  48. # Wait until /opendevin/logs/jupyter_kernel_gateway.log contains "is available"
  49. while ! grep -q "is available" /opendevin/logs/jupyter_kernel_gateway.log; do
  50. sleep 1
  51. done
  52. # Wait until /opendevin/logs/jupyter_execute_server.log contains "Jupyter kernel created for conversation"
  53. while ! grep -q "Jupyter kernel created for conversation" /opendevin/logs/jupyter_execute_server.log; do
  54. sleep 1
  55. done
  56. echo "Jupyter kernel ready."