"Out of memory" when I run a rake command on dotcloud - ruby-on-rails

I'm trying to host a website on dotcloud. In my postinstall file I have this :
cd /home/dotcloud/current && bundle exec rake db:migrate
cd /home/dotcloud/current && bundle exec rake db:seed
When it run a command I have this message :
./postinstall: line 1: 158 Killed bundle exec rake db:migrate
It's the same think with every rake commands.
My application is a normal live application and have 64mb reserved. When I see the memory usage I have this :
At the bottom, there is dots which mark a "out of memory" error but all the memory is not used.
It works on sandbox.
So, is it possible to use dotcloud with the basic plan for a rails application? What can I do?

I run this command and It works!
dotcloud scale www:memory=128mb
Does it meens than a rails application does not work with 64mb of memory? Is there as way to do it?

Related

OpsWorks deploy failed after bundle exec rake assets:precompile

I'm trying to deploy an application using AWS OpsWorks with chef, I had have run the deploy in other times and had never failed but this time I got the next message in the log. I run the command bundle
exec rake assets:precompile] in localhost and everything is alright,
What can be?
[2018-03-01T18:50:54+00:00] INFO: Processing execute[cd
/srv/www/my_project/releases/20180301185045 && RAILS_ENV=production bundle
exec rake assets:precompile] action run
(/opt/aws/opsworks/releases/20160504095744_3437-
20160504095744/vendor/bundle/ruby/2.0.0/gems/chef-
11.10.4/lib/chef/provider/deploy.rb line 63)
Error executing action 'run' on resource 'execute[cd
/srv/www/my_project/releases/20180301185045 && RAILS_ENV=production bundle
exec rake assets:precompile]'
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '137'
---- Begin output of cd /srv/www/my_project/releases/20180301185045 &&
RAILS_ENV=production bundle exec rake assets:precompile ----
STDOUT:
Agreed that Opsworks will always run into out of memory state during deployment especially on instances (micro/small). SSH to the instance and make swap memory (e.g. 2GB / 4GB) will help to reduce the issue a lot.
Sometimes the instances got out of memory.
Only stop and start the instance where you are doing the deploy.

Running RAILS_ENV=production with the system command

I have got a really weird problem with a script that I am running on my server, the details are below. But essentially I am using a script to set up a rails application and I am calling that script from an existing rails application.
In my existing application (the application that is calling the script on the server) I have:-
Spawnling.new do
system "cd ~/ && ~/*/create_site.sh param1 param2 >> /tmp/logger"
end
The create_site.sh script creates a fresh installation of rails using the below:
rails new $DIR --database postgresql
It then does a number of things to set up the application. The issue is that the script seems to run absolutely fine until it gets to the following command:
cd $DIR && RAILS_ENV=production rails g roroacms:install -v && RAILS_ENV=production rake assets:clean && RAILS_ENV=production rake assets:precompile
It is really odd because when I run the top command manually as the root user it seems to run absolutely fine without any issues at all. When I view the logger file at the end of the top command it looks like the below:
Your bundle is updated!
Bundle is installed and up to date
RoroaCMS installation
Installation complete with assets
Server started
When I run this manually it outputs a number of messages between each line where it is running the command. Any ideas on this? I am thinking that it could be something to do with RAILS_ENV as the rails new command runs fine earlier in the script.
Hi I do a fair bit of scripting rails on servers and I always use the format bundle exec rails g rspec:install production so your command would be cd $DIR && bundle exec rails g roroacms:install -v production && bundle exec rake assets:clean production && bundle exec rake assets:precompile production. I dont have a whole lot of reasoning behind it but that format seems to be most reliable across different server environments.

Detect initial deploy in openshift deploy hook

I have a rails application on openshift. I want to run rake db:migrate in a deploy hook on openshift, except on first deploy, when I want to run rake db:setup.
This is not necessarily openshift-specific, since deploy hooks are just bash scripts which run when the application is deployed.
Is there any way of knowing if the application has been deployed before or whether the database has already been created from a deploy hook?
I don't think you have to make this distinction. rake db_setup can be called even if the database already exist. See also - How to check if the database exists or not in rails before doing a rake db:setup
Alternatively, you could create a custom rails task. This task could for example try to access the database to check whether it exists. If not you can call db:setup. To learn more about custom rake tasks have a look at this nice video - http://railscasts.com/episodes/66-custom-rake-tasks. Using rake has the benefit that your solution is independent of OpenShift and by using Rake you have access to the Rails environment.
I found a solution in the openshift docs, which is actually not even valid sh. Here is my version.
if echo "use $OPENSHIFT_APP_NAME; show tables" | mysql | grep schema_migrations 2>&1 > /dev/null
then
bundle exec rake db:migrate RAILS_ENV="production"
else
bundle exec rake db:setup RAILS_ENV="production"
fi
If you are using postgres, here is a similar command
if echo "\c $PGDATABASE; \dt" | psql | grep schema_migrations 2>&1 >/dev/null
then
bundle exec rake db:migrate RAILS_ENV="production"
else
bundle exec rake db:setup RAILS_ENV="production"
fi
I'm sure there is a similar environment variable as $PGDATABASE for mysql that you can use instead of $OPENSHIFT_APP_NAME. You can find it by running rhc ssh -a app-name, then running env to get a list of the environment variables.

Execute rake command inside bash

I am seeing many times the question about execution of bash files inside rake (task) files.
My question is, how to execute a rake command inside the bash file?
I have a migrate.sh file inside each rails app on my server and I'm using a general publish.sh. All of this runs ok.
Then, I have a command like rake tmp:clear assets:clean log:clear RAILS_ENV=production inside each migrate.sh that gives me a rake: command not found error.
Help?
Basically rake is not resolved as the PATH variable is not correct. You can try doing echo $PATH. Also you can create a bash script and provide some environment variables required by rake like this:
#!/bin/bash
GEM_HOME=/home/tuxdna/.gems
SHELL=/bin/bash
USER=tuxdna
PATH=/home/tuxdna/.gems/bin:/usr/lib/ruby/gems/1.8/bin/:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
GEM_PATH=/home/tuxdna/.gems:/usr/lib/ruby/gems/1.8
cd ~/somesite
export RAILS_ENV=production
bundle exec rake mytask:task1
klashxx's supposition was correct. It was a permissions/profile issue. I had change my user to root to be able to do other previous tasks and found out that my root was not able to run rake tasks.
This will not be an issue on production server though.
Thanks klashxx

Capistrano on windows returns error code 256

I have a ruby on rails application that i wish to deploy on a remote linux server from my windows machine. However I get the following out after running cap deploy command at the prompt
Command bundle exec rake assets:clean && EXECJS_RUNTIME='Node' JRUBY_OPTS='-J-d32 -X-C' bundle exec rake assets:precompile returned status code 256
Any ideas on what the error code means?

Resources