Memory error in Rails console on AWS - amazon-ec2

I logged into our production instance on AWS, and tried to go into Rails console:
bundle exec rails c production
But I'm getting the following error
There was an error while trying to load the gem 'mini_magick' (Bundler::GemRequireError)
Gem Load Error is: Cannot allocate memory - animate
When I run free I see there's no swap:
free
total used free shared buffers cached
Mem: 7659512 7515728 143784 408 1724 45604
-/+ buffers/cache: 7468400 191112
Swap: 0 0 0
df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 3824796 12 3824784 1% /dev
tmpfs 765952 376 765576 1% /run
/dev/xvda1 15341728 11289944 3323732 78% /
none 4 0 4 0% /sys/fs/cgroup
none 5120 0 5120 0% /run/lock
none 3829756 0 3829756 0% /run/shm
none 102400 0 102400 0% /run/user
/dev/xvdf 10190136 6750744 2898720 70% /mnt
Not sure what's causing this or how to resolve it. Any help is appreciated.
Thanks!

You can increase EC2 instance memory or add swap memory to EC2.
grep Mem /proc/meminfo
grep Swap /proc/meminfo
free
uname -a
# Set swap file to /swapfile1
sudo dd if=/dev/zero of=/swapfile1 bs=1M count=512
grep Swap /proc/meminfo
ll /swapfile1
sudo chmod 600 /swapfile1
mkswap /swapfile1
ll /swapfile1
sudo mkswap /swapfile1
swapon -s
free
sudo swapon /swapfile1
free
grep Swap /proc/meminfo

Related

Remote SSH: Disk quota exceeded

I use vscode to connect to a supercomputer using SSH remote.
I ran a selenium request from a jupyter notebook that took too long, then failed and then the bash: cannot create temp file for here-document: Disk quota exceeded started to appear when trying to complete with tab the name of a file/folder in the terminal.
These are the outputs of df and quota commands:
>> df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 189G 0 189G 0% /dev
tmpfs 189G 2.6G 186G 2% /dev/shm
tmpfs 189G 17M 189G 1% /run
tmpfs 189G 0 189G 0% /sys/fs/cgroup
/dev/mapper/vg_loginnode1-lv_root 1.0T 44G 981G 5% /
/dev/sda2 1014M 315M 700M 31% /boot
/dev/sda1 100M 12M 89M 12% /boot/efi
/dev/mapper/vg_loginnode1-lv_tmp 1.0T 26G 999G 3% /tmp
/dev/mapper/vg_loginnode1-lv_vartmp 200G 379M 200G 1% /var/tmp
tmpfs 38G 12K 38G 1% /run/user/42
home 51T 19T 32T 37% /home
proj 4.4P 3.6P 801T 83% /proj
sw7 21T 4.9T 16T 25% /software
tmpfs 38G 0 38G 0% /run/user/10754
>> df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
devtmpfs 49329535 638 49328897 1% /dev
tmpfs 49339830 1050 49338780 1% /dev/shm
tmpfs 49339830 5418 49334412 1% /run
tmpfs 49339830 16 49339814 1% /sys/fs/cgroup
/dev/mapper/vg_loginnode1-lv_root 107374144 262482 107111662 1% /
/dev/sda2 524288 27 524261 1% /boot
/dev/sda1 0 0 0 - /boot/efi
/dev/mapper/vg_loginnode1-lv_tmp 107374144 33180 107340964 1% /tmp
/dev/mapper/vg_loginnode1-lv_vartmp 104857600 518 104857082 1% /var/tmp
tmpfs 49339830 9 49339821 1% /run/user/42
home 157286400 84893563 72392837 54% /home
proj 500000000 343005480 156994520 69% /proj
sw7 104857600 33867547 70990053 33% /software
tmpfs 49339830 10 49339820 1% /run/user/10754
>> quota -u
Disk quotas for user ***** (uid 10754):
Filesystem blocks quota limit grace files quota limit grace
/dev/mapper/vg_loginnode1-lv_tmp
10485760* 10485760 10485760 22639 0 0
Obviously, I am surpassing the quota. As I told you at the beginning, this is a supercomputer, so I have limited to no access to the base folders (tmp, etc.). So, any ideas on how to solve this without cleaning tmp are more than welcome.
Hit the same issue. I cannot find any files that I own in /tmp, so I don't know why the system says my tmp quota is exceeded.
I found a work-around: change the location of my bash temp files.
$ mkdir -p ~/tmp
$ export TMPDIR=~/tmp
$ echo "export TMPDIR=~/tmp" >> ~/.bashrc

Ubuntu 20.0.4 server install didn't use whole NVMe drive

