]> andersk Git - openssh.git/blame_incremental - contrib/redhat/sshd.init
- (djm) Update RPM spec version
[openssh.git] / contrib / redhat / sshd.init
... / ...
CommitLineData
1#!/bin/bash
2
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
18RETVAL=0
19
20# Some functions to make the below more readable
21KEYGEN=/usr/bin/ssh-keygen
22RSA1_KEY=/etc/ssh/ssh_host_key
23RSA_KEY=/etc/ssh/ssh_host_rsa_key
24DSA_KEY=/etc/ssh/ssh_host_dsa_key
25PID_FILE=/var/run/sshd.pid
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}
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
62 my_success "RSA1 key generation"
63 echo
64 else
65 my_failure "RSA1 key generation"
66 echo
67 exit 1
68 fi
69 fi
70}
71do_rsa_keygen() {
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
75 my_success "RSA key generation"
76 echo
77 else
78 my_failure "RSA key generation"
79 echo
80 exit 1
81 fi
82 fi
83}
84do_dsa_keygen() {
85 if ! test -f $DSA_KEY ; then
86 echo -n "Generating SSH2 DSA host key: "
87 if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
88 my_success "DSA key generation"
89 echo
90 else
91 my_failure "DSA key generation"
92 echo
93 exit 1
94 fi
95 fi
96}
97
98case "$1" in
99 start)
100 # Create keys if necessary
101 do_rsa1_keygen;
102 do_rsa_keygen;
103 do_dsa_keygen;
104
105 echo -n "Starting sshd: "
106 if [ ! -f $PID_FILE ] ; then
107 sshd
108 RETVAL=$?
109 if [ "$RETVAL" = "0" ] ; then
110 my_success "sshd startup" "sshd"
111 touch /var/lock/subsys/sshd
112 else
113 my_failure "sshd startup" ""
114 fi
115 fi
116 echo
117 ;;
118 stop)
119 echo -n "Shutting down sshd: "
120 if [ -f $PID_FILE ] ; then
121 killproc sshd
122 RETVAL=$?
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 ;;
132 condrestart)
133 if [ -f /var/lock/subsys/sshd ] ; then
134 $0 stop
135 $0 start
136 RETVAL=$?
137 fi
138 ;;
139 status)
140 status sshd
141 RETVAL=$?
142 ;;
143 *)
144 echo "Usage: sshd {start|stop|restart|status|condrestart}"
145 exit 1
146 ;;
147esac
148
149exit $RETVAL
This page took 0.033674 seconds and 5 git commands to generate.