]>
Commit | Line | Data |
---|---|---|
cf3b46d6 AF |
1 | #!/bin/sh |
2 | # | |
3 | # sshd sshd (secure shell daemon) | |
4 | # | |
8f0031d7 | 5 | # chkconfig: 345 22 88 |
cf3b46d6 | 6 | # |
4a9f24b4 | 7 | # description: sshd (secure shell daemon) is a server part of the ssh suite. \ |
8 | # Ssh can be used for remote login, remote file copying, TCP port \ | |
cf3b46d6 AF |
9 | # forwarding etc. Ssh offers strong encryption and authentication. |
10 | ||
cf3b46d6 AF |
11 | # Source function library |
12 | . /etc/rc.d/init.d/functions | |
13 | ||
14 | # Get network config | |
15 | . /etc/sysconfig/network | |
16 | ||
3cd7ffe2 | 17 | SSHD_OOM_ADJUST=-1000 |
df55b69c | 18 | PIDFILE=/var/run/sshd.pid |
3cd7ffe2 | 19 | |
cf3b46d6 AF |
20 | # Get service config |
21 | [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd | |
22 | ||
23 | # Check that networking is up. | |
7d58fbb0 | 24 | if is_yes "${NETWORKING}"; then |
224aaee1 | 25 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status -a "$1" != init ]; then |
e6635719 | 26 | msg_network_down "OpenSSH" |
7d58fbb0 | 27 | exit 1 |
28 | fi | |
29 | else | |
30 | exit 0 | |
cf3b46d6 | 31 | fi |
a1c37c17 | 32 | |
32322335 | 33 | adjust_oom() { |
df55b69c ER |
34 | if [ -e $PIDFILE ]; then |
35 | for pid in $(cat $PIDFILE); do | |
9172cbe8 | 36 | echo "$SSHD_OOM_ADJUST" 2>/dev/null > /proc/$pid/oom_score_adj |
141073f0 ER |
37 | done |
38 | fi | |
32322335 AM |
39 | } |
40 | ||
945a8076 | 41 | checkconfig() { |
d27ccc9b | 42 | ssh_gen_keys |
945a8076 ER |
43 | /usr/sbin/sshd -t || exit 1 |
44 | } | |
45 | ||
e6635719 | 46 | ssh_gen_keys() { |
35cb43f7 | 47 | @@LIBEXECDIR@@/sshd-keygen |
e6635719 ER |
48 | } |
49 | ||
50 | start() { | |
51 | # Check if the service is already running? | |
c2560889 | 52 | if status --pidfile $PIDFILE sshd >/dev/null; then |
e6635719 ER |
53 | msg_already_running "OpenSSH" |
54 | return | |
3c573fc0 | 55 | fi |
56 | ||
945a8076 ER |
57 | checkconfig |
58 | ||
4dc2df04 | 59 | if [ "$(echo /etc/ssh/ssh_host*key)" = "/etc/ssh/ssh_host*key" ]; then |
e6635719 | 60 | msg_not_running "OpenSSH" |
7d58fbb0 | 61 | nls "No SSH host key found! You must run \"%s init\" first." "$0" |
01d1f289 | 62 | exit 1 |
63 | fi | |
3c573fc0 | 64 | |
1292c55e ER |
65 | if is_yes "$IPV4_NETWORKING" && is_no "$IPV6_NETWORKING"; then |
66 | OPTIONS="$OPTIONS -4" | |
67 | fi | |
68 | if is_yes "$IPV6_NETWORKING" && is_no "$IPV4_NETWORKING"; then | |
69 | OPTIONS="$OPTIONS -6" | |
70 | fi | |
71 | ||
e6635719 | 72 | msg_starting "OpenSSH" |
df55b69c | 73 | daemon --pidfile $PIDFILE /usr/sbin/sshd $OPTIONS |
e6635719 ER |
74 | RETVAL=$? |
75 | adjust_oom | |
76 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sshd | |
b10eed65 ER |
77 | } |
78 | ||
79 | stop() { | |
3cd7ffe2 | 80 | if [ ! -f /var/lock/subsys/sshd ]; then |
e6635719 | 81 | msg_not_running "OpenSSH" |
3cd7ffe2 | 82 | return |
a1c37c17 | 83 | fi |
3cd7ffe2 ER |
84 | |
85 | msg_stopping "OpenSSH" | |
86 | # we use start-stop-daemon to stop sshd, as it is unacceptable for such | |
87 | # critical service as sshd to kill it by procname, but unfortunately | |
88 | # rc-scripts does not provide way to kill *only* by pidfile | |
df55b69c | 89 | start-stop-daemon --stop --quiet --pidfile $PIDFILE && ok || fail |
3cd7ffe2 ER |
90 | rm -f /var/lock/subsys/sshd >/dev/null 2>&1 |
91 | } | |
92 | ||
93 | reload() { | |
94 | if [ ! -f /var/lock/subsys/sshd ]; then | |
95 | msg_not_running "OpenSSH" | |
96 | RETVAL=7 | |
97 | return | |
98 | fi | |
99 | ||
100 | checkconfig | |
101 | msg_reloading "OpenSSH" | |
102 | killproc sshd -HUP | |
103 | RETVAL=$? | |
b10eed65 ER |
104 | } |
105 | ||
8e8276e5 ER |
106 | condrestart() { |
107 | if [ ! -f /var/lock/subsys/sshd ]; then | |
108 | msg_not_running "OpenSSH" | |
109 | RETVAL=$1 | |
110 | return | |
111 | fi | |
112 | ||
113 | checkconfig | |
114 | stop | |
115 | start | |
116 | } | |
117 | ||
b10eed65 ER |
118 | RETVAL=0 |
119 | # See how we were called. | |
120 | case "$1" in | |
121 | start) | |
122 | start | |
123 | ;; | |
124 | stop) | |
125 | stop | |
cf3b46d6 | 126 | ;; |
cbd44157 | 127 | restart) |
945a8076 | 128 | checkconfig |
b10eed65 ER |
129 | stop |
130 | start | |
cf3b46d6 | 131 | ;; |
8e8276e5 ER |
132 | try-restart) |
133 | condrestart 0 | |
134 | ;; | |
3cd7ffe2 ER |
135 | reload|force-reload) |
136 | reload | |
137 | ;; | |
138 | configtest) | |
139 | checkconfig | |
cf3b46d6 | 140 | ;; |
01d1f289 | 141 | init) |
0d883194 | 142 | nls "Now the SSH host key will be generated. Please note, that if you" |
143 | nls "will use password for the key, you will need to type it on each" | |
144 | nls "reboot." | |
e6635719 | 145 | ssh_gen_keys |
36f63877 | 146 | ;; |
3cd7ffe2 | 147 | status) |
df55b69c | 148 | status --pidfile $PIDFILE sshd |
3cd7ffe2 | 149 | exit $? |
36f63877 | 150 | ;; |
cf3b46d6 | 151 | *) |
8e8276e5 | 152 | msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|configtest|init|status}" |
bff0c7f8 | 153 | exit 3 |
cf3b46d6 AF |
154 | esac |
155 | ||
cbd44157 | 156 | exit $RETVAL |