Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Rev 29 | 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>
52 magnus 6
#               Updated by Magnus Holmgren <magnus@debian.org>
2 magnus 7
 
8
### BEGIN INIT INFO
52 magnus 9
# Provides:          lsh-server
2 magnus 10
# Required-Start:    $local_fs $remote_fs $syslog $named $network
11
# Required-Stop:     $local_fs $remote_fs $syslog $named $network
52 magnus 12
# X-Start-Before:    cman drbd smokeping vz
13
# X-Stop-After:      cman drbd smokeping vz
2 magnus 14
# Default-Start:     2 3 4 5
15
# Default-Stop:      0 1 6
16
# Short-Description: lsh secure shell server
17
### END INIT INFO
18
 
19
PATH=/sbin:/bin:/usr/sbin:/usr/bin
20
DAEMON=/usr/sbin/lshd
21
NAME=lshd
22
DESC="secure shell v2 server"
23
CONFIG=/etc/default/lsh-server
52 magnus 24
PIDFILE=/var/run/$NAME.pid
2 magnus 25
 
26
RANDOM_SEED="/var/spool/lsh/yarrow-seed-file"
27
HOST_KEY="/etc/lsh_host_key"
28
 
29
test -f $DAEMON || exit 0
30
 
52 magnus 31
. /lib/lsb/init-functions
2 magnus 32
 
52 magnus 33
set +e
34
 
2 magnus 35
if [ -r "$CONFIG" ]; then
36
   . "$CONFIG"
37
fi
38
 
39
if [ x"$LSHD_PORT" = x ]; then
40
   LSHD_PORT="22"
41
fi
42
 
43
case "$ENABLE_SFTP" in
44
  true|y*|Y*)
52 magnus 45
    SFTP_FLAG="--subsystems sftp=/usr/lib/lsh/sftp-server"
2 magnus 46
    ;;
47
  *)
48
    SFTP_FLAG=""
49
    ;;
50
esac
51
 
52 magnus 52
create_seed_and_key() {
2 magnus 53
   if [ ! -f "$RANDOM_SEED" ]; then
52 magnus 54
      log_action_begin_msg "Creating lsh random seed file (this only needs to be done once)"
2 magnus 55
      DIR=$(dirname "$RANDOM_SEED")
52 magnus 56
      if install -d -m 700 "$DIR" &&
57
          dd if=/dev/random "of=$RANDOM_SEED" bs=1 count=32 2>/dev/null &&
58
          chmod 600 "$RANDOM_SEED"; then
59
          log_action_end_msg 0
60
      else
61
          log_action_end_msg 1
62
          exit 1
63
      fi
2 magnus 64
   fi
65
 
66
   if [ ! -f "$HOST_KEY" ]; then
52 magnus 67
      log_action_begin_msg "Creating lsh host key (this only needs to be done once)"
68
      lsh-keygen --server --output-file "$HOST_KEY"
2 magnus 69
 
70
      if [ ! -f "$HOST_KEY" ]; then
52 magnus 71
         log_action_end_msg 1
72
         exit 1
2 magnus 73
      fi
74
 
52 magnus 75
      log_action_end_msg 0
2 magnus 76
   fi
52 magnus 77
}
2 magnus 78
 
52 magnus 79
 
2 magnus 80
case "$1" in
81
  start)
52 magnus 82
        create_seed_and_key
83
        [ "$VERBOSE" = no ] || log_daemon_msg "Starting $DESC" "$NAME"
84
        start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON \
85
                          -- --daemonic --port "$LSHD_PORT" $SFTP_FLAG
86
        ret=$?
87
        [ "$VERBOSE" = no ] || log_end_msg $ret
2 magnus 88
        ;;
89
  stop|graceful-stop)
52 magnus 90
        [ "$VERBOSE" = no ] || log_daemon_msg "Gracefully stopping $DESC" "$NAME"
2 magnus 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
52 magnus 93
        start-stop-daemon --stop --retry HUP/1 --quiet --pidfile $PIDFILE \
94
            --oknodo --exec $DAEMON
95
        ret=$?
96
        [ "$VERBOSE" = no ] || log_end_msg $ret
2 magnus 97
        ;;
98
  restart|force-reload)
52 magnus 99
        create_seed_and_key
100
        [ "$VERBOSE" = no ] || log_daemon_msg "Restarting $DESC" "$NAME"
101
        start-stop-daemon --stop --retry HUP/1 --quiet --pidfile $PIDFILE \
102
            --oknodo --exec $DAEMON &&
103
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
104
                       -- --daemonic --port "$LSHD_PORT" $SFTP_FLAG
105
        ret=$?
106
        [ "$VERBOSE" = no ] || log_end_msg $ret
2 magnus 107
        ;;
52 magnus 108
  status)
109
        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
110
        ;;
2 magnus 111
  *)
112
        echo "Usage: /etc/init.d/lsh-utils {start|stop|restart|force-reload}" >&2
52 magnus 113
        exit 3
2 magnus 114
        ;;
115
esac