1180740Sdes#! /bin/bash
2180740Sdes#
3180740Sdes# $Id: sshd.init,v 1.4 2003/11/21 12:48:57 djm Exp $
4180740Sdes#
5180740Sdes### BEGIN INIT INFO
6180740Sdes# Provides:
7180740Sdes# Required-Start: $network
8180740Sdes# Required-Stop:
9180740Sdes# Default-Start:  3 4 5
10180740Sdes# Default-Stop:   0 1 2 6
11180740Sdes# Description: sshd
12180740Sdes#                Bring up/down the OpenSSH secure shell daemon.
13180740Sdes### END INIT INFO
14180740Sdes#
15180740Sdes# Written by Miquel van Smoorenburg <miquels@drinkel.ow.org>.
16180740Sdes# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
17180740Sdes# Modified for OpenLinux by Raymund Will <ray@caldera.de>
18180740Sdes
19180740SdesNAME=sshd
20180740SdesDAEMON=/usr/sbin/$NAME
21180740Sdes# Hack-Alert(TM)!  This is necessary to get around the 'reload'-problem
22180740Sdes# created by recent OpenSSH daemon/ssd combinations. See Caldera internal
23180740Sdes# PR [linux/8278] for details...
24180740SdesPIDF=/var/run/$NAME.pid
25180740SdesNAME=$DAEMON
26180740Sdes
27180740Sdes_status() {
28180740Sdes  [ -z "$1" ] || local pidf="$1"
29180740Sdes  local ret=-1
30180740Sdes  local pid
31180740Sdes  if [ -n "$pidf" ] && [  -r "$pidf" ]; then
32180740Sdes    pid=$(head -1 $pidf)
33180740Sdes  else
34180740Sdes    pid=$(pidof $NAME)
35180740Sdes  fi
36180740Sdes
37180740Sdes  if [ ! -e $SVIlock ]; then
38180740Sdes    # no lock-file => not started == stopped?
39180740Sdes    ret=3
40180740Sdes  elif [ -n "$pidf" -a ! -f "$pidf" ] || [ -z "$pid" ]; then
41180740Sdes    # pid-file given but not present or no pid => died, but was not stopped
42180740Sdes    ret=2
43180740Sdes  elif [ -r /proc/$pid/cmdline ] &&
44180740Sdes       echo -ne $NAME'\000' | cmp -s - /proc/$pid/cmdline; then
45180740Sdes    # pid-file given and present or pid found => check process...
46180740Sdes    # but don't compare exe, as this will fail after an update!
47180740Sdes    # compares OK => all's well, that ends well...
48180740Sdes    ret=0
49180740Sdes  else
50180740Sdes    # no such process or exe does not match => stale pid-file or process died
51180740Sdes    #   just recently...
52180740Sdes    ret=1
53180740Sdes  fi
54180740Sdes  return $ret
55180740Sdes}
56180740Sdes
57180740Sdes# Source function library (and set vital variables).
58180740Sdes. @SVIdir@/functions
59180740Sdes
60180740Sdescase "$1" in
61180740Sdes start)
62180740Sdes  [ ! -e $SVIlock ] || exit 0
63180740Sdes  [ -x $DAEMON ] || exit 5
64180740Sdes  SVIemptyConfig @sysconfdir@/sshd_config && exit 6
65180740Sdes
66180740Sdes  if [ ! \( -f @sysconfdir@/ssh_host_key -a            \
67180740Sdes	    -f @sysconfdir@/ssh_host_key.pub \) -a     \
68180740Sdes       ! \( -f @sysconfdir@/ssh_host_rsa_key -a        \
69180740Sdes	    -f @sysconfdir@/ssh_host_rsa_key.pub \) -a \
70180740Sdes       ! \( -f @sysconfdir@/ssh_host_dsa_key -a        \
71180740Sdes	    -f @sysconfdir@/ssh_host_dsa_key.pub \) ]; then
72180740Sdes
73180740Sdes    echo "$SVIsubsys: host key not initialized: skipped!"
74180740Sdes    echo "$SVIsubsys: use ssh-host-keygen to generate one!"
75180740Sdes    exit 6
76180740Sdes  fi
77180740Sdes
78180740Sdes  echo -n "Starting $SVIsubsys services: "
79180740Sdes  ssd -S -x $DAEMON -n $NAME -- $OPTIONS
80180740Sdes  ret=$?
81180740Sdes
82180740Sdes  echo  "."
83180740Sdes  touch $SVIlock
84180740Sdes  ;;
85180740Sdes
86180740Sdes stop)
87180740Sdes  [ -e $SVIlock ] || exit 0
88180740Sdes
89180740Sdes  echo -n "Stopping $SVIsubsys services: "
90180740Sdes  ssd -K -p $PIDF -n $NAME
91180740Sdes  ret=$?
92180740Sdes
93180740Sdes  echo "."
94180740Sdes  rm -f $SVIlock
95180740Sdes  ;;
96180740Sdes
97180740Sdes force-reload|reload)
98180740Sdes  [ -e $SVIlock ] || exit 0
99180740Sdes
100180740Sdes  echo "Reloading $SVIsubsys configuration files: "
101180740Sdes  ssd -K --signal 1 -q -p $PIDF -n $NAME
102180740Sdes  ret=$?
103180740Sdes  echo "done."
104180740Sdes  ;;
105180740Sdes
106180740Sdes restart)
107180740Sdes  $0 stop
108180740Sdes  $0 start
109180740Sdes  ret=$?
110180740Sdes  ;;
111180740Sdes
112180740Sdes status)
113180740Sdes  _status $PIDF
114180740Sdes  ret=$?
115180740Sdes  ;;
116180740Sdes
117180740Sdes *)
118180740Sdes  echo "Usage: $SVIscript {[re]start|stop|[force-]reload|status}"
119180740Sdes  ret=2
120180740Sdes  ;;
121180740Sdes
122180740Sdesesac
123180740Sdes
124180740Sdesexit $ret
125180740Sdes
126