ecc44c39e4437e4a1bce9308c344d3f3e8ddb7d9
[openwrt/svn-archive/archive.git] / net / openssh / files / sshd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2011 OpenWrt.org
3
4 START=50
5 STOP=50
6
7 SERVICE_USE_PID=1
8
9 start() {
10 for type in rsa dsa; do {
11 # check for keys
12 key=/etc/ssh/ssh_host_${type}_key
13 [ ! -f $key ] && {
14 # generate missing keys
15 [ -x /usr/bin/ssh-keygen ] && {
16 /usr/bin/ssh-keygen -N '' -t $type -f $key 2>&- >&-
17 }
18 }
19 }; done
20 user_exists sshd 22 || user_add sshd 22 22 sshd /var/empty
21 group_exists sshd 22 || group_add sshd 22
22 mkdir -m 0700 -p /var/empty
23 service_start /usr/sbin/sshd
24 }
25
26 stop() {
27 service_stop /usr/sbin/sshd
28 }
29
30 shutdown() {
31 local pid
32 local pids
33 local pid_mine
34
35 stop
36
37 # kill active clients
38 pid_mine="$$"
39 pids="$(pidof sshd)"
40 for pid in $pids; do
41 [ "$pid" = "$pid_mine" ] && continue
42 [ -e "/proc/$pid/stat" ] && kill $pid
43 done
44 }