setup.sh 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. set -e
  3. # Hardcoded to use the Python interpreter from the OpenDevin runtime client
  4. OPENDEVIN_PYTHON_INTERPRETER=/opendevin/miniforge3/bin/python
  5. # check if OPENDEVIN_PYTHON_INTERPRETER exists and it is usable
  6. if [ -z "$OPENDEVIN_PYTHON_INTERPRETER" ] || [ ! -x "$OPENDEVIN_PYTHON_INTERPRETER" ]; then
  7. echo "OPENDEVIN_PYTHON_INTERPRETER is not usable. Please pull the latest Docker image!"
  8. exit 1
  9. fi
  10. # Install dependencies
  11. $OPENDEVIN_PYTHON_INTERPRETER -m pip install jupyterlab notebook jupyter_kernel_gateway
  12. source ~/.bashrc
  13. # ADD /opendevin/plugins to PATH to make `jupyter_cli` available
  14. echo 'export PATH=$PATH:/opendevin/plugins/jupyter' >> ~/.bashrc
  15. export PATH=/opendevin/plugins/jupyter:$PATH
  16. # if user name is `opendevin`, add '/home/opendevin/.local/bin' to PATH
  17. if [ "$USER" = "opendevin" ]; then
  18. echo 'export PATH=$PATH:/home/opendevin/.local/bin' >> ~/.bashrc
  19. echo "export OPENDEVIN_PYTHON_INTERPRETER=$OPENDEVIN_PYTHON_INTERPRETER" >> ~/.bashrc
  20. export PATH=$PATH:/home/opendevin/.local/bin
  21. export PIP_CACHE_DIR=$HOME/.cache/pip
  22. fi
  23. # if user name is `root`, add '/root/.local/bin' to PATH
  24. if [ "$USER" = "root" ]; then
  25. echo 'export PATH=$PATH:/root/.local/bin' >> ~/.bashrc
  26. echo "export OPENDEVIN_PYTHON_INTERPRETER=$OPENDEVIN_PYTHON_INTERPRETER" >> ~/.bashrc
  27. export PATH=$PATH:/root/.local/bin
  28. export PIP_CACHE_DIR=$HOME/.cache/pip
  29. fi
  30. # Run background process to start jupyter kernel gateway
  31. # write a bash function that finds a free port
  32. find_free_port() {
  33. local start_port="${1:-20000}"
  34. local end_port="${2:-65535}"
  35. for port in $(seq $start_port $end_port); do
  36. if ! ss -tuln | awk '{print $5}' | grep -q ":$port$"; then
  37. echo $port
  38. return
  39. fi
  40. done
  41. echo "No free ports found in the range $start_port to $end_port" >&2
  42. return 1
  43. }
  44. export JUPYTER_GATEWAY_PORT=$(find_free_port 20000 30000)
  45. $OPENDEVIN_PYTHON_INTERPRETER -m \
  46. jupyter kernelgateway --KernelGatewayApp.ip=0.0.0.0 --KernelGatewayApp.port=$JUPYTER_GATEWAY_PORT > /opendevin/logs/jupyter_kernel_gateway.log 2>&1 &
  47. export JUPYTER_GATEWAY_PID=$!
  48. echo "export JUPYTER_GATEWAY_PID=$JUPYTER_GATEWAY_PID" >> ~/.bashrc
  49. export JUPYTER_GATEWAY_KERNEL_ID="default"
  50. echo "export JUPYTER_GATEWAY_KERNEL_ID=$JUPYTER_GATEWAY_KERNEL_ID" >> ~/.bashrc
  51. echo "JupyterKernelGateway started with PID: $JUPYTER_GATEWAY_PID"
  52. # Start the jupyter_server
  53. export JUPYTER_EXEC_SERVER_PORT=$(find_free_port 30000 40000)
  54. echo "export JUPYTER_EXEC_SERVER_PORT=$JUPYTER_EXEC_SERVER_PORT" >> ~/.bashrc
  55. $OPENDEVIN_PYTHON_INTERPRETER /opendevin/plugins/jupyter/execute_server > /opendevin/logs/jupyter_execute_server.log 2>&1 &
  56. export JUPYTER_EXEC_SERVER_PID=$!
  57. echo "export JUPYTER_EXEC_SERVER_PID=$JUPYTER_EXEC_SERVER_PID" >> ~/.bashrc
  58. echo "Execution server started with PID: $JUPYTER_EXEC_SERVER_PID"
  59. # Wait until /opendevin/logs/jupyter_kernel_gateway.log contains "is available"
  60. while ! grep -q "at" /opendevin/logs/jupyter_kernel_gateway.log; do
  61. echo "Waiting for Jupyter kernel gateway to be available..."
  62. sleep 1
  63. done
  64. # Wait until /opendevin/logs/jupyter_execute_server.log contains "Jupyter kernel created for conversation"
  65. while ! grep -q "kernel created" /opendevin/logs/jupyter_execute_server.log; do
  66. echo "Waiting for Jupyter kernel to be created..."
  67. sleep 1
  68. done
  69. echo "Jupyter kernel ready."