Why I am not able to run Unicorn RoR - ruby-on-rails

I am trying to install a RoR server on Amazon EC2 using Amazon Linux and Ansible. Everything goes through fine, at the end I am not able to run unicorn. I have checked that unicorn gem is installed
`gem list | grep unicorn`
showed unicorn installed.
When I type
`unicorn_rails`
I get command not found error. I checked my gem file and it has the line gem unicorn then I run bundle install and the output has unicorn in the list. Still not able to run it.
Thanks.

I'm not sure that you can run unicorn_rails. Just use:
bundle exec unicorn -p <port> -c <path_to_config_file>
For example:
bundle exec unicorn -p 3000 -c ./config/unicorn.rb

If you are using bundler run unicorn with bundle exec:
$ bundle exec unicorn_rails
Find out more here.

Related

Ubuntu run Puma and Sidekiq in background as Daemonized processes

Two years ago I was running the following command:
bundle exec puma -C config/puma.rb -b unix:/home/user/site/shared/tmp/sockets/user-puma.sock -d
bundle exec sidekiq -d
But now, after some Ubuntu updates, the -d flag is deprecated and I can't start the Puma and Sidekiq processes to run in background.
I also tried running:
bundle exec puma -C config/puma.rb -b unix:/home/user/site/shared/tmp/sockets/user-puma.sock &
bundle exec sidekiq &
This works only while I'm logged on the SSH, when I close the SSH connection, all processes opened with & are closed.
How can I run Puma, Sidekiq and other processes in background as Daemons?
What works for me is setting up my own systemd service for sidekiq
A well-documented example file is in the sidekiq github repository
Along with this, I'd also recommend using monit to watch background processes... here's a recipe from Lugo Labs that I loosely base my deploys off of

Delayed_job restarting manually works, but not via crontab

If I run my script manually, i.e. sh /home/deploy/scripts/cleanup.sh, everything works fine, but when executing the same script via crontab, the delayed_job part does not work (everything else works!)
# Restart all processes
cd ~/apps/kosher/current
~/.rvm/bin/rvm default do bundle exec pumactl -S /home/deploy/apps/kosher/shared/tmp/pids/puma.state -F /home/deploy/apps/kosher/shared/puma.rb stop
~/.rvm/bin/rvm default do bundle exec puma -C /home/deploy/apps/kosher/shared/puma.rb --daemon
if RAILS_ENV=production bin/delayed_job restart
then
echo "kosher delayed_job restarted" >> /home/deploy/scripts/cleanup.log
else
echo "kosher delayed_job restart failed" >> /home/deploy/scripts/cleanup.log
fi
I tried to use ~/.rvm/bin/rvm default do bundle exec bin/delayed_job -n 1 restart instead of RAILS_ENV=production bin/delayed_job restart, but then I receive an error, stating, that I'm missing the listen-gem:
bundler: failed to load command: bin/delayed_job (bin/delayed_job)
LoadError: Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile
However, my Gemfile does indeed include the gem.
Why can't I restart delayed_job via crontab?

start unicorn on startup

I'm using Rails 4 + Nginx + Unicorn and I want that when my raspberry pi is rebooted it should run Rails application on startup.
Issue: The Nginx is running but unicorn is not running.
I've put in /etc/rc.local file the following command
cd /opt/www/RAILSAPP/current && bundle exec unicorn -E production -c config/unicorn.rb -D
but its not up when I'm rebooting. when I'm accessing the pi via ssh and run the command its working.
How can I start unicorn on startup in order to serve the rails app?

master failed to start, check stderr log for details

I'm trying to start unicorn and I keep getting this error constantly.
My unicorn.rb (https://gist.github.com/anonymous/d1f3d9bcdd1a6c4d8435)
Command that I'm using to start unicorn:
/home/app/adsgold/# unicorn_rails master -c config/unicorn.rb -D -E production
Commands that I've already tried:
/home/app/adsgold/# unicorn_rails -c config/unicorn.rb -D -E production
/home/app/adsgold/# unicorn_rails master -c config/unicorn.rb -D -E production -p 3000
/home/app/adsgold/# bundle exec master unicorn -c unicorn.cnf -E production -D
Complete error beeing shown: https://gist.github.com/anonymous/828d9677f928fa671762
It looks you have RVM and Ruby installed system-wide. Generally it may cause lots of issues. Even RVM documentation warns about that. Try to install RVM and Ruby as user, which owns app directory. In that case you will get consistent system.
By the way, do you have this directory /home/deploy/apps/shared on your environment? Is it writable for your App? According Unicorn config following things depend on it:
pid "/home/deploy/apps/shared/pids/unicorn.pid"
stderr_path "/home/deploy/apps/shared/log/unicorn.stderr.log"
stdout_path "/home/deploy/apps/shared/log/unicorn.stdout.log"
If you do have all this stuff, content of /home/deploy/apps/shared/log/unicorn.stderr.log also would be helpful.
Are the necessary permissions in place? (I notice the read error comes from a globally-installed gem, so I'm wondering what all is where.)

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