summaryrefslogtreecommitdiff
path: root/contrib/redhat/sshd.init
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2002-05-10 12:19:23 +1000
committerDamien Miller <djm@mindrot.org>2002-05-10 12:19:23 +1000
commitcfe4a89eef91939ef865d6d25ecdc39fb87e8b5f (patch)
tree248f29910c75e3fc959cadcbc3160c492dad08e6 /contrib/redhat/sshd.init
parenta7a5d6d1b54e5c6f4827d7b6545b59787fe61e71 (diff)
- (djm) Rework RedHat RPM files. Based on spec from Nalin
Dahyabhai <nalin@redhat.com> and patches from Pekka Savola <pekkas@netcore.fi>
Diffstat (limited to 'contrib/redhat/sshd.init')
-rwxr-xr-xcontrib/redhat/sshd.init161
1 files changed, 76 insertions, 85 deletions
diff --git a/contrib/redhat/sshd.init b/contrib/redhat/sshd.init
index 86b040cda..4ee8630c3 100755
--- a/contrib/redhat/sshd.init
+++ b/contrib/redhat/sshd.init
@@ -1,5 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2 2#
3# Init file for OpenSSH server daemon 3# Init file for OpenSSH server daemon
4# 4#
5# chkconfig: 2345 55 25 5# chkconfig: 2345 55 25
@@ -15,149 +15,140 @@
15# source function library 15# source function library
16. /etc/rc.d/init.d/functions 16. /etc/rc.d/init.d/functions
17 17
18# pull in sysconfig settings
18[ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd 19[ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
19 20
20RETVAL=0 21RETVAL=0
22prog="sshd"
21 23
22# Some functions to make the below more readable 24# Some functions to make the below more readable
23KEYGEN=/usr/bin/ssh-keygen 25KEYGEN=/usr/bin/ssh-keygen
26SSHD=/usr/sbin/sshd
24RSA1_KEY=/etc/ssh/ssh_host_key 27RSA1_KEY=/etc/ssh/ssh_host_key
25RSA_KEY=/etc/ssh/ssh_host_rsa_key 28RSA_KEY=/etc/ssh/ssh_host_rsa_key
26DSA_KEY=/etc/ssh/ssh_host_dsa_key 29DSA_KEY=/etc/ssh/ssh_host_dsa_key
27PID_FILE=/var/run/sshd.pid 30PID_FILE=/var/run/sshd.pid
28my_success() { 31
29 local msg
30 if [ $# -gt 1 ]; then
31 msg="$2"
32 else
33 msg="done"
34 fi
35 case "`type -type success`" in
36 function)
37 success "$1"
38 ;;
39 *)
40 echo -n "${msg}"
41 ;;
42 esac
43}
44my_failure() {
45 local msg
46 if [ $# -gt 1 ]; then
47 msg="$2"
48 else
49 msg="FAILED"
50 fi
51 case "`type -type failure`" in
52 function)
53 failure "$1"
54 ;;
55 *)
56 echo -n "${msg}"
57 ;;
58 esac
59}
60do_rsa1_keygen() { 32do_rsa1_keygen() {
61 if ! test -f $RSA1_KEY ; then 33 if [ ! -s $RSA1_KEY ]; then
62 echo -n "Generating SSH1 RSA host key: " 34 echo -n $"Generating SSH1 RSA host key: "
63 if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then 35 if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then
64 my_success "RSA1 key generation" 36 chmod 600 $RSA1_KEY
37 chmod 644 $RSA1_KEY.pub
38 success $"RSA1 key generation"
65 echo 39 echo
66 else 40 else
67 my_failure "RSA1 key generation" 41 failure $"RSA1 key generation"
68 echo 42 echo
69 exit 1 43 exit 1
70 fi 44 fi
71 fi 45 fi
72} 46}
47
73do_rsa_keygen() { 48do_rsa_keygen() {
74 if ! test -f $RSA_KEY ; then 49 if [ ! -s $RSA_KEY ]; then
75 echo -n "Generating SSH2 RSA host key: " 50 echo -n $"Generating SSH2 RSA host key: "
76 if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then 51 if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then
77 my_success "RSA key generation" 52 chmod 600 $RSA_KEY
53 chmod 644 $RSA_KEY.pub
54 success $"RSA key generation"
78 echo 55 echo
79 else 56 else
80 my_failure "RSA key generation" 57 failure $"RSA key generation"
81 echo 58 echo
82 exit 1 59 exit 1
83 fi 60 fi
84 fi 61 fi
85} 62}
63
86do_dsa_keygen() { 64do_dsa_keygen() {
87 if ! test -f $DSA_KEY ; then 65 if [ ! -s $DSA_KEY ]; then
88 echo -n "Generating SSH2 DSA host key: " 66 echo -n $"Generating SSH2 DSA host key: "
89 if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then 67 if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
90 my_success "DSA key generation" 68 chmod 600 $DSA_KEY
69 chmod 644 $DSA_KEY.pub
70 success $"DSA key generation"
91 echo 71 echo
92 else 72 else
93 my_failure "DSA key generation" 73 failure $"DSA key generation"
94 echo 74 echo
95 exit 1 75 exit 1
96 fi 76 fi
97 fi 77 fi
98} 78}
99do_restart_sanity_check() { 79
100 sshd -t 80do_restart_sanity_check()
81{
82 $SSHD -t
101 RETVAL=$? 83 RETVAL=$?
102 if [ ! "$RETVAL" = 0 ]; then 84 if [ ! "$RETVAL" = 0 ]; then
103 my_failure "Configuration file or keys" 85 failure $"Configuration file or keys are invalid"
104 echo 86 echo
105 exit $RETVAL
106 fi 87 fi
107} 88}
108 89
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}
109 120
110case "$1" in 121case "$1" in
111 start) 122 start)
112 # Create keys if necessary 123 start
113 do_rsa1_keygen;
114 do_rsa_keygen;
115 do_dsa_keygen;
116
117 echo -n "Starting sshd: "
118 if [ ! -f $PID_FILE ] ; then
119 sshd $OPTIONS
120 RETVAL=$?
121 if [ "$RETVAL" = "0" ] ; then
122 my_success "sshd startup" "sshd"
123 touch /var/lock/subsys/sshd
124 else
125 my_failure "sshd startup" ""
126 fi
127 fi
128 echo
129 ;; 124 ;;
130 stop) 125 stop)
131 echo -n "Shutting down sshd: " 126 stop
132 if [ -f $PID_FILE ] ; then
133 killproc sshd
134 RETVAL=$?
135 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd
136 fi
137 echo
138 ;; 127 ;;
139 restart) 128 restart)
140 do_restart_sanity_check 129 stop
141 $0 stop 130 start
142 $0 start 131 ;;
143 RETVAL=$? 132 reload)
133 reload
144 ;; 134 ;;
145 condrestart) 135 condrestart)
146 if [ -f /var/lock/subsys/sshd ] ; then 136 if [ -f /var/lock/subsys/sshd ] ; then
147 do_restart_sanity_check 137 do_restart_sanity_check
148 $0 stop 138 if [ "$RETVAL" = 0 ] ; then
149 $0 start 139 stop
150 RETVAL=$? 140 # avoid race
141 sleep 3
142 start
143 fi
151 fi 144 fi
152 ;; 145 ;;
153 status) 146 status)
154 status sshd 147 status $SSHD
155 RETVAL=$? 148 RETVAL=$?
156 ;; 149 ;;
157 *) 150 *)
158 echo "Usage: sshd {start|stop|restart|status|condrestart}" 151 echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
159 exit 1 152 RETVAL=1
160 ;;
161esac 153esac
162
163exit $RETVAL 154exit $RETVAL