0

I need to prevent termination of a critical process. A very annoying thing that happens is my VPS likes to kill processes it doesn't like when the RAM gets low. What ends up happening is this critical process gets killed first. This is very bad because the if the VPS IP cycles and the process gets killed, I am completely out of luck because the process can't connect to me and send the VPS's new external IP address.

I don't care if the killing is justifiable. I want to keep this process alive at all costs, and I don't care what measures I have to take. This process is the gateway to my system and I need it alive no matter what.

From comment: This process can not be killed. If this process is killed, consider my server completely inaccessible. This can not happen. I can't be expected to optimize services to not use RAM. The OS will still kill them if they use too much. But this one process is VERY IMPORTANT and must be kept alive at all costs.

Dev
  • 682
  • 2
  • 10
  • 30
  • 1
    Not possible unless you get your VPS to set this up. What you can do is the next best thing: make it respawn: http://askubuntu.com/questions/370957/how-to-prevent-a-process-from-being-killed " This is very bad because the if the VPS IP cycles and the process gets killed, I am completely out of luck because the process can't connect to me and send the VPS's new external IP address." there should be ways around this too: make your process look for your new IP. – Rinzwind Feb 05 '17 at 10:51

1 Answers1

0

Optimize the services running on your VPS to suit the RAM available or upgrade the available RAM to provide for the services.

You could resort to adjusting the oomkiller. See the accepted answer here Set OOM killer adjustment for process on startup?

  • This process can not be killed. If this process is killed, consider my server completely inaccessible. **This can not happen.** I can't be expected to optimize services to *not* use RAM. The OS will still kill them if they use too much. But this one process is VERY IMPORTANT and must be kept alive at all costs. – Dev Feb 05 '17 at 18:40
  • Yes, I read and understood that the first time. Then upgrade your VPS available RAM if you feel you cannot optimize your services to consume LESS RAM (where did I suggest they can consume no RAM?). You won't magically get more resources than the the system has available. The idea behind the link to the other answer is to make OTHER services that are less critical to be killed to free resources first making your critical service less likely to be killed. – user525027 Feb 05 '17 at 19:34
  • Less likely to be killed? No, that will not work. This process MUST NOT BE KILLED. Everything else must be killed FIRST at all costs, no matter what. I do not want to take any risks. – Dev Feb 05 '17 at 20:09
  • I'm sorry if I'm being disrespectful. I would like to not worry about putting the RAM over 75% sometimes – Dev Feb 06 '17 at 02:43
  • In all honesty then you don't have enough RAM on your VPS to provide for what you expect it to do reliably. Add more RAM. If you really insist on not having the service killed you can try disabling the oomkiller on the critical service with for example `pgrep -f “/usr/sbin/sshd” | while read PID; do echo -17 > /proc/$PID/oom_score_adj; done` – user525027 Feb 06 '17 at 08:34
  • `It is important to note that this might cause unexpected behavior depending on the resources and configuration of the system. If the kernel is unable to kill a process using a large amount of memory, it will move onto other available processes. Some of those processes might be important operating system processes that ultimately might cause the system to go down.` – http://www.oracle.com/technetwork/articles/servers-storage-dev/oom-killer-1911807.html – user525027 Feb 06 '17 at 08:43