-1

Here is my code and output in console:

root@a:/home/rails/car_main# bundle install

You have requested:
  rails = 4.2

The bundle currently has rails locked at 4.0.2.
Try running `bundle update rails`

Here is what I did and output:

root@a:/home/rails/car_main# bundle update rails
Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies............
Using rake 10.5.0
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.4 (was 4.7.5)
Using thread_safe 0.3.5
Using builder 3.2.2 (was 3.1.4)
Using erubis 2.7.0
Using mini_portile2 2.0.0
Using rack 1.6.4 (was 1.5.5)
Using mime-types 2.99 (was 1.25.1)
Using arel 6.0.3 (was 4.0.2)
Installing bcrypt 3.1.10 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/bcrypt-3.1.10/ext/mri
/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160218-3939-e5ct6z.rb extconf.rb
Cannot allocate memory - /usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160218-3939-e5ct6z.rb extconf.rb 2>&1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.3.0/gems/bcrypt-3.1.10 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/bcrypt-3.1.10/gem_make.out
Installing bcrypt-ruby 3.1.2 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/bcrypt-ruby-3.1.2/ext/mri
/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160218-3939-e88mem.rb extconf.rb
Cannot allocate memory - /usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160218-3939-e88mem.rb extconf.rb 2>&1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.3.0/gems/bcrypt-ruby-3.1.2 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/bcrypt-ruby-3.1.2/gem_make.out
Using coffee-script-source 1.10.0
Using execjs 2.6.0
Using thor 0.19.1
Using bundler 1.11.2
Using hike 1.2.3
Using multi_json 1.11.2
Using tilt 1.4.1
Using sass 3.4.21
Using will_paginate 3.0.4
Installing ffi 1.9.10 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/ffi-1.9.10/ext/ffi_c
/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160218-3939-u62vla.rb extconf.rb
Cannot allocate memory - /usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160218-3939-u62vla.rb extconf.rb 2>&1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.3.0/gems/ffi-1.9.10 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/ffi-1.9.10/gem_make.out
Using diff-lcs 1.2.5
Installing unf_ext 0.0.7.1 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /usr/local/rvm/gems/ruby-2.3.0/gems/unf_ext-0.0.7.1/ext/unf_ext
/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160218-3939-1n8ty2l.rb extconf.rb
Cannot allocate memory - /usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160218-3939-1n8ty2l.rb extconf.rb 2>&1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.3.0/gems/unf_ext-0.0.7.1 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.3.0/extensions/x86_64-linux/2.3.0/unf_ext-0.0.7.1/gem_make.out
Using ffaker 2.1.0

After this when I type bundle install I still get the error

Okay. What do I do with memory? I use digital ocean droplet for $5 my website is quite simple. I did what suggested here in this question: https://askubuntu.com/questions/253466/why-am-i-frequently-getting-this-cannot-allocate-memory-error here is output:

root@a:/home/rails/car_main# ps --sort -rss -eo rss,pid,command | head
  RSS   PID COMMAND
75920  1538 unicorn worker[0] -D -c /etc/unicorn.conf -E production                                                                                              
74176  1541 unicorn worker[1] -D -c /etc/unicorn.conf -E production                                                                                              
73988  1543 unicorn worker[2] -D -c /etc/unicorn.conf -E production                                                                                              
73828  1546 unicorn worker[3] -D -c /etc/unicorn.conf -E production                                                                                              
11972  1057 /usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf
10464  1535 unicorn master -D -c /etc/unicorn.conf -E production                                                                                                 
 7508  4037 postgres: rails rails_project_production 127.0.0.1(56865) idle                                                              
 6788  1630 -bash
 5732  1563 postgres: rails rails_project_production 127.0.0.1(56745) idle 

UPDATE2: I print this as suggested in comments link root@a:/home/rails/car_main# sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2 Problem still exist. I will try to stop postgres now

