openssh.init 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. #PKG openssh-server
  3. #INIT 50
  4. . /etc/rc.conf
  5. case $1 in
  6. autostop) ;;
  7. autostart)
  8. test x"${openssh:-NO}" = x"NO" && exit 0
  9. grep "^dropbear" /etc/rc.conf >/dev/null 2>&1 || dropbear=NO
  10. if [[ $openssh = AUTO && $dropbear != NO ]]; then
  11. echo openssh not starting: set to AUTO and dropbear is enabled
  12. exit 0
  13. fi
  14. test x"$openssh" = x"DAEMON" && test -x /bin/mksh && exec mksh -T- $0 start
  15. exec sh $0 start
  16. ;;
  17. start)
  18. if [[ ! -s /etc/ssh/ssh_host_rsa_key ]]; then
  19. mkdir -p /etc/ssh
  20. if [[ ! -x /usr/bin/ssh-keygen ]]; then
  21. echo "openssh not starting: SSH private key missing"
  22. exit 0
  23. fi
  24. echo "openssh: generating SSH private key (RSA)"
  25. /usr/bin/ssh-keygen -N '' -t rsa -f /etc/ssh/ssh_host_rsa_key
  26. rv=$?
  27. echo openssh: key generation exited with code $rv
  28. [[ $rv = 0 && -s /etc/ssh/ssh_host_rsa_key ]] || exit 1
  29. fi
  30. mkdir -p /var/run/sshd
  31. mkdir -p /var/empty
  32. touch /var/log/btmp && chmod 600 /var/log/btmp
  33. /usr/sbin/sshd
  34. ;;
  35. stop)
  36. if [ -e /var/run/sshd.pid ]; then
  37. kill $(cat /var/run/sshd.pid)
  38. fi
  39. ;;
  40. restart)
  41. sh $0 stop
  42. sh $0 start
  43. ;;
  44. *)
  45. echo "Usage: $0 {start | stop | restart}"
  46. exit 1
  47. ;;
  48. esac
  49. exit $?