Linux – Arrange server resources so that ssh is always available

linuxsshUbuntu

I have a linux server for one of my web applications. Every once in a while, a process (a long running script maybe) might go out of hand, consume too much memory / cpu cycles maybe and block all other processes.

In such situations, I can't ssh into the server, and I need to restart the server through a management panel. I'd prefer to login into the machine and deal with the problematic process only.

Is it possible to arrange the resources in a linux machine such that, however a process is consuming resources, there is always enough resources available for an ssh connection?

Best Answer

You can use 'nice' to prioritize certain software.

You could also look into installing monit, which you can instruct to restart a certain package if a certain threshold is met.

A monit config along these lines will automatically restart Apache:

check process apache
   with pidfile "/usr/local/apache/logs/httpd.pid"
   start program = "/etc/init.d/httpd start" with timeout 60 seconds
   stop program = "/etc/init.d/httpd stop"
   if 2 restarts within 3 cycles then timeout
   if totalmem > 100 Mb then alert
   if children > 255 for 5 cycles then stop
   if cpu usage > 95% for 3 cycles then restart
   if failed port 80 protocol http then restart
   group server
   depends on httpd.conf, httpd.bin