]> andersk Git - openssh.git/blame - contrib/redhat/sshd.init
- (djm) Update RPM spec version
[openssh.git] / contrib / redhat / sshd.init
CommitLineData
8efc0c15 1#!/bin/bash
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
18RETVAL=0
19
71d43804 20# Some functions to make the below more readable
21KEYGEN=/usr/bin/ssh-keygen
fa08c86b 22RSA1_KEY=/etc/ssh/ssh_host_key
23RSA_KEY=/etc/ssh/ssh_host_rsa_key
71d43804 24DSA_KEY=/etc/ssh/ssh_host_dsa_key
25PID_FILE=/var/run/sshd.pid
a892c46e 26my_success() {
27 local msg
28 if [ $# -gt 1 ]; then
29 msg="$2"
30 else
31 msg="done"
32 fi
33 case "`type -type success`" in
34 function)
35 success "$1"
36 ;;
37 *)
38 echo -n "${msg}"
39 ;;
40 esac
41}
42my_failure() {
43 local msg
44 if [ $# -gt 1 ]; then
45 msg="$2"
46 else
47 msg="FAILED"
48 fi
49 case "`type -type failure`" in
50 function)
51 failure "$1"
52 ;;
53 *)
54 echo -n "${msg}"
55 ;;
56 esac
57}
fa08c86b 58do_rsa1_keygen() {
59 if ! test -f $RSA1_KEY ; then
60 echo -n "Generating SSH1 RSA host key: "
61 if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then
a892c46e 62 my_success "RSA1 key generation"
fa08c86b 63 echo
64 else
a892c46e 65 my_failure "RSA1 key generation"
fa08c86b 66 echo
67 exit 1
68 fi
69 fi
70}
71d43804 71do_rsa_keygen() {
fa08c86b 72 if ! test -f $RSA_KEY ; then
73 echo -n "Generating SSH2 RSA host key: "
74 if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then
a892c46e 75 my_success "RSA key generation"
71d43804 76 echo
77 else
a892c46e 78 my_failure "RSA key generation"
71d43804 79 echo
80 exit 1
81 fi
dd092f97 82 fi
71d43804 83}
84do_dsa_keygen() {
85 if ! test -f $DSA_KEY ; then
fa08c86b 86 echo -n "Generating SSH2 DSA host key: "
87 if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
a892c46e 88 my_success "DSA key generation"
71d43804 89 echo
90 else
a892c46e 91 my_failure "DSA key generation"
71d43804 92 echo
93 exit 1
94 fi
dd092f97 95 fi
71d43804 96}
97
98case "$1" in
99 start)
100 # Create keys if necessary
fa08c86b 101 do_rsa1_keygen;
71d43804 102 do_rsa_keygen;
103 do_dsa_keygen;
104
105 echo -n "Starting sshd: "
106 if [ ! -f $PID_FILE ] ; then
1e61f54a 107 sshd
71d43804 108 RETVAL=$?
1e61f54a 109 if [ "$RETVAL" = "0" ] ; then
a892c46e 110 my_success "sshd startup" "sshd"
1e61f54a 111 touch /var/lock/subsys/sshd
112 else
a892c46e 113 my_failure "sshd startup" ""
1e61f54a 114 fi
71d43804 115 fi
116 echo
117 ;;
118 stop)
119 echo -n "Shutting down sshd: "
120 if [ -f $PID_FILE ] ; then
121 killproc sshd
373998a4 122 RETVAL=$?
71d43804 123 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd
124 fi
125 echo
126 ;;
127 restart)
128 $0 stop
129 $0 start
130 RETVAL=$?
131 ;;
30d8b039 132 condrestart)
133 if [ -f /var/lock/subsys/sshd ] ; then
134 $0 stop
135 $0 start
136 RETVAL=$?
137 fi
138 ;;
71d43804 139 status)
140 status sshd
141 RETVAL=$?
142 ;;
143 *)
30d8b039 144 echo "Usage: sshd {start|stop|restart|status|condrestart}"
71d43804 145 exit 1
146 ;;
8efc0c15 147esac
148
149exit $RETVAL
This page took 0.45924 seconds and 5 git commands to generate.