Mike Lockwood | 1305e95 | 2011-12-07 08:17:59 -0800 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | # |
| 3 | # $Id: sshd.init,v 1.4 2003/11/21 12:48:57 djm Exp $ |
| 4 | # |
| 5 | ### BEGIN INIT INFO |
| 6 | # Provides: |
| 7 | # Required-Start: $network |
| 8 | # Required-Stop: |
| 9 | # Default-Start: 3 4 5 |
| 10 | # Default-Stop: 0 1 2 6 |
| 11 | # Description: sshd |
| 12 | # Bring up/down the OpenSSH secure shell daemon. |
| 13 | ### END INIT INFO |
| 14 | # |
| 15 | # Written by Miquel van Smoorenburg <miquels@drinkel.ow.org>. |
| 16 | # Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>. |
| 17 | # Modified for OpenLinux by Raymund Will <ray@caldera.de> |
| 18 | |
| 19 | NAME=sshd |
| 20 | DAEMON=/usr/sbin/$NAME |
| 21 | # Hack-Alert(TM)! This is necessary to get around the 'reload'-problem |
| 22 | # created by recent OpenSSH daemon/ssd combinations. See Caldera internal |
| 23 | # PR [linux/8278] for details... |
| 24 | PIDF=/var/run/$NAME.pid |
| 25 | NAME=$DAEMON |
| 26 | |
| 27 | _status() { |
| 28 | [ -z "$1" ] || local pidf="$1" |
| 29 | local ret=-1 |
| 30 | local pid |
| 31 | if [ -n "$pidf" ] && [ -r "$pidf" ]; then |
| 32 | pid=$(head -1 $pidf) |
| 33 | else |
| 34 | pid=$(pidof $NAME) |
| 35 | fi |
| 36 | |
| 37 | if [ ! -e $SVIlock ]; then |
| 38 | # no lock-file => not started == stopped? |
| 39 | ret=3 |
| 40 | elif [ -n "$pidf" -a ! -f "$pidf" ] || [ -z "$pid" ]; then |
| 41 | # pid-file given but not present or no pid => died, but was not stopped |
| 42 | ret=2 |
| 43 | elif [ -r /proc/$pid/cmdline ] && |
| 44 | echo -ne $NAME'\000' | cmp -s - /proc/$pid/cmdline; then |
| 45 | # pid-file given and present or pid found => check process... |
| 46 | # but don't compare exe, as this will fail after an update! |
| 47 | # compares OK => all's well, that ends well... |
| 48 | ret=0 |
| 49 | else |
| 50 | # no such process or exe does not match => stale pid-file or process died |
| 51 | # just recently... |
| 52 | ret=1 |
| 53 | fi |
| 54 | return $ret |
| 55 | } |
| 56 | |
| 57 | # Source function library (and set vital variables). |
| 58 | . @SVIdir@/functions |
| 59 | |
| 60 | case "$1" in |
| 61 | start) |
| 62 | [ ! -e $SVIlock ] || exit 0 |
| 63 | [ -x $DAEMON ] || exit 5 |
| 64 | SVIemptyConfig @sysconfdir@/sshd_config && exit 6 |
| 65 | |
| 66 | if [ ! \( -f @sysconfdir@/ssh_host_key -a \ |
| 67 | -f @sysconfdir@/ssh_host_key.pub \) -a \ |
| 68 | ! \( -f @sysconfdir@/ssh_host_rsa_key -a \ |
| 69 | -f @sysconfdir@/ssh_host_rsa_key.pub \) -a \ |
| 70 | ! \( -f @sysconfdir@/ssh_host_dsa_key -a \ |
| 71 | -f @sysconfdir@/ssh_host_dsa_key.pub \) ]; then |
| 72 | |
| 73 | echo "$SVIsubsys: host key not initialized: skipped!" |
| 74 | echo "$SVIsubsys: use ssh-host-keygen to generate one!" |
| 75 | exit 6 |
| 76 | fi |
| 77 | |
| 78 | echo -n "Starting $SVIsubsys services: " |
| 79 | ssd -S -x $DAEMON -n $NAME -- $OPTIONS |
| 80 | ret=$? |
| 81 | |
| 82 | echo "." |
| 83 | touch $SVIlock |
| 84 | ;; |
| 85 | |
| 86 | stop) |
| 87 | [ -e $SVIlock ] || exit 0 |
| 88 | |
| 89 | echo -n "Stopping $SVIsubsys services: " |
| 90 | ssd -K -p $PIDF -n $NAME |
| 91 | ret=$? |
| 92 | |
| 93 | echo "." |
| 94 | rm -f $SVIlock |
| 95 | ;; |
| 96 | |
| 97 | force-reload|reload) |
| 98 | [ -e $SVIlock ] || exit 0 |
| 99 | |
| 100 | echo "Reloading $SVIsubsys configuration files: " |
| 101 | ssd -K --signal 1 -q -p $PIDF -n $NAME |
| 102 | ret=$? |
| 103 | echo "done." |
| 104 | ;; |
| 105 | |
| 106 | restart) |
| 107 | $0 stop |
| 108 | $0 start |
| 109 | ret=$? |
| 110 | ;; |
| 111 | |
| 112 | status) |
| 113 | _status $PIDF |
| 114 | ret=$? |
| 115 | ;; |
| 116 | |
| 117 | *) |
| 118 | echo "Usage: $SVIscript {[re]start|stop|[force-]reload|status}" |
| 119 | ret=2 |
| 120 | ;; |
| 121 | |
| 122 | esac |
| 123 | |
| 124 | exit $ret |
| 125 | |