"Fossies" - the Fresh Open Source Software Archive

Member "sshdfilter-1.5.7/etc/init.d/ssh.ub80.orig" (4 Jun 2010, 3839 Bytes) of package /linux/privat/old/sshdfilter-1.5.7.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #! /bin/sh
    2 
    3 ### BEGIN INIT INFO
    4 # Provides:     sshd
    5 # Required-Start:   $network $local_fs $remote_fs
    6 # Required-Stop:
    7 # Default-Start:    2 3 4 5
    8 # Default-Stop:     0 1 6
    9 # Short-Description:    OpenBSD Secure Shell server
   10 ### END INIT INFO
   11 
   12 set -e
   13 
   14 # /etc/init.d/ssh: start and stop the OpenBSD "secure shell(tm)" daemon
   15 
   16 test -x /usr/sbin/sshd || exit 0
   17 ( /usr/sbin/sshd -\? 2>&1 | grep -q OpenSSH ) 2>/dev/null || exit 0
   18 
   19 SSHD_OOM_ADJUST=-17
   20 if test -f /etc/default/ssh; then
   21     . /etc/default/ssh
   22 fi
   23 
   24 . /lib/lsb/init-functions
   25 
   26 if [ -n "$2" ]; then
   27     SSHD_OPTS="$SSHD_OPTS $2"
   28 fi
   29 
   30 # Are we running from init?
   31 run_by_init() {
   32     ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]
   33 }
   34 
   35 check_for_no_start() {
   36     # forget it if we're trying to start, and /etc/ssh/sshd_not_to_be_run exists
   37     if [ -e /etc/ssh/sshd_not_to_be_run ]; then 
   38     if [ "$1" = log_end_msg ]; then
   39         log_end_msg 0
   40     fi
   41     if ! run_by_init; then
   42         log_action_msg "OpenBSD Secure Shell server not in use (/etc/ssh/sshd_not_to_be_run)"
   43     fi
   44     exit 0
   45     fi
   46 }
   47 
   48 check_dev_null() {
   49     if [ ! -c /dev/null ]; then
   50     if [ "$1" = log_end_msg ]; then
   51         log_end_msg 1 || true
   52     fi
   53     if ! run_by_init; then
   54         log_action_msg "/dev/null is not a character device!"
   55     fi
   56     exit 1
   57     fi
   58 }
   59 
   60 check_privsep_dir() {
   61     # Create the PrivSep empty dir if necessary
   62     if [ ! -d /var/run/sshd ]; then
   63     mkdir /var/run/sshd
   64     chmod 0755 /var/run/sshd
   65     fi
   66 }
   67 
   68 check_config() {
   69     if [ ! -e /etc/ssh/sshd_not_to_be_run ]; then
   70     /usr/sbin/sshd -t || exit 1
   71     fi
   72 }
   73 
   74 adjust_oom() {
   75     if [ -e /var/run/sshd.pid ]; then
   76     PID="$(head -n1 /var/run/sshd.pid)"
   77     if [ -e "/proc/$PID/oom_adj" ]; then
   78         printf '%s' "$SSHD_OOM_ADJUST" >"/proc/$PID/oom_adj" || true
   79     fi
   80     fi
   81 }
   82 
   83 export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
   84 
   85 case "$1" in
   86   start)
   87     check_privsep_dir
   88     check_for_no_start
   89     check_dev_null
   90     log_daemon_msg "Starting OpenBSD Secure Shell server" "sshd"
   91     if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
   92         log_end_msg 0
   93         adjust_oom
   94     else
   95         log_end_msg 1
   96     fi
   97     ;;
   98   stop)
   99     log_daemon_msg "Stopping OpenBSD Secure Shell server" "sshd"
  100     if start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/sshd.pid; then
  101         log_end_msg 0
  102     else
  103         log_end_msg 1
  104     fi
  105     ;;
  106 
  107   reload|force-reload)
  108     check_for_no_start
  109     check_config
  110     log_daemon_msg "Reloading OpenBSD Secure Shell server's configuration" "sshd"
  111     if start-stop-daemon --stop --signal 1 --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd; then
  112         log_end_msg 0
  113     else
  114         log_end_msg 1
  115     fi
  116     ;;
  117 
  118   restart)
  119     check_privsep_dir
  120     check_config
  121     log_daemon_msg "Restarting OpenBSD Secure Shell server" "sshd"
  122     start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile /var/run/sshd.pid
  123     check_for_no_start log_end_msg
  124     check_dev_null log_end_msg
  125     if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
  126         log_end_msg 0
  127         adjust_oom
  128     else
  129         log_end_msg 1
  130     fi
  131     ;;
  132 
  133   try-restart)
  134     check_privsep_dir
  135     check_config
  136     log_daemon_msg "Restarting OpenBSD Secure Shell server" "sshd"
  137     set +e
  138     start-stop-daemon --stop --quiet --retry 30 --pidfile /var/run/sshd.pid
  139     RET="$?"
  140     set -e
  141     case $RET in
  142         0)
  143         # old daemon stopped
  144         check_for_no_start log_end_msg
  145         check_dev_null log_end_msg
  146         if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
  147             log_end_msg 0
  148         else
  149             log_end_msg 1
  150         fi
  151         ;;
  152         1)
  153         # daemon not running
  154         log_progress_msg "(not running)"
  155         log_end_msg 0
  156         ;;
  157         *)
  158         # failed to stop
  159         log_progress_msg "(failed to stop)"
  160         log_end_msg 1
  161         ;;
  162     esac
  163     ;;
  164 
  165   *)
  166     log_action_msg "Usage: /etc/init.d/ssh {start|stop|reload|force-reload|restart|try-restart}"
  167     exit 1
  168 esac
  169 
  170 exit 0