port-check.sh 483 B

1234567891011121314151617181920
  1. #!/bin/bash
  2. . mailcow.conf
  3. if [[ -z $(which ss) ]]; then echo "Please install the ss util first."; exit 1; fi
  4. for port in ${SMTP_PORT} ${SMTPS_PORT} ${SUBMISSION_PORT} ${IMAP_PORT} ${IMAPS_PORT} ${POP_PORT} ${POPS_PORT} ${SIEVE_PORT} 443; do
  5. if [[ ! -z $(ss -tlnp "( sport = :$port )" 2> /dev/null | grep LISTEN | grep -vi docker) ]]; then
  6. echo "Port $port is in use by another process."
  7. err=1
  8. fi
  9. done
  10. if [[ ${err} == "1" ]]; then
  11. echo
  12. echo "Exiting."
  13. exit 1
  14. fi
  15. exit 0