oasis.sh 805 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. CURRENT_DIR=$(pwd)
  3. cd "$CURRENT_DIR/src/server" || { echo "Directory not found: $CURRENT_DIR/src/server"; exit 1; }
  4. node SSB_server.js start &
  5. check_server_ready() {
  6. local host="127.0.0.1"
  7. local port="8008"
  8. node -e "
  9. const net = require('net');
  10. const client = new net.Socket();
  11. client.setTimeout(5000); // Set a timeout of 5 seconds
  12. client.connect($port, '$host', function() {
  13. client.end(); // Successfully connected, close the socket
  14. process.exit(0); // Exit with a success code
  15. });
  16. client.on('error', function(err) {
  17. process.exit(1); // Exit with error code if connection fails
  18. });
  19. "
  20. }
  21. until check_server_ready; do
  22. sleep 1
  23. done
  24. cd "$CURRENT_DIR/src/backend" || { echo "Directory not found: $CURRENT_DIR/src/backend"; exit 1; }
  25. node backend.js