]> andersk Git - gssapi-openssh.git/blame - openssh/contrib/redhat/sshd.init
Import of OpenSSH 3.5p1
[gssapi-openssh.git] / openssh / contrib / redhat / sshd.init
CommitLineData
3c0ef626 1#!/bin/bash
700318f3 2#
3c0ef626 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
15# source function library
16. /etc/rc.d/init.d/functions
17
700318f3 18# pull in sysconfig settings
3c0ef626 19[ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
20
21RETVAL=0
700318f3 22prog="sshd"
3c0ef626 23
24# Some functions to make the below more readable
25KEYGEN=/usr/bin/ssh-keygen
700318f3 26SSHD=/usr/sbin/sshd
3c0ef626 27RSA1_KEY=/etc/ssh/ssh_host_key
28RSA_KEY=/etc/ssh/ssh_host_rsa_key
29DSA_KEY=/etc/ssh/ssh_host_dsa_key
30PID_FILE=/var/run/sshd.pid
700318f3 31
3c0ef626 32do_rsa1_keygen() {
700318f3 33 if [ ! -s $RSA1_KEY ]; then
34 echo -n $"Generating SSH1 RSA host key: "
3c0ef626 35 if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then
700318f3 36 chmod 600 $RSA1_KEY
37 chmod 644 $RSA1_KEY.pub
38 success $"RSA1 key generation"
3c0ef626 39 echo
40 else
700318f3 41 failure $"RSA1 key generation"
3c0ef626 42 echo
43 exit 1
44 fi
45 fi
46}
700318f3 47
3c0ef626 48do_rsa_keygen() {
700318f3 49 if [ ! -s $RSA_KEY ]; then
50 echo -n $"Generating SSH2 RSA host key: "
3c0ef626 51 if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then
700318f3 52 chmod 600 $RSA_KEY
53 chmod 644 $RSA_KEY.pub
54 success $"RSA key generation"
3c0ef626 55 echo
56 else
700318f3 57 failure $"RSA key generation"
3c0ef626 58 echo
59 exit 1
60 fi
61 fi
62}
700318f3 63
3c0ef626 64do_dsa_keygen() {
700318f3 65 if [ ! -s $DSA_KEY ]; then
66 echo -n $"Generating SSH2 DSA host key: "
3c0ef626 67 if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
700318f3 68 chmod 600 $DSA_KEY
69 chmod 644 $DSA_KEY.pub
70 success $"DSA key generation"
3c0ef626 71 echo
72 else
700318f3 73 failure $"DSA key generation"
3c0ef626 74 echo
75 exit 1
76 fi
77 fi
78}
700318f3 79
80do_restart_sanity_check()
81{
82 $SSHD -t
3c0ef626 83 RETVAL=$?
84 if [ ! "$RETVAL" = 0 ]; then
700318f3 85 failure $"Configuration file or keys are invalid"
3c0ef626 86 echo
3c0ef626 87 fi
88}
89
700318f3 90start()
91{
92 # Create keys if necessary
93 do_rsa1_keygen
94 do_rsa_keygen
95 do_dsa_keygen
96
97 echo -n $"Starting $prog:"
98 initlog -c "$SSHD $OPTIONS" && success || failure
99 RETVAL=$?
100 [ "$RETVAL" = 0 ] && touch /var/lock/subsys/sshd
101 echo
102}
103
104stop()
105{
106 echo -n $"Stopping $prog:"
107 killproc $SSHD -TERM
108 RETVAL=$?
109 [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/sshd
110 echo
111}
112
113reload()
114{
115 echo -n $"Reloading $prog:"
116 killproc $SSHD -HUP
117 RETVAL=$?
118 echo
119}
3c0ef626 120
121case "$1" in
122 start)
700318f3 123 start
3c0ef626 124 ;;
125 stop)
700318f3 126 stop
3c0ef626 127 ;;
128 restart)
700318f3 129 stop
130 start
131 ;;
132 reload)
133 reload
3c0ef626 134 ;;
135 condrestart)
136 if [ -f /var/lock/subsys/sshd ] ; then
137 do_restart_sanity_check
700318f3 138 if [ "$RETVAL" = 0 ] ; then
139 stop
140 # avoid race
141 sleep 3
142 start
143 fi
3c0ef626 144 fi
145 ;;
146 status)
700318f3 147 status $SSHD
3c0ef626 148 RETVAL=$?
149 ;;
150 *)
700318f3 151 echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
152 RETVAL=1
3c0ef626 153esac
3c0ef626 154exit $RETVAL
This page took 0.176938 seconds and 5 git commands to generate.