I installed Ubuntu 20.0.4 LTS onto a fresh Samsung 250GB NVMe and used all the defaults during installation. Everything seemed to go fine but I'm not seeing that it is only showing ~100GB on the drive. How do I extend the partition
$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 16G 0 16G 0% /dev
tmpfs 3.1G 1.5M 3.1G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 98G 26G 68G 28% /
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/nvme0n1p2 1.5G 111M 1.3G 8% /boot
/dev/loop0 56M 56M 0 100% /snap/core18/2128
/dev/nvme0n1p1 1.1G 5.3M 1.1G 1% /boot/efi
/dev/loop1 62M 62M 0 100% /snap/core20/1328
/dev/loop2 71M 71M 0 100% /snap/lxd/21029
/dev/loop3 68M 68M 0 100% /snap/lxd/21835
/dev/loop4 56M 56M 0 100% /snap/core18/2284
/dev/loop5 44M 44M 0 100% /snap/snapd/149
sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
NAME FSTYPE SIZE MOUNTPOINT LABEL
loop0 squashfs 55.4M /snap/core18/2128
loop1 squashfs 61.9M /snap/core20/1328
loop2 squashfs 70.3M /snap/lxd/21029
loop3 squashfs 67.2M /snap/lxd/21835
loop4 squashfs 55.5M /snap/core18/2284
loop5 squashfs 43.6M /snap/snapd/14978
nvme0n1 232.9G
├─nvme0n1p1 vfat 1.1G /boot/efi
├─nvme0n1p2 ext4 1.5G /boot
└─nvme0n1p3 LVM2_member 230.3G
└─ubuntu--vg-ubuntu--lv ext4 100G /
running these commands did the trick
sudo lvresize -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

Bash: Multiple npm install in the background give error, 'No space left on device'

I am setting up docker on a google cloud compute machine, 1 vCPU and 3.75 GB ram.
If I simply run docker-compose up --build, it does work but the process is sequential and slow. So I am using this bash script so that I can build images in the background, and skip the usual sequential process.
command=$1
shift
jobsList=""
taskList[0]=""
i=0
#Replaces all the fluff with nothing, and we get our job Id
function getJobId(){
echo "$(echo $STRING | sed s/^[^0-9]*// | sed s/[^0-9].*$//)"
}
for task in "$#"
do
echo "Command is $command $task"
docker-compose $command $task &> ${task}.text &
lastJob=`getJobId $(jobs %%)`
jobsList="$jobsList $lastJob"
echo "jobsList is $jobsList"
taskList[$i]="$command $task"
i=$(($i + 1))
done
i=0
for job in $jobsList
do
wait %$job
echo "${taskList[$i]} completed with status $?"
i=$(($i + 1))
done
and I use it in the following manner:
availableServices=$(docker-compose config --services)
while IFS='' read -r line || [[ -n "$line" ]]
do
services+=$(echo "$line ")
done <<<"$availableServices"
./runInParallel.sh build $services
I string together available services in docker-compose.yml, and pass it to my script.
But the issue is eventually all the processes fail with the following error:
npm WARN tar ENOSPC: no space left on device, write
Unhandled rejection Error: ENOSPC: no space left on device, write
I checked inodes, and on /dev/sda1 only 44% were used.
Here's my output for the command df -h:
Filesystem Size Used Avail Use% Mounted on
udev 1.8G 0 1.8G 0% /dev
tmpfs 370M 892K 369M 1% /run
/dev/sda1 9.6G 9.1G 455M 96% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/loop0 55M 55M 0 100% /snap/google-cloud-sdk/64
/dev/loop2 55M 55M 0 100% /snap/google-cloud-sdk/62
/dev/loop1 55M 55M 0 100% /snap/google-cloud-sdk/63
/dev/loop3 79M 79M 0 100% /snap/go/3095
/dev/loop5 89M 89M 0 100% /snap/core/5897
/dev/loop4 90M 90M 0 100% /snap/core/6130
/dev/loop6 90M 90M 0 100% /snap/core/6034
/dev/sda15 105M 3.6M 101M 4% /boot/efi
tmpfs 370M 0 370M 0% /run/user/1001
and here's the output for df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
udev 469499 385 469114 1% /dev
tmpfs 472727 592 472135 1% /run
/dev/sda1 1290240 636907 653333 50% /
tmpfs 472727 1 472726 1% /dev/shm
tmpfs 472727 8 472719 1% /run/lock
tmpfs 472727 18 472709 1% /sys/fs/cgroup
/dev/loop0 20782 20782 0 100% /snap/google-cloud-sdk/64
/dev/loop2 20680 20680 0 100% /snap/google-cloud-sdk/62
/dev/loop1 20738 20738 0 100% /snap/google-cloud-sdk/63
/dev/loop3 9417 9417 0 100% /snap/go/3095
/dev/loop5 12808 12808 0 100% /snap/core/5897
/dev/loop4 12810 12810 0 100% /snap/core/6130
/dev/loop6 12810 12810 0 100% /snap/core/6034
/dev/sda15 0 0 0 - /boot/efi
tmpfs 472727 10 472717 1% /run/user/1001
From your df -h output, root directory (/dev/sda1) has only 455MB free space.
Whenever you run docker build, the docker-client (CLI) will send all the contents of the Dockerfile directory to docker-daemon which builds the image.
So, for example, if you have three services each with 300MB directories, you can build them sequentially with 455MB available free space, but to build them all at the same time you need 300MB*3 amount of free space for docker-daemon to cache and build the images.

