Rev 2 | Rev 45 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | magnus | 1 | #!/bin/sh |
2 | # |
||
3 | # lsh-utils Start/stop secure shell server. |
||
4 | # Written by Timshel Knoll <timshel@debian.org> |
||
5 | # Updated by Stefan Pfetzing <dreamind@dreamind.de> |
||
6 | # |
||
7 | |||
8 | ### BEGIN INIT INFO |
||
9 | # Provides: sshd |
||
10 | # Required-Start: $local_fs $remote_fs $syslog $named $network |
||
11 | # Required-Stop: $local_fs $remote_fs $syslog $named $network |
||
12 | # Default-Start: 2 3 4 5 |
||
13 | # Default-Stop: 0 1 6 |
||
14 | # Short-Description: lsh secure shell server |
||
15 | ### END INIT INFO |
||
16 | |||
17 | PATH=/sbin:/bin:/usr/sbin:/usr/bin |
||
18 | DAEMON=/usr/sbin/lshd |
||
19 | NAME=lshd |
||
20 | DESC="secure shell v2 server" |
||
21 | CONFIG=/etc/default/lsh-server |
||
22 | |||
23 | RANDOM_SEED="/var/spool/lsh/yarrow-seed-file" |
||
24 | HOST_KEY="/etc/lsh_host_key" |
||
25 | |||
26 | test -f $DAEMON || exit 0 |
||
27 | |||
28 | set -e |
||
29 | |||
30 | if [ -r "$CONFIG" ]; then |
||
31 | . "$CONFIG" |
||
32 | fi |
||
33 | |||
34 | if [ x"$LSHD_PORT" = x ]; then |
||
35 | LSHD_PORT="22" |
||
36 | fi |
||
37 | |||
38 | case "$ENABLE_SFTP" in |
||
39 | true|y*|Y*) |
||
8 | magnus | 40 | SFTP_FLAG="--subsystems sftp=/usr/lib/lsh-server/sftp-server" |
2 | magnus | 41 | ;; |
42 | *) |
||
43 | SFTP_FLAG="" |
||
44 | ;; |
||
45 | esac |
||
46 | |||
47 | if [ "$1" != "stop" -a "$1" != "graceful-stop" ]; then |
||
48 | if [ ! -f "$RANDOM_SEED" ]; then |
||
49 | echo -n "Creating lsh random seed file (this only needs to be done once): $RANDOM_SEED" |
||
50 | DIR=$(dirname "$RANDOM_SEED") |
||
51 | mkdir -p "$DIR" |
||
52 | chmod 700 "$DIR" |
||
53 | dd if=/dev/random "of=$RANDOM_SEED" bs=1 count=32 2>/dev/null |
||
54 | chmod 600 "$RANDOM_SEED" |
||
55 | echo "." |
||
56 | fi |
||
57 | |||
58 | if [ ! -f "$HOST_KEY" ]; then |
||
59 | echo -n "Creating lsh host key (this only needs to be done once): $HOST_KEY" |
||
60 | lsh-keygen --server | \ |
||
61 | lsh-writekey --server --output-file "$HOST_KEY" |
||
62 | |||
63 | if [ ! -f "$HOST_KEY" ]; then |
||
64 | echo " failed! not starting lshd" |
||
65 | exit 0 |
||
66 | fi |
||
67 | |||
68 | echo "." |
||
69 | fi |
||
70 | fi |
||
71 | |||
72 | case "$1" in |
||
73 | start) |
||
74 | echo -n "Starting $DESC: $NAME" |
||
75 | start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \ |
||
76 | --background --make-pidfile --exec $DAEMON -- \ |
||
77 | --port "$LSHD_PORT" $SFTP_FLAG |
||
78 | echo "." |
||
79 | ;; |
||
80 | stop|graceful-stop) |
||
81 | echo -n "Gracefully stopping $DESC: $NAME" |
||
82 | # Signal 1 causes the "old" lsh to close up shop on its port, but |
||
83 | # keeps running until all active connections have been closed |
||
84 | start-stop-daemon --stop --signal 1 --quiet --pidfile \ |
||
85 | /var/run/$NAME.pid --oknodo --exec $DAEMON |
||
86 | # Remove the old pid file, the server will exit when ready |
||
87 | rm -f /var/run/$NAME.pid |
||
88 | echo "." |
||
89 | ;; |
||
90 | #reload) |
||
91 | # Signal 1 causes the "old" lsh to close up shop on its port, but |
||
92 | # keeps running until all active connections have been closed |
||
93 | #echo -n "Reloading $DESC configuration files." |
||
94 | #start-stop-daemon --stop --signal 1 --quiet --pidfile \ |
||
95 | # /var/run/$NAME.pid --exec $DAEMON |
||
96 | #;; |
||
97 | restart|force-reload) |
||
98 | # |
||
99 | # If the "reload" option is implemented, move the "force-reload" |
||
100 | # option to the "reload" entry above. If not, "force-reload" is |
||
101 | # just the same as "restart". |
||
102 | # |
||
103 | echo -n "Restarting $DESC: $NAME" |
||
104 | start-stop-daemon --stop --signal 1 --quiet --pidfile \ |
||
105 | /var/run/$NAME.pid --oknodo --exec $DAEMON |
||
106 | # Remove the old pid file, the old server will exit when ready |
||
107 | rm -f /var/run/$NAME.pid |
||
108 | sleep 1 |
||
109 | start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \ |
||
110 | --background --make-pidfile --exec $DAEMON -- \ |
||
111 | --port "$LSHD_PORT" $SFTP_FLAG |
||
112 | echo "." |
||
113 | ;; |
||
114 | *) |
||
115 | echo "Usage: /etc/init.d/lsh-utils {start|stop|restart|force-reload}" >&2 |
||
116 | exit 1 |
||
117 | ;; |
||
118 | esac |
||
119 | |||
120 | exit 0 |