]> git.pld-linux.org Git - packages/openssh.git/blobdiff - opensshd.init
- prevent sshd from being killed via oom
[packages/openssh.git] / opensshd.init
index 5b7f078009d5c3a6c19d9fd31bc053805db639cf..17c2a2b9274cbc7f9c93c502eacb0ddff4a2381d 100644 (file)
@@ -8,6 +8,7 @@
 #              Ssh can be used for remote login, remote file copying, TCP port \
 #              forwarding etc. Ssh offers strong encryption and authentication.
 
+SSHD_OOM_ADJUST=-17
 
 # Source function library
 . /etc/rc.d/init.d/functions
@@ -28,6 +29,16 @@ else
        exit 0
 fi
 
+adjust_oom() {
+    if [ -e /var/run/sshd.pid ]; then
+       for pid in $(cat /var/run/sshd.pid); do
+               if [ -w "/proc/$pid/oom_adj" ]; then
+                   echo "$SSHD_OOM_ADJUST" > "/proc/$pid/oom_adj" 2> /dev/null || :
+               fi
+       done
+    fi
+}
+
 checkconfig() {
        /usr/sbin/sshd -t || exit 1
 }
@@ -61,8 +72,9 @@ start() {
        # Check if the service is already running?
        if [ ! -f /var/lock/subsys/sshd ]; then
                msg_starting OpenSSH
-               daemon /usr/sbin/sshd
+               daemon --pidfile /var/run/sshd.pid /usr/sbin/sshd
                RETVAL=$?
+               adjust_oom
                [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sshd
        else
                msg_already_running OpenSSH
@@ -117,6 +129,7 @@ case "$1" in
        ;;
   reload|force-reload)
        if [ -f /var/lock/subsys/sshd ]; then
+               checkconfig
                msg_reloading OpenSSH
                killproc sshd -HUP
                RETVAL=$?
This page took 0.093865 seconds and 4 git commands to generate.