/network/if-up.d/openssh-server

http://github.com/brinkman83/bashrc · Shell · 37 lines · 20 code · 8 blank · 9 comment · 13 complexity · d6e8fb0f6192bc4cb91c4a1bc50d096b MD5 · raw file

  1. #! /bin/sh
  2. # Reload the OpenSSH server when an interface comes up, to allow it to start
  3. # listening on new addresses.
  4. set -e
  5. # Don't bother to restart sshd when lo is configured.
  6. if [ "$IFACE" = lo ]; then
  7. exit 0
  8. fi
  9. # Only run from ifup.
  10. if [ "$MODE" != start ]; then
  11. exit 0
  12. fi
  13. # OpenSSH only cares about inet and inet6. Get ye gone, strange people
  14. # still using ipx.
  15. if [ "$ADDRFAM" != inet ] && [ "$ADDRFAM" != inet6 ]; then
  16. exit 0
  17. fi
  18. # Is /usr mounted?
  19. if [ ! -e /usr/sbin/sshd ]; then
  20. exit 0
  21. fi
  22. if [ ! -f /var/run/sshd.pid ] || \
  23. [ "$(ps -p "$(cat /var/run/sshd.pid)" -o comm=)" != sshd ]; then
  24. exit 0
  25. fi
  26. # We'd like to use 'reload' here, but it has some problems; see #502444.
  27. stop ssh || true
  28. start ssh || true
  29. exit 0