Update 3 I tried to stop and start postgres( I am not sure if I googled how to this correctly so here the code and output:

root@a:/usr/bin# /etc/init.d/postgresql stop
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_TIME = "ru_RU.UTF-8",
    LC_MONETARY = "ru_RU.UTF-8",
    LC_ADDRESS = "ru_RU.UTF-8",
    LC_TELEPHONE = "ru_RU.UTF-8",
    LC_NAME = "ru_RU.UTF-8",
    LC_MEASUREMENT = "ru_RU.UTF-8",
    LC_IDENTIFICATION = "ru_RU.UTF-8",
    LC_NUMERIC = "ru_RU.UTF-8",
    LC_PAPER = "ru_RU.UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
 * Stopping PostgreSQL 9.3 database server                               [ OK ] 
root@a:/usr/bin# /etc/init.d/postgresql start
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_TIME = "ru_RU.UTF-8",
    LC_MONETARY = "ru_RU.UTF-8",
    LC_ADDRESS = "ru_RU.UTF-8",
    LC_TELEPHONE = "ru_RU.UTF-8",
    LC_NAME = "ru_RU.UTF-8",
    LC_MEASUREMENT = "ru_RU.UTF-8",
    LC_IDENTIFICATION = "ru_RU.UTF-8",
    LC_NUMERIC = "ru_RU.UTF-8",
    LC_PAPER = "ru_RU.UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
 * Starting PostgreSQL 9.3 database server                                       * perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_TIME = "ru_RU.UTF-8",
    LC_MONETARY = "ru_RU.UTF-8",
    LC_ADDRESS = "ru_RU.UTF-8",
    LC_TELEPHONE = "ru_RU.UTF-8",
    LC_NAME = "ru_RU.UTF-8",
    LC_MEASUREMENT = "ru_RU.UTF-8",
    LC_IDENTIFICATION = "ru_RU.UTF-8",
    LC_NUMERIC = "ru_RU.UTF-8",
    LC_PAPER = "ru_RU.UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
The PostgreSQL server failed to start. Please check the log output:
2016-02-18 12:42:32 EST FATAL:  could not map anonymous shared memory: Cannot allocate memory
2016-02-18 12:42:32 EST HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space. To reduce the request size (currently 147783680 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.

UPDATE 4: I print htop: here is the output: enter image description here What processes should I kill?

Update 5:

I ran once again bundle update Then I got some error and promt to install bundler so I installed it with

root@a:/home/rails/car_main# apt-get install bundler Then I did once again bundle update:

root@a:/home/rails/car_main# bundle update
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler (LoadError)
    from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/bin/bundle:7:in `<main>'

UPDATE 6: So I run bundle update once again and it gave me an error that cannot install sqlite3 and suggested to install it manually so i did it and here's the output:

root@a:/home/rails/car_main# gem  install sqlite3 -v '1.3.8'
Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3:
    ERROR: Failed to build gem native extension.

    current directory: /usr/local/rvm/gems/ruby-2.3.0@railstutorial_rails_4_0/gems/sqlite3-1.3.8/ext/sqlite3
/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160218-26242-ueiluc.rb extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... yes
checking for sqlite3_initialize()... yes
checking for sqlite3_backup_init()... yes
checking for sqlite3_column_database_name()... yes
checking for sqlite3_enable_load_extension()... yes
checking for sqlite3_load_extension()... yes
checking for sqlite3_open_v2()... yes
checking for sqlite3_prepare_v2()... yes
checking for sqlite3_int64 in sqlite3.h... yes
checking for sqlite3_uint64 in sqlite3.h... yes
creating Makefile

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /usr/local/rvm/gems/ruby-2.3.0@railstutorial_rails_4_0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.8/mkmf.log

current directory: /usr/local/rvm/gems/ruby-2.3.0@railstutorial_rails_4_0/gems/sqlite3-1.3.8/ext/sqlite3
make "DESTDIR=" clean

current directory: /usr/local/rvm/gems/ruby-2.3.0@railstutorial_rails_4_0/gems/sqlite3-1.3.8/ext/sqlite3
make "DESTDIR="
compiling database.c
compiling backup.c
compiling exception.c
compiling statement.c
statement.c: In function ‘bind_param’:
statement.c:261:7: warning: implicit declaration of function ‘RBIGNUM’ [-Wimplicit-function-declaration]
       if (RBIGNUM_LEN(value) * SIZEOF_BDIGITS <= 8) {
       ^
In file included from statement.c:1:0:
./sqlite3_ruby.h:16:34: error: invalid type argument of ‘->’ (have ‘int’)
 #define RBIGNUM_LEN(x) RBIGNUM(x)->len
                                  ^
statement.c:261:11: note: in expansion of macro ‘RBIGNUM_LEN’
       if (RBIGNUM_LEN(value) * SIZEOF_BDIGITS <= 8) {
           ^
statement.c:261:32: error: ‘SIZEOF_BDIGITS’ undeclared (first use in this function)
       if (RBIGNUM_LEN(value) * SIZEOF_BDIGITS <= 8) {
                                ^
statement.c:261:32: note: each undeclared identifier is reported only once for each function it appears in
statement.c: In function ‘reset_bang’:
statement.c:293:7: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
   int status;
       ^
statement.c: In function ‘clear_bindings’:
statement.c:313:7: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
   int status;
       ^
make: *** [statement.o] Error 1

make failed, exit code 2

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.3.0@railstutorial_rails_4_0/gems/sqlite3-1.3.8 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.3.0@railstutorial_rails_4_0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.8/gem_make.out

I will remove sqlite version in gemfile hope it helps

Community
  • 1
  • 1
user2950593
  • 9,233
  • 15
  • 67
  • 131
  • why downwote? Did I miss something? I print the command get an error. Did what I was promt, got strange output and asked a question here providing details. Whoever downvoted me explain what is wrong with this question? – user2950593 Feb 18 '16 at 17:28
  • quoting your stacktrace: `Cannot allocate memory` – mmln Feb 18 '16 at 17:30
  • @mymlyn okay see an update please – user2950593 Feb 18 '16 at 17:35
  • if I had to guess would be associated with not being aware of where gcc is: http://stackoverflow.com/questions/6119153/why-do-i-get-a-bcrypt-ruby-gem-install-error – Drew Feb 18 '16 at 17:36
  • Try stopping postgres and your rails server, then run bundle update again. – Robert Nubel Feb 18 '16 at 17:38
  • @RobertNubel see update 3 – user2950593 Feb 18 '16 at 17:44
  • @Drew see an update 2 - i print it as suggested in question you posted - it doesn't work – user2950593 Feb 18 '16 at 17:45
  • You're still running out of memory (hence why Postgres can't start up again). Stop every process on your machine that you can, and use the top command to monitor how much memory you have free/used. – Robert Nubel Feb 18 '16 at 17:47
  • use `htop` to track the process that eats your memory, also yout could use `df` to check your disk space, btw for that price you could get 4 times more ram, fighting lack of ram is usually not worth it unless of course you want to learn how stuff works and have time to spare :) – mmln Feb 18 '16 at 17:48
  • @RobertNubel so I did htop to see processes as suggested by mymlin. See `update4` Should I kill all of them? How do I kill process btw? – user2950593 Feb 18 '16 at 17:54
  • 1
    It doesn't look like there are any more processes you can kill, at this point, and you've got just about all the RAM free you can get on your droplet. Try `bundle update rails` again and see if it works. If not, the easiest solution is to get more RAM; otherwise, you might be able to use compiler flags to tune gcc to use less memory when compiling. – Robert Nubel Feb 18 '16 at 17:55
  • @mymlyn if it will solve it would be awesome. I will check if it possible to add ram without destroying a droplet if not I will create a new one. Time is a very preciousthing, I can't afford right now digging so deep=) – user2950593 Feb 18 '16 at 17:57
  • @RobertNubel see update 5=) – user2950593 Feb 18 '16 at 18:03

1 Answers1

0

your issue is related to lack of memory, quoting your stack trace: Cannot allocate memory

considering unicorn workers eat up all your ram you should reduce amount of workers, some more info here,

i noticed that you already killed all the processes; deploy your app, if itll have enough ram everything should go fine (btw: check htop while deploying), if issue persists, there either is memory leak somewhere (update gem versions) or you simply got not enough ram - as i said for that price you should get 4x the resources elsewhere

if you are running all those commands live on your server, you should consider using capistrano in future

regarding Update 5: you should run gem install bundler (I assume you dont have rvm?)

mmln
  • 2,104
  • 3
  • 24
  • 33
  • yeah I run this with ssh connection... I am not sure if I can deploy it - now it gives me an error you can see it in update 5=) – user2950593 Feb 18 '16 at 18:07
  • okay I will consider capistrano. When I will be deploying another rails app in the future) – user2950593 Feb 18 '16 at 18:09
  • bundler itself is a gem which should be installed in the gemset youre using, updated my answer – mmln Feb 18 '16 at 18:11
  • Nope I have it - rvm 1.26.11 ( I guess it was pre installed with droplet) – user2950593 Feb 18 '16 at 18:16
  • Thanks, about bundler=) – user2950593 Feb 18 '16 at 18:16
  • well it gave me another error `An error occurred while installing sqlite3 (1.3.8), and Bundler cannot continue. Make sure that `gem install sqlite3 -v '1.3.8'` succeeds before bundling.` – user2950593 Feb 18 '16 at 18:22
  • I guess I should change version of sqlite – user2950593 Feb 18 '16 at 18:22
  • I do not even need it cause it's production – user2950593 Feb 18 '16 at 18:24
  • yeah bundle update now went allright and bundle install – user2950593 Feb 18 '16 at 18:31
  • can you see this question please http://stackoverflow.com/questions/35489976/rails-postgersql-connection-could-not-connect-to-server-connection-refused – user2950593 Feb 18 '16 at 18:51
  • sorry i can't ask mpre than 6 questions in 24 hours so I will ask you here. I managed to deploy my app but something wen wrong and there is a message that page is unavailable. where I can see app's logs? – user2950593 Feb 18 '16 at 20:06
  • if you're sure its your app thats throwing an error its in your apps root folder `app_root/logs/your_environment.log`, error could also be related to nginx (if thats what youre using) and unicorn – mmln Feb 18 '16 at 20:13
  • what if I have nothing in production.log? – user2950593 Feb 18 '16 at 20:37
  • then most likely the request did not hit your application at all and is stuck on nginx or unicorn instead (or something else, not sure what your stack is... and youre hot fixing production) – mmln Feb 18 '16 at 20:40