Rake Assets:Precompile Gets Killed When There Is a Console Session Open in Production

Rake assets:precompile gets killed when there is a console session open in production

Your precompile process is probably being killed because you are running out of RAM. You can confirm this by running top in another ssh session. To fix this, create a swap file that will be used when RAM is full.

Create SWAP Space on Ubuntu
You will probably end up needing some swap space if you plan on using Rails on Digital Ocean 512MB RAM droplet. Specifically, you will run out of RAM when compiling the assets resulting in the process being quietly killed and preventing successful deployments.

To see if you have a swap files:

sudo swapon -s

No swap file shown? Check how much disk space space you have:

 df

To create a swap file:

Step 1: Allocate a file for swap

sudo fallocate -l 2048m /mnt/swap_file.swap

Step 2: Change permission

sudo chmod 600 /mnt/swap_file.swap

Step 3: Format the file for swapping device

sudo mkswap /mnt/swap_file.swap

Step 4: Enable the swap

sudo swapon /mnt/swap_file.swap

Step 5: Make sure the swap is mounted when you Reboot. First, open fstab

sudo nano /etc/fstab

Finally, add entry in fstab (only if it wasn't automatically added)

# /etc/fstab
/mnt/swap_file.swap none swap sw 0 0

Save and exit. You're done adding swap. Now your rake assets:precompile should complete without being killed.

Rails 5.2.4: How to reduce RAM use?

Is uglifier and sass-rails needed?

If you don't use sass on your project you can remove sass-rails. But I see you have font-awesome-sass gem.

Uglifier is used only when compiling assets so your css and js files are smaller.

The app has 200 tables. Will reducing the number of models and using .pluck on queries help reduce RAM use?

Rails autoloads your code, but I doubt the number of models has a significant impact on the ram usage. On the other hand, when you read a record from the database, rails has to create an ActiveRecord object on memory, if you have a table with hundreds of records and you just load all of them at once (User.all.to_a or User.all.each) it will require a lot of ram but only on that specific moment. Usually pluck is a good way to use less ram since you only fetch an array of the values you want and not complete AR objects when you don't need them.

Will removing js dependencies such as mapbox and other css also reduce RAM use?

I don't think so, js dependencies are used during assets compilation.

A good trick to free some ram if you use multiple threads is to use jemalloc instead of the standard malloc for memory allocation https://www.youtube.com/watch?v=4_yxbh9Enoc

Another thing you can do is to only load the rails modules you actually use. On your config/application.rb file you'll see a line like this require 'rails/all' that loads all rails features https://github.com/rails/rails/blob/master/railties/lib/rails/all.rb

You can change that line to only import the features you want, like if you don't use action_cable or active_job you can just import the rest.

Another thing you can do is remove gems related to third party js and css like bootstrap, font-awesome, jquery and use yarn to handle dependencies of js and css. You may lose some view helpers provided by those gems though.

How to precompile a pdf asset in Rails?

I don't think a pdf must be "precompiled".

if you just want to access the pdf from your app without using another service like S3, you can just put that pdf folder on your public folder of the rails app, and they will be available on the app as an static file.

www.domain.com/pdf/ricerca_wg.pdf

just be sure that the public/pdf folder isn't in the gitignore and it must work.

Postgree too many connections in rails console

[SOLVED]

Somehow my demo app was not finding the entries in the tables, so it was creating multiple pools connections, without closing them, because before closing the connection, a 500 error was getting thrown, hence that bit of code where I closed the pool was never closed. More abut postgre session here
https://devcenter.heroku.com/articles/concurrency-and-database-connections#connection-pool

Undefined variable: $navbar-height . error in Ruby On Rails

After analyzing the trace records I follow the below steps:
Copy local Gemfile and Gemfile.lock to production server and run the below command:

$ rvm use 2.1.3
$ rvm gemset empty
$ bundle install

How can i customize greenlight from big blue button

Its for Greenlight V1.

After searching bit i found below steps to setup ruby on rails greenlight app on server.

If you already setup greenlight with docker then please stop docker.
for docker compose you need to run command docker-compose down. it will stop docker image and you will see 404 on your server .

You need to fork greenlight from github first then clone that project in server you can clone it anywhere on server just make sure your server is running on port 5000.

you can checkout more from here

This are all the commands I used to have greenlight running without docker which works for me

======================
apt-get install curl

sudo apt-get install gnupg2

curl -sSL https://rvm.io/mpapis.asc | sudo gpg2 --import -

sudo gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

curl -sSL https://get.rvm.io | sudo bash -s stable

source /etc/profile.d/rvm.sh

rvm requirements

rvm list known

rvm install 2.5.1

rvm use 2.5.1 --default

ruby --version

gem install rails

cd /

git clone https://github.com/bigbluebutton/greenlight.git

cd /greenlight

nano Gemfile

(mover dotenv-rails fuera del bloque test/development)

gem install bundler -v 1.16.1

sudo apt-get install libpq-dev

bundle

cp greenlight.nginx /etc/bigbluebutton/nginx/greenlight.nginx

systemctl restart nginx

rake secret
(Copy the secret generated, you will need it for .env)

bbb-conf --secret
(Copy the URL and Secret, you will need it for .env)

cp sample.env .env

nano .env
(fill the Secret and BigBlueButton credentials you generated before)

RAILS_ENV=production rake db:migrate

rails assets:precompile

rails s -p 5000 -e production

=======================================

In this project do changes as you require and run server again.



Related Topics



Leave a reply



Submit