How to execute linux commands in a remote machine with shell script

I have a test server, from which i need to login to two different prod server and execute
top, free -h, ps -ef commands
could some one help me with a shell script
Only ssh command can do this:
$ for ip in 192.168.138.22{1,2,3}; do ssh ${ip} -o StrictHostKeyChecking=no "free -h"; done
total used free shared buff/cache available
Mem: 7.8G 782M 5.2G 152M 1.8G 6.4G
Swap: 7.9G 0B 7.9G
total used free shared buff/cache available
Mem: 7.8G 1.3G 4.1G 169M 2.5G 5.8G
Swap: 7.9G 0B 7.9G
total used free shared buff/cache available
Mem: 7.8G 563M 5.9G 118M 1.4G 6.6G
Swap: 7.9G 0B 7.9G
However, this need to authenticate ssh-key with each other. So, we can use sshpass to pass the passqord:
$ for ip in 192.168.138.22{1,2,3}; do sshpass -p PASSWORD ssh ${ip} -o StrictHostKeyChecking=no "free -h"; done
total used free shared buff/cache available
Mem: 7.8G 782M 5.2G 152M 1.8G 6.4G
Swap: 7.9G 0B 7.9G
total used free shared buff/cache available
Mem: 7.8G 1.3G 4.1G 169M 2.5G 5.8G
Swap: 7.9G 0B 7.9G
total used free shared buff/cache available
Mem: 7.8G 563M 5.9G 118M 1.4G 6.6G
Swap: 7.9G 0B 7.9G
If you have ssh access to your server, you can execute commands remotely on this way:
ssh -i <PATH_YOUR_PRIVATE_KEY>remote_username#remote_host "<COMMAND>"

vagrant - no space left on device error

I am new to vagrant. I am following the instructions at http://gettingstartedwithdjango.com/en/lessons/introduction-and-launch/
I am getting the following error on running "sudo ./postinstall.sh" script
+ apt-get -y clean
+ rm -f /var/lib/dhcp3/*
+ rm /etc/udev/rules.d/70-persistent-net.rules
rm: cannot remove `/etc/udev/rules.d/70-persistent-net.rules': Is a directory
+ mkdir /etc/udev/rules.d/70-persistent-net.rules
mkdir: cannot create directory `/etc/udev/rules.d/70-persistent-net.rules': File exists
+ rm -rf /dev/.udev/
+ rm /lib/udev/rules.d/75-persistent-net-generator.rules
rm: cannot remove `/lib/udev/rules.d/75-persistent-net-generator.rules': No such file or directory
+ rm -f /home/vagrant/{*.iso,postinstall*.sh}
+ dd if=/dev/zero of=/EMPTY bs=1M
dd: writing `/EMPTY': No space left on device
78504+0 records in
78503+0 records out
82316406784 bytes (82 GB) copied, 105.122 s, 783 MB/s
+ rm -f /EMPTY
+ exit
But I seem to have enough space:
vagrant#precise64:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/precise64-root 79G 2.3G 73G 3% /
udev 174M 0 174M 0% /dev
tmpfs 74M 272K 73M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 183M 0 183M 0% /run/shm
/dev/sda1 228M 25M 192M 12% /boot
/vagrant 220G 91G 130G 42% /vagrant
/tmp/vagrant-chef-1/chef-solo-1/cookbooks 220G 91G 130G 42% /tmp/vagrant-chef-1/chef-solo-1/cookbooks
/tmp/vagrant-chef-1/chef-solo-2/cookbooks 220G 91G 130G 42% /tmp/vagrant-chef-1/chef-solo-2/cookbooks
Can somebody please help? Thank you.
It's supposed to do this :) It's making your virtual disk as small as possible since it is thinly provisioned.
Creating a file full of zeros on the disk until it is full is clearing the blocks on the disk and as such your file representing the VMs disk will be as small as the actual data you have on the disk.
The problem resides in the following statement:
dd if=/dev/zero of=/EMPTY bs=1M
If you don't specify count=<some value>, the dd command will continue until the end of device is reached. So basically with the above command you're trying to create a file called that spawns through the whole partition, called EMPTY under /. Thus the error.

Resources