sshd.init 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. #
  3. # Init file for OpenSSH server daemon
  4. #
  5. # chkconfig: 2345 55 25
  6. # description: OpenSSH server daemon
  7. #
  8. # processname: sshd
  9. # config: /etc/ssh/ssh_host_key
  10. # config: /etc/ssh/ssh_host_key.pub
  11. # config: /etc/ssh/ssh_random_seed
  12. # config: /etc/ssh/sshd_config
  13. # pidfile: /var/run/sshd.pid
  14. # source function library
  15. . /etc/rc.d/init.d/functions
  16. # pull in sysconfig settings
  17. [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
  18. RETVAL=0
  19. prog="sshd"
  20. # Some functions to make the below more readable
  21. SSHD=/usr/sbin/sshd
  22. PID_FILE=/var/run/sshd.pid
  23. do_restart_sanity_check()
  24. {
  25. $SSHD -t
  26. RETVAL=$?
  27. if [ $RETVAL -ne 0 ]; then
  28. failure $"Configuration file or keys are invalid"
  29. echo
  30. fi
  31. }
  32. start()
  33. {
  34. # Create keys if necessary
  35. /usr/bin/ssh-keygen -A
  36. if [ -x /sbin/restorecon ]; then
  37. /sbin/restorecon /etc/ssh/ssh_host_rsa_key.pub
  38. /sbin/restorecon /etc/ssh/ssh_host_dsa_key.pub
  39. /sbin/restorecon /etc/ssh/ssh_host_ecdsa_key.pub
  40. fi
  41. echo -n $"Starting $prog:"
  42. $SSHD $OPTIONS && success || failure
  43. RETVAL=$?
  44. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sshd
  45. echo
  46. }
  47. stop()
  48. {
  49. echo -n $"Stopping $prog:"
  50. killproc $SSHD -TERM
  51. RETVAL=$?
  52. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd
  53. echo
  54. }
  55. reload()
  56. {
  57. echo -n $"Reloading $prog:"
  58. killproc $SSHD -HUP
  59. RETVAL=$?
  60. echo
  61. }
  62. case "$1" in
  63. start)
  64. start
  65. ;;
  66. stop)
  67. stop
  68. ;;
  69. restart)
  70. stop
  71. start
  72. ;;
  73. reload)
  74. reload
  75. ;;
  76. condrestart)
  77. if [ -f /var/lock/subsys/sshd ] ; then
  78. do_restart_sanity_check
  79. if [ $RETVAL -eq 0 ] ; then
  80. stop
  81. # avoid race
  82. sleep 3
  83. start
  84. fi
  85. fi
  86. ;;
  87. status)
  88. status $SSHD
  89. RETVAL=$?
  90. ;;
  91. *)
  92. echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
  93. RETVAL=1
  94. esac
  95. exit $RETVAL