opensshd.init.in 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!@STARTUP_SCRIPT_SHELL@
  2. # Donated code that was put under PD license.
  3. #
  4. # Stripped PRNGd out of it for the time being.
  5. umask 022
  6. CAT=@CAT@
  7. KILL=@KILL@
  8. prefix=@prefix@
  9. sysconfdir=@sysconfdir@
  10. piddir=@piddir@
  11. SSHD=$prefix/sbin/sshd
  12. PIDFILE=$piddir/sshd.pid
  13. PidFile=`grep "^PidFile" ${sysconfdir}/sshd_config | tr "=" " " | awk '{print $2}'`
  14. [ X$PidFile = X ] || PIDFILE=$PidFile
  15. SSH_KEYGEN=$prefix/bin/ssh-keygen
  16. HOST_KEY_DSA=$sysconfdir/ssh_host_dsa_key
  17. HOST_KEY_RSA=$sysconfdir/ssh_host_rsa_key
  18. @COMMENT_OUT_ECC@HOST_KEY_ECDSA=$sysconfdir/ssh_host_ecdsa_key
  19. HOST_KEY_ED25519=$sysconfdir/ssh_host_ed25519_key
  20. checkkeys() {
  21. if [ ! -f $HOST_KEY_DSA ]; then
  22. ${SSH_KEYGEN} -t dsa -f ${HOST_KEY_DSA} -N ""
  23. fi
  24. if [ ! -f $HOST_KEY_RSA ]; then
  25. ${SSH_KEYGEN} -t rsa -f ${HOST_KEY_RSA} -N ""
  26. fi
  27. @COMMENT_OUT_ECC@ if [ ! -f $HOST_KEY_ECDSA ]; then
  28. @COMMENT_OUT_ECC@ ${SSH_KEYGEN} -t ecdsa -f ${HOST_KEY_ECDSA} -N ""
  29. @COMMENT_OUT_ECC@ fi
  30. if [ ! -f $HOST_KEY_ED25519 ]; then
  31. ${SSH_KEYGEN} -t ed25519 -f ${HOST_KEY_ED25519} -N ""
  32. fi
  33. }
  34. stop_service() {
  35. if [ -r $PIDFILE -a ! -z ${PIDFILE} ]; then
  36. PID=`${CAT} ${PIDFILE}`
  37. fi
  38. if [ ${PID:=0} -gt 1 -a ! "X$PID" = "X " ]; then
  39. ${KILL} ${PID}
  40. else
  41. echo "Unable to read PID file"
  42. fi
  43. }
  44. start_service() {
  45. # XXX We really should check if the service is already going, but
  46. # XXX we will opt out at this time. - Bal
  47. # Check to see if we have keys that need to be made
  48. checkkeys
  49. # Start SSHD
  50. echo "starting $SSHD... \c" ; $SSHD
  51. sshd_rc=$?
  52. if [ $sshd_rc -ne 0 ]; then
  53. echo "$0: Error ${sshd_rc} starting ${SSHD}... bailing."
  54. exit $sshd_rc
  55. fi
  56. echo done.
  57. }
  58. case $1 in
  59. 'start')
  60. start_service
  61. ;;
  62. 'stop')
  63. stop_service
  64. ;;
  65. 'restart')
  66. stop_service
  67. start_service
  68. ;;
  69. *)
  70. echo "$0: usage: $0 {start|stop|restart}"
  71. ;;
  72. esac