drumming102

Untitled

May 2nd, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ## Fix permissions of server directory
  4. if [ ! "$USER" = "" ]; then
  5. chown -R "$USER":"$USER" "$SERVER_DIR" &
  6. chmod 770 "$SERVER_DIR" &
  7. fi
  8.  
  9. ## Comment the following line out to let the script check if the server port
  10. ## is occupied and kill the occupying proccess if required
  11. exit 0
  12.  
  13. if [ ! "`which lsof`" = "" ]; then
  14.  
  15. #Convert IP to a format accepted by lsof
  16. if [ "$IP" = "0.0.0.0" ]; then
  17. IP=""
  18. elif [ ! "$IP" = "" ]; then
  19. IP="@$IP"
  20. fi
  21.  
  22. #Check for running processes on the same IP/port
  23. PID="`lsof -t -i$IP:$PORT`"
  24. if [ ! "$PID" = "" ]; then
  25. echo "Warning: Found running process using the same IP/port ($PID)"
  26. EXE="`file /proc/$PID/exe`"
  27. if [ ! "`echo $EXE | grep java`" = "" ]; then
  28. echo "Seems to be a Java process, killing $PID"
  29. kill -9 "$PID"
  30. else
  31. echo "Not a Java process, not killing $PID ($EXE)"
  32. fi
  33. fi
  34. fi
Advertisement
Add Comment
Please, Sign In to add comment