How to start foreman in production mode(ENV) - ruby-on-rails

Is it possible run the rails foreman in production mode in local terminal?

Yes. Set the RAILS_ENV variable to production.
$ RAILS_ENV="production" foreman start

RAILS_ENV env value will be overridden by the .env file when foreman starts.
However, you can start foreman with --env option:
foreman start --env .env,production.env
# production.env
RAILS_ENV=production
RAILS_SERVE_STATIC_FILES=enabled

Related

foreman in test environment?

Simple question. How to start Rails using Foreman in test env?
RAILS_ENV=test bundle exec foreman start
// starts in develop
bundle exec foreman -e test start
// bombs
bundle exec foreman start -e test
// bombs
Foreman has to point to a Procfile, or Procfile has to exist in the current directory.
# Procfile
rails s
Then you'd run
foreman start -f Procfile
It's common practice to keep a Procfile.test, Procfile.dev, etc.
# Procfile.test
rails s -e test
Hope that helps :)

God using sudo fails to find the environment parameter SECRET_KEY_BASE in the .bash_profile file

I added those rows to /home/web/.bash_profile. The web is the user of Rails app.
SECRET_KEY_BASE=xxxxxxxxxxxxxxxxxxxxx
export SECRET_KEY_BASE
I added this row into /etc/sudoers.
Defaults env_keep += "SECRET_KEY_BASE"
This command returns expected result.
sudo ruby -e 'puts ENV["SECRET_KEY_BASE"]'
If I run Unicorn without God, it can find SECRET_KEY_BASE from environment, and performs normally.
bundle exec unicorn_rails -c config/unicorn.rb -E production -D
Running Unicorn using sudo without God performs normally, too.
sudo bundle exec unicorn_rails -c config/unicorn.rb -E production -D
But when I run Unicorn with God using sudo, it failed to find SECRET_KEY_BASE and becomes error.
sudo god start my_app
The start command in the my_app.god is this.
God.watch do |w|
w.start = "cd #{rails_root} && bundle exec unicorn_rails -c config/unicorn.rb -E #{rails_env} -D"
w.uid = 'web'
w.gid = 'web'
...
end
It seems that the problem exists around God rather than .bash_profile and Unicorn. Besides what should I try?
I added this line into the my_app.god
ENV["SECRET_KEY_BASE"] = 'xxxxxxxxxxxxxxxxxxxxxxxx'
I know that this isn't a cool solution, but it works. And SECRET_KEY_BASE isn't included in a Git repository as source code.

Supervisord with rails - can't find command 'RAILS_ENV=production'

I try to run sidekiq service with supervisord
Here's my config:
[program:my-app-sidekiq-staging]
directory=/srv/www/DOMAIN/current
command=RAILS_ENV=production /usr/local/rvm/bin/rvm ruby-2.2.2#my-app-staging do bundle exec sidekiq -e production -d -C config/sidekiq.yml -L log/sidekiq.log
autostart=true
autorestart=true
redirect_stderr=true
After startup I’m have fatal error:
can't find command 'RAILS_ENV=production'
I’m confused, because my config for rails runs without errors
directory=/srv/www/DOMAIN/current
command=RAILS_ENV=production /usr/local/rvm/bin/rvm ruby-2.2.2#my-app-staging do bundle exec passenger start -S tmp/unicorn/ilp-app-unicorn.sock --environment production --friendly-error-pages
Your environment should not be set in the command but in a separate environment value.
environment=RAILS_ENV=production
See this question.
Supervisor and Environment Variables

rvmsudo unicorn_rails -c config/unicorn/production.rb -D --env production is not working

I have installed new ec2-instance for production server
when i tried the following command in the current folder
[ec2-user#ip-xx-xxx-xxx-xxx current]$ rvmsudo unicorn_rails -c config/unicorn/production.rb
-D --env production
sudo: unicorn_rails: command not found
Please let me know how to start the production server which is running at port 80.
Thanks in advance
For port 80: First run
export rvmsudo_secure_path=1
then
rvmsudo unicorn_rails -c config/unicorn/production.rb -D --env production
it will work for sure
You dont have to use rvmsudo and all to start your unicorn app server. You can do it
bundle exec unicorn -D -c /path/to/app/unicorn.rb -E production

How to start rails server in production mode using unicorn and config file?

I add Gem 'unicorn' to Gemfile and call rails server unicorn -e production, but I get a load error. Then I add Gem 'unicorn_rails', then call rails server unicorn -e production, but I can't find the socket file. So I am considering if it doesn't use the config/unicorn.rb file as the configuration? So I call unicorn_rails -c config/unicorn.rb -E production -D, but I get another error text file busy.
So now I am stuck in this matter, could you help me? :)
It should be something looks like:
bundle exec unicorn -E production -c config/unicorn.rb
and you should only need unicorn gem
bundle exec unicorn -p $PORT -c ./config/unicorn.rb
works for me
I put it in the Procfile and then use Foreman to start it off by entering
foreman start
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
service unicorn_projectName start
works for me

Resources