]> andersk Git - gssapi-openssh.git/blame - openssh/contrib/redhat/sshd.init
Release new patch.
[gssapi-openssh.git] / openssh / contrib / redhat / sshd.init
CommitLineData
3c0ef626 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
18[ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
19
20RETVAL=0
21
22# Some functions to make the below more readable
23KEYGEN=/usr/bin/ssh-keygen
24RSA1_KEY=/etc/ssh/ssh_host_key
25RSA_KEY=/etc/ssh/ssh_host_rsa_key
26DSA_KEY=/etc/ssh/ssh_host_dsa_key
27PID_FILE=/var/run/sshd.pid
28my_success() {
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() {
61 if ! test -f $RSA1_KEY ; then
62 echo -n "Generating SSH1 RSA host key: "
63 if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then
64 my_success "RSA1 key generation"
65 echo
66 else
67 my_failure "RSA1 key generation"
68 echo
69 exit 1
70 fi
71 fi
72}
73do_rsa_keygen() {
74 if ! test -f $RSA_KEY ; then
75 echo -n "Generating SSH2 RSA host key: "
76 if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then
77 my_success "RSA key generation"
78 echo
79 else
80 my_failure "RSA key generation"
81 echo
82 exit 1
83 fi
84 fi
85}
86do_dsa_keygen() {
87 if ! test -f $DSA_KEY ; then
88 echo -n "Generating SSH2 DSA host key: "
89 if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
90 my_success "DSA key generation"
91 echo
92 else
93 my_failure "DSA key generation"
94 echo
95 exit 1
96 fi
97 fi
98}
99do_restart_sanity_check() {
100 sshd -t
101 RETVAL=$?
102 if [ ! "$RETVAL" = 0 ]; then
103 my_failure "Configuration file or keys"
104 echo
105 exit $RETVAL
106 fi
107}
108
109
110case "$1" in
111 start)
112 # Create keys if necessary
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 ;;
130 stop)
131 echo -n "Shutting down sshd: "
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 ;;
139 restart)
140 do_restart_sanity_check
141 $0 stop
142 $0 start
143 RETVAL=$?
144 ;;
145 condrestart)
146 if [ -f /var/lock/subsys/sshd ] ; then
147 do_restart_sanity_check
148 $0 stop
149 $0 start
150 RETVAL=$?
151 fi
152 ;;
153 status)
154 status sshd
155 RETVAL=$?
156 ;;
157 *)
158 echo "Usage: sshd {start|stop|restart|status|condrestart}"
159 exit 1
160 ;;
161esac
162
163exit $RETVAL
This page took 0.087423 seconds and 5 git commands to generate.