summaryrefslogtreecommitdiff
path: root/contrib/caldera/sshd.init
blob: 983146f4fe0015ef6e84b02f02afe3ddcba6a4d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#! /bin/bash
#
# $Id: sshd.init,v 1.4 2003/11/21 12:48:57 djm Exp $
#
### BEGIN INIT INFO
# Provides:
# Required-Start: $network
# Required-Stop:
# Default-Start:  3 4 5
# Default-Stop:   0 1 2 6
# Description: sshd
#                Bring up/down the OpenSSH secure shell daemon.
### END INIT INFO
#
# Written by Miquel van Smoorenburg <miquels@drinkel.ow.org>.
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for OpenLinux by Raymund Will <ray@caldera.de>

NAME=sshd
DAEMON=/usr/sbin/$NAME
# Hack-Alert(TM)!  This is necessary to get around the 'reload'-problem
# created by recent OpenSSH daemon/ssd combinations. See Caldera internal
# PR [linux/8278] for details...
PIDF=/var/run/$NAME.pid
NAME=$DAEMON

_status() {
  [ -z "$1" ] || local pidf="$1"
  local ret=-1
  local pid
  if [ -n "$pidf" ] && [  -r "$pidf" ]; then
    pid=$(head -1 $pidf)
  else
    pid=$(pidof $NAME)
  fi

  if [ ! -e $SVIlock ]; then
    # no lock-file => not started == stopped?
    ret=3
  elif [ -n "$pidf" -a ! -f "$pidf" ] || [ -z "$pid" ]; then
    # pid-file given but not present or no pid => died, but was not stopped
    ret=2
  elif [ -r /proc/$pid/cmdline ] &&
       echo -ne $NAME'\000' | cmp -s - /proc/$pid/cmdline; then
    # pid-file given and present or pid found => check process...
    # but don't compare exe, as this will fail after an update!
    # compares OK => all's well, that ends well...
    ret=0
  else
    # no such process or exe does not match => stale pid-file or process died
    #   just recently...
    ret=1
  fi
  return $ret
}

# Source function library (and set vital variables).
. @SVIdir@/functions

case "$1" in
 start)
  [ ! -e $SVIlock ] || exit 0
  [ -x $DAEMON ] || exit 5
  SVIemptyConfig @sysconfdir@/sshd_config && exit 6

  if [ ! \( -f @sysconfdir@/ssh_host_key -a            \
	    -f @sysconfdir@/ssh_host_key.pub \) -a     \
       ! \( -f @sysconfdir@/ssh_host_rsa_key -a        \
	    -f @sysconfdir@/ssh_host_rsa_key.pub \) -a \
       ! \( -f @sysconfdir@/ssh_host_dsa_key -a        \
	    -f @sysconfdir@/ssh_host_dsa_key.pub \) ]; then

    echo "$SVIsubsys: host key not initialized: skipped!"
    echo "$SVIsubsys: use ssh-host-keygen to generate one!"
    exit 6
  fi

  echo -n "Starting $SVIsubsys services: "
  ssd -S -x $DAEMON -n $NAME -- $OPTIONS
  ret=$?

  echo  "."
  touch $SVIlock
  ;;

 stop)
  [ -e $SVIlock ] || exit 0

  echo -n "Stopping $SVIsubsys services: "
  ssd -K -p $PIDF -n $NAME
  ret=$?

  echo "."
  rm -f $SVIlock
  ;;

 force-reload|reload)
  [ -e $SVIlock ] || exit 0

  echo "Reloading $SVIsubsys configuration files: "
  ssd -K --signal 1 -q -p $PIDF -n $NAME
  ret=$?
  echo "done."
  ;;

 restart)
  $0 stop
  $0 start
  ret=$?
  ;;

 status)
  _status $PIDF
  ret=$?
  ;;

 *)
  echo "Usage: $SVIscript {[re]start|stop|[force-]reload|status}"
  ret=2
  ;;

esac

exit $ret