1
votes

SECRET_KEY_BASE missing error on production while I have placed secret token export command in .profile and .bashrc

my export command is like this:

export SECRET_KEY_BASE=21021dd33712b563e*******************

in pumma access logs it shows me this error

2015-12-23 06:32:28 -0500: Rack app error: #<RuntimeError: Missing    `secret_token` and `secret_key_base` for 'production' environment, set     these values in `config/secrets.yml`>
 /home/deploy/apps/pulsemedia/shared/bundle/ruby/2.2.0/gems/railties-  4.2.5/lib/rails/application.rb:534:in `validate_secret_key_config!'
 /home/deploy/apps/pulsemedia/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/application.rb:246:in `env_config'
 /home/deploy/apps/pulsemedia/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/engine.rb:514:in `call'
 /home/deploy/apps/pulsemedia/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/application.rb:165:in `call'
 /home/deploy/apps/pulsemedia/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/configuration.rb:79:in `call'
 /home/deploy/apps/pulsemedia/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/server.rb:541:in `handle_request'
 /home/deploy/apps/pulsemedia/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/server.rb:388:in `process_client'
 /home/deploy/apps/pulsemedia/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/server.rb:270:in `block in run'

Here is my secrets.yml file

 production:

    secret_key_base: <%= ENV['SECRET_KEY_BASE'] %>

I try ENV['SECRET_KEY_BASE'] in rails console production it shows me key there but I don't know whats happening.

Note: I am using rails 4.2.1

2
Are you certain your puma process is running under the same account as your environment variable? Also ... you might find that your puma process does not trigger the execution of your .profile or .bashrc files. - Jon
yup I manually ran these commands as well but nothing happend. - Asad Ali
what web server do you use on production (unicorn/passenger etc)? it can lose custom environment variable. - andrykonchin

2 Answers

0
votes

I killed pumma process and restart using this command

bundle exec puma -C /home/deploy/path_to/shared/puma.rb

Woked for me.

-2
votes

Type on your shell

   rake secret

Then replace

    <%= ENV['SECRET_KEY_BASE'] %> 

with the result.