]> andersk Git - openssh.git/blame_incremental - contrib/redhat/sshd.init
Fix init script
[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
22RSA_KEY=/etc/ssh/ssh_host_key
23DSA_KEY=/etc/ssh/ssh_host_dsa_key
24PID_FILE=/var/run/sshd.pid
25do_rsa_keygen() {
26 if $KEYGEN -R && ! test -f $RSA_KEY ; then
27 echo -n "Generating SSH RSA host key: "
28 if $KEYGEN -q -b 1024 -f $RSA_KEY -C '' -N '' >&/dev/null; then
29 success "RSA key generation"
30 echo
31 else
32 failure "RSA key generation"
33 echo
34 exit 1
35 fi
36 fi
37}
38do_dsa_keygen() {
39 if ! test -f $DSA_KEY ; then
40 echo -n "Generating SSH DSA host key: "
41 if $KEYGEN -q -d -b 1024 -f $DSA_KEY -C '' -N '' >&/dev/null; then
42 success "DSA key generation"
43 echo
44 else
45 failure "DSA key generation"
46 echo
47 exit 1
48 fi
49 fi
50}
51
52case "$1" in
53 start)
54 # Create keys if necessary
55 do_rsa_keygen;
56 do_dsa_keygen;
57
58 echo -n "Starting sshd: "
59 if [ ! -f $PID_FILE ] ; then
60 sshd
61 RETVAL=$?
62 if [ "$RETVAL" = "0" ] ; then
63 success "sshd startup"
64 touch /var/lock/subsys/sshd
65 else
66 failure "sshd startup"
67 fi
68 fi
69 echo
70 ;;
71 stop)
72 echo -n "Shutting down sshd: "
73 if [ -f $PID_FILE ] ; then
74 killproc sshd
75 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd
76 fi
77 echo
78 ;;
79 restart)
80 $0 stop
81 $0 start
82 RETVAL=$?
83 ;;
84 status)
85 status sshd
86 RETVAL=$?
87 ;;
88 *)
89 echo "Usage: sshd {start|stop|restart|status}"
90 exit 1
91 ;;
92esac
93
94exit $RETVAL
This page took 0.07008 seconds and 5 git commands to generate.