sshd.rc6.4 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2015 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. extra_commands="checkconfig"
  5. extra_started_commands="reload"
  6. : ${SSHD_CONFDIR:=/etc/ssh}
  7. : ${SSHD_CONFIG:=${SSHD_CONFDIR}/sshd_config}
  8. : ${SSHD_PIDFILE:=/var/run/${SVCNAME}.pid}
  9. : ${SSHD_BINARY:=/usr/sbin/sshd}
  10. depend() {
  11. use logger dns
  12. if [ "${rc_need+set}" = "set" ] ; then
  13. : # Do nothing, the user has explicitly set rc_need
  14. else
  15. local x warn_addr
  16. for x in $(awk '/^ListenAddress/{ print $2 }' "$SSHD_CONFIG" 2>/dev/null) ; do
  17. case "${x}" in
  18. 0.0.0.0|0.0.0.0:*) ;;
  19. ::|\[::\]*) ;;
  20. *) warn_addr="${warn_addr} ${x}" ;;
  21. esac
  22. done
  23. if [ -n "${warn_addr}" ] ; then
  24. need net
  25. ewarn "You are binding an interface in ListenAddress statement in your sshd_config!"
  26. ewarn "You must add rc_need=\"net.FOO\" to your /etc/conf.d/sshd"
  27. ewarn "where FOO is the interface(s) providing the following address(es):"
  28. ewarn "${warn_addr}"
  29. fi
  30. fi
  31. }
  32. checkconfig() {
  33. if [ ! -d /var/empty ] ; then
  34. mkdir -p /var/empty || return 1
  35. fi
  36. if [ ! -e "${SSHD_CONFIG}" ] ; then
  37. eerror "You need an ${SSHD_CONFIG} file to run sshd"
  38. eerror "There is a sample file in /usr/share/doc/openssh"
  39. return 1
  40. fi
  41. ssh-keygen -A || return 1
  42. [ "${SSHD_PIDFILE}" != "/var/run/sshd.pid" ] \
  43. && SSHD_OPTS="${SSHD_OPTS} -o PidFile=${SSHD_PIDFILE}"
  44. [ "${SSHD_CONFIG}" != "/etc/ssh/sshd_config" ] \
  45. && SSHD_OPTS="${SSHD_OPTS} -f ${SSHD_CONFIG}"
  46. "${SSHD_BINARY}" -t ${SSHD_OPTS} || return 1
  47. }
  48. start() {
  49. checkconfig || return 1
  50. ebegin "Starting ${SVCNAME}"
  51. start-stop-daemon --start --exec "${SSHD_BINARY}" \
  52. --pidfile "${SSHD_PIDFILE}" \
  53. -- ${SSHD_OPTS}
  54. eend $?
  55. }
  56. stop() {
  57. if [ "${RC_CMD}" = "restart" ] ; then
  58. checkconfig || return 1
  59. fi
  60. ebegin "Stopping ${SVCNAME}"
  61. start-stop-daemon --stop --exec "${SSHD_BINARY}" \
  62. --pidfile "${SSHD_PIDFILE}" --quiet
  63. eend $?
  64. }
  65. reload() {
  66. checkconfig || return 1
  67. ebegin "Reloading ${SVCNAME}"
  68. start-stop-daemon --signal HUP \
  69. --exec "${SSHD_BINARY}" --pidfile "${SSHD_PIDFILE}"
  70. eend $?
  71. }