rc.sshd 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #! /bin/sh
  2. # Copyright (c) 1995-2000 SuSE GmbH Nuernberg, Germany.
  3. #
  4. # Author: Jiri Smid <feedback@suse.de>
  5. #
  6. # /etc/init.d/sshd
  7. #
  8. # and symbolic its link
  9. #
  10. # /usr/sbin/rcsshd
  11. #
  12. ### BEGIN INIT INFO
  13. # Provides: sshd
  14. # Required-Start: $network $remote_fs
  15. # Required-Stop: $network $remote_fs
  16. # Default-Start: 3 5
  17. # Default-Stop: 0 1 2 6
  18. # Description: Start the sshd daemon
  19. ### END INIT INFO
  20. SSHD_BIN=/usr/sbin/sshd
  21. test -x $SSHD_BIN || exit 5
  22. SSHD_SYSCONFIG=/etc/sysconfig/ssh
  23. test -r $SSHD_SYSCONFIG || exit 6
  24. . $SSHD_SYSCONFIG
  25. SSHD_PIDFILE=/var/run/sshd.init.pid
  26. . /etc/rc.status
  27. # Shell functions sourced from /etc/rc.status:
  28. # rc_check check and set local and overall rc status
  29. # rc_status check and set local and overall rc status
  30. # rc_status -v ditto but be verbose in local rc status
  31. # rc_status -v -r ditto and clear the local rc status
  32. # rc_failed set local and overall rc status to failed
  33. # rc_reset clear local rc status (overall remains)
  34. # rc_exit exit appropriate to overall rc status
  35. # First reset status of this service
  36. rc_reset
  37. case "$1" in
  38. start)
  39. # Generate any missing host keys
  40. ssh-keygen -A
  41. echo -n "Starting SSH daemon"
  42. ## Start daemon with startproc(8). If this fails
  43. ## the echo return value is set appropriate.
  44. startproc -f -p $SSHD_PIDFILE $SSHD_BIN $SSHD_OPTS -o "PidFile=$SSHD_PIDFILE"
  45. # Remember status and be verbose
  46. rc_status -v
  47. ;;
  48. stop)
  49. echo -n "Shutting down SSH daemon"
  50. ## Stop daemon with killproc(8) and if this fails
  51. ## set echo the echo return value.
  52. killproc -p $SSHD_PIDFILE -TERM $SSHD_BIN
  53. # Remember status and be verbose
  54. rc_status -v
  55. ;;
  56. try-restart)
  57. ## Stop the service and if this succeeds (i.e. the
  58. ## service was running before), start it again.
  59. $0 status >/dev/null && $0 restart
  60. # Remember status and be quiet
  61. rc_status
  62. ;;
  63. restart)
  64. ## Stop the service and regardless of whether it was
  65. ## running or not, start it again.
  66. $0 stop
  67. $0 start
  68. # Remember status and be quiet
  69. rc_status
  70. ;;
  71. force-reload|reload)
  72. ## Signal the daemon to reload its config. Most daemons
  73. ## do this on signal 1 (SIGHUP).
  74. echo -n "Reload service sshd"
  75. killproc -p $SSHD_PIDFILE -HUP $SSHD_BIN
  76. rc_status -v
  77. ;;
  78. status)
  79. echo -n "Checking for service sshd "
  80. ## Check status with checkproc(8), if process is running
  81. ## checkproc will return with exit status 0.
  82. # Status has a slightly different for the status command:
  83. # 0 - service running
  84. # 1 - service dead, but /var/run/ pid file exists
  85. # 2 - service dead, but /var/lock/ lock file exists
  86. # 3 - service not running
  87. checkproc -p $SSHD_PIDFILE $SSHD_BIN
  88. rc_status -v
  89. ;;
  90. probe)
  91. ## Optional: Probe for the necessity of a reload,
  92. ## give out the argument which is required for a reload.
  93. test /etc/ssh/sshd_config -nt $SSHD_PIDFILE && echo reload
  94. ;;
  95. *)
  96. echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
  97. exit 1
  98. ;;
  99. esac
  100. rc_exit