foreman start doesn't seem to bind puma socket in development - ruby-on-rails

I'm working a Rails application ran into some problems with a 502 error when I tried to go to our staging site. This thread had the answer I needed by adding to puma.rb:
application_path = '/home/deploy/hotel-automata/shared'
bind "unix://#{application_path}/sockets/puma.socket"
I was also able to start the server in development by running foreman start -p 3000. The question I have is how does this not throw an error? The application_path I have definitely doesn't exist in my local computer and running bundle exec puma or bundle exec rails server threw an error on file not found. Is this something that's specific to foreman or am I missing something? I looked around for a while but couldn't find anything related to this.
Also, is this the best way to do this? I feel that using an exact path might not be the best way here but I'm not sure what else I should do. Any suggestions on this point would be much appreciated too.
Also, here's my Procfile:
web: bundle exec rails server
redis: redis-server
sidekiq: bundle exec sidekiq

Related

Bundler won't find puma when deploying Rails 5 app

Just FYI, this is the first time I'm deploying something on a production server. I went through this guide as my server is also hosted on DO.
The environment is pretty much the same - I'm using Ubuntu 14.04, Ruby 2.3.3 (rbenv) and rails 5.
I followed everything step by step and I have gotten no error, however, now I'm getting a 502 bad gateway when accessing my public IP.
I have noticed that for some reason after starting puma manager (sudo start puma-manager), the directory "shared/sockets/puma.sock" is not getting created.
When I start puma manually by using -> RACK_ENV=production bundle exec puma -C config/puma.rb from my app directory, I get the following error:
bundler: failed to load command: puma (/root/.rbenv/versions/2.3.3/bin/puma)
Errno::ENOENT: No such file or directory - connect(2) for /root/belooga/shared/sockets/puma.sock
Any idea of what I might be doing wrong? Should you need to see any file, please let me know and I'll provide anything that might be needed.
Cheers!
EDIT:
I have double-checked all the paths in:
myapp/config/puma.rb
/etc/puma.conf
/etc/nginx/sites-available/default
... the directory "shared/sockets/puma.sock" is not getting created.
Here is your problem, create the directory before you start the puma server.

How do I keep sidekiq always up on Heroku?

Whenever I run heroku run bundle exec sidekiq, I see all my background jobs being done, however, I want them to be able to go without me needing to be there. When I exit out of that terminal tab, sidekiq stops working. How would I mitigate that?
Also, I've read something about procfiles and increasing workers. I don't know what procfiles are and I don't know how to increase workers either.
Basically, I'm a newbie trying to get sidekiq set up to run on Heroku for my Rails app. I want it to be running at all times.
Create a file named ./Procfile with the following in it:
web: bundle exec rails server -p $PORT
worker: bundle exec sidekiq
sidekiq on Heroku
more on Procfiles
foreman gem

Heroku/ruby on rails... how can I figure out if I'm running as a worker or a web

I have an app on (ruby/rails) heroku. It's running 1 web and 1 worker (for example)
I want to be able to tell what "type" of dyno the app is running under.
I suspect it's a simple thing to tell, but I can't see anything that tells me how to tell.
I don't know if there's a more elegant way to do this, but you can set an environment variable in your Procfile:
web: bundle exec ... PROC_TYPE=web
worker: bundle exec ... PROC_TYPE=worker
Then in your rails code, you can check ENV['PROC_TYPE']
EDIT: more detailed Procfile example, typical for a rails app:
web: bundle exec rails server -p $PORT PROC_TYPE=web
worker: bundle exec rake jobs:work PROC_TYPE=worker

Rails server hangs when started with foreman

Here's what my Procfile looks like:
web: bundle exec rails server thin -p $PORT -e $RACK_ENV
worker: bundle exec rake jobs:work
I intend to add a worker process because I wish to run some background jobs. I'm following these instructions
This is what I noticed:
No problems encountered if the worker is started separately.
When I keep the second line in the Procfile and don't not change anything else, the rails server serves a couple of requests and hangs after that
As mentioned here , I've added STDOUT.sync = true to config/environments/development.rb and verified the same in the rails console. Did not work.
Tailed log/development.log and compared it against the stuff that foreman outputted to the shell and noticed that both matched for a couple of requests and then foreman stopped printing out stuff to the shell - the next request would then hang
I updated foreman using foreman.pkg as mentioned here and verified the same with [6]
It was mentioned here that this might be caused due to a stray debug statement. I'm not using the debugger and I do not have the pry gem or the ruby-debug gem in my Gemfile.lock
I believe the symptoms are similar to this related unanswered question
Please help!
[6]:
which foreman
/usr/bin/foreman
ls -lah /usr/bin/foreman # checked the updated date
Tracked and resolved here:
https://github.com/ddollar/foreman/issues/244
TL;DR: Install the gem, don't use foreman.pkg
I'll add than if you're using Heroku, the foreman version included with the heroku toolbelt has the same issue.
Use the one you can get with gem install foreman instead.

'foreman start' is stuck

I have a locally developed Rails application. It is very simple, with no database but only a controller that accesses Facebook data and renders them in view. By the way, gem RestGraph is used.
Before I push this application to heroku, I used foreman start to test it. Since I was using WEBrick before I need to install 'thin' gem and create a Procfile which reads:
web: bundle exec thin start -R config.ru -e $RACK_ENV -p $PORT
an '.env' file seems also required, which reads:
RACK_ENV=development
PORT=3000
The 'config.ru' file is generate by rails, which reads:
require ::File.expand_path('../config/environment', __FILE__)
run Myapp::Application
Now I entered 'foreman start', but all I get is one line:
15:33:18 web.1 | started with pid 27143
The server will not boot. And if I force terminate it, the error is:
/usr/local/foreman/lib/foreman/engine.rb:141: [BUG] rb_sys_fail() - errno == 0
Which is not very helpful.
It may be that instead of being "stuck," your log is just being buffered: foreman only shows line with “started wit pid #” and nothing else
I solved that issue by adding
$stdout.sync = true
to config.ru
Then you might get more helpful feedback from Foreman.
This seems a little over complex. From looking at a couple of apps I have I have the following in my procfile:
bundle exec rails server thin -p $PORT
I also don't have a .env file in these instances.
One thing worth noting is that Foreman will ignore the port you pass in most of the time, it likes to sit in a port range higher than 5000

Resources