]> andersk Git - openssh.git/blame - contrib/redhat/sshd.init
- jakob@cvs.openbsd.org 2001/08/02 16:14:05
[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
5ef815d7 18[ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
19
8efc0c15 20RETVAL=0
21
71d43804 22# Some functions to make the below more readable
23KEYGEN=/usr/bin/ssh-keygen
fa08c86b 24RSA1_KEY=/etc/ssh/ssh_host_key
25RSA_KEY=/etc/ssh/ssh_host_rsa_key
71d43804 26DSA_KEY=/etc/ssh/ssh_host_dsa_key
27PID_FILE=/var/run/sshd.pid
a892c46e 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}
fa08c86b 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
a892c46e 64 my_success "RSA1 key generation"
fa08c86b 65 echo
66 else
a892c46e 67 my_failure "RSA1 key generation"
fa08c86b 68 echo
69 exit 1
70 fi
71 fi
72}
71d43804 73do_rsa_keygen() {
fa08c86b 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
a892c46e 77 my_success "RSA key generation"
71d43804 78 echo
79 else
a892c46e 80 my_failure "RSA key generation"
71d43804 81 echo
82 exit 1
83 fi
dd092f97 84 fi
71d43804 85}
86do_dsa_keygen() {
87 if ! test -f $DSA_KEY ; then
fa08c86b 88 echo -n "Generating SSH2 DSA host key: "
89 if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
a892c46e 90 my_success "DSA key generation"
71d43804 91 echo
92 else
a892c46e 93 my_failure "DSA key generation"
71d43804 94 echo
95 exit 1
96 fi
dd092f97 97 fi
71d43804 98}
99
100case "$1" in
101 start)
102 # Create keys if necessary
fa08c86b 103 do_rsa1_keygen;
71d43804 104 do_rsa_keygen;
105 do_dsa_keygen;
106
107 echo -n "Starting sshd: "
108 if [ ! -f $PID_FILE ] ; then
5ef815d7 109 sshd $OPTIONS
71d43804 110 RETVAL=$?
1e61f54a 111 if [ "$RETVAL" = "0" ] ; then
a892c46e 112 my_success "sshd startup" "sshd"
1e61f54a 113 touch /var/lock/subsys/sshd
114 else
a892c46e 115 my_failure "sshd startup" ""
1e61f54a 116 fi
71d43804 117 fi
118 echo
119 ;;
120 stop)
121 echo -n "Shutting down sshd: "
122 if [ -f $PID_FILE ] ; then
123 killproc sshd
373998a4 124 RETVAL=$?
71d43804 125 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd
126 fi
127 echo
128 ;;
129 restart)
130 $0 stop
131 $0 start
132 RETVAL=$?
133 ;;
30d8b039 134 condrestart)
135 if [ -f /var/lock/subsys/sshd ] ; then
136 $0 stop
137 $0 start
138 RETVAL=$?
139 fi
140 ;;
71d43804 141 status)
142 status sshd
143 RETVAL=$?
144 ;;
145 *)
30d8b039 146 echo "Usage: sshd {start|stop|restart|status|condrestart}"
71d43804 147 exit 1
148 ;;
8efc0c15 149esac
150
151exit $RETVAL
This page took 1.936968 seconds and 5 git commands to generate.