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