sshd.init 721 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2006-2011 OpenWrt.org
  3. START=50
  4. STOP=50
  5. USE_PROCD=1
  6. PROG=/usr/sbin/sshd
  7. start_service() {
  8. for type in rsa ecdsa ed25519; do {
  9. # check for keys
  10. key=/etc/ssh/ssh_host_${type}_key
  11. [ ! -f $key ] && {
  12. # generate missing keys
  13. [ -x /usr/bin/ssh-keygen ] && {
  14. /usr/bin/ssh-keygen -N '' -t $type -f $key 2>&- >&-
  15. }
  16. }
  17. }; done
  18. mkdir -m 0700 -p /var/empty
  19. procd_open_instance
  20. procd_set_param command $PROG -D
  21. procd_close_instance
  22. }
  23. shutdown() {
  24. local pid
  25. local pids
  26. local pid_mine
  27. stop
  28. # kill active clients
  29. pid_mine="$$"
  30. pids="$(pidof sshd)"
  31. for pid in $pids; do
  32. [ "$pid" = "$pid_mine" ] && continue
  33. [ -e "/proc/$pid/stat" ] && kill $pid
  34. done
  35. }