Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH and -bash: fork: Cannot allocate memory VPS Ubuntu

I am hosting my Rails app on Ubuntu 12.04 VPS, Nginx + Unicorn, after deployment everything is fine, but few hours later, when I ssh to the VPS I get this message

-bash: fork: Cannot allocate memory

-bash: wait_for: No record of process 4201 

-bash: wait_for: No record of process 4201 

If I run any command, it would just return

-bash: fork: Cannot allocate memory.
like image 973
user1883793 Avatar asked Nov 18 '14 01:11

user1883793


1 Answers

Seems you have run out of memory. Many VPS servers are setup with no swap, so when you run out of memory, it will kill things off in a seemingly random manner.

The easiest way to fix it is to get more memory provisioned to your VPS, likely costing more money. The next best way (other than running less stuff and memory optimizing everything running) would be to add a swap partition or swap file.

For a 1GB swap file (as root):

dd if=/dev/zero of=/swapfile bs=1M count=1024
mkswap /swapfile
swapon  /swapfile

Be sure to add it to /etc/fstab too as:

/swapfile none swap defaults 0 0

That will make it come back after reboot.

like image 175
Beirdo Avatar answered Oct 18 '22 19:10

Beirdo