Change unicorn port from 3000 in development

A recent commit changed the “unicorn port” from 9292 to 3000. I don’t see any way to change the port now and this is confliciting with another rails site I have running on 3000. Previously, I’ve been running discourse as bundle exec rails server --port=3001, but this no longer works as unicorn is now grabbing 3000.

Tried a few combinations of UNICORN_PORT=3001, --port=3001, changing source code of unicorn.conf, but end up with:

I, [2018-08-14T11:26:11.496753 #63852] INFO – : listening on addr=0.0.0.0:3000 fd=20

Each time.

Any way to work around this?

Changed that line in bin/rails to point to 3001 and it seems to work now. Should that line be an ||=?

Why do you have another Rails site running in the same container as Discourse?

Donno, Matt. I followed Beginners Guide to Install Discourse on macOS for Development which didn’t have me setting up containers (I’m assuming you’re referring to Docker or something related?).

There are 2 schools of thought when it comes to launching a rails server in development.

The @sam school of thought, where you want to keep console pristine cause you are a fanatical puts debugger. That way you can just add puts statements around the app and see the output in the same window you run the server.

If you subscribe to @sam’s school of thought you launch your rails server with:

bin/unicorn

If you want a different port, you run

bin/unicorn -p 7777

The other school of thought is the @tgxworld school of thought / Rails official setup. In this case are not a puts debugger and want to see all the debug rails logs in the console.

If you are like this you would launch unicorn in dev via

bin/rails s

If you want a custom port you will use

bin/rails s -p 7777

Note, I had to push a few fixes to make this post true, so pull latest.

12 Likes

You rock, @sam, cheers!

2 Likes

Or you subscribe to @LeoMcA’s school of thought, where you’re a fanatical puts debugger, but launch with rails s, so you have to squint really hard to see what you want among all the rails logs.

I feel like a fool.

6 Likes

Yeah, I launch my local dev with Puma via Foreman so I think I get “puts” in the Foreman logs and “logger.log” in the Rails log, so I think I’m with the @sam school in my other project. Nice to have these two schools for Discourse local dev now!

2 Likes

FYI, foreman support has just been removed per:

2 Likes

I just added an option to avoid all that squinting, you can now use

DISCOURSE_DEV_LOG_LEVEL="warn" bin/rails s

to see puts statements locally without the noise.

13 Likes

Nice! I’ve been using RAILS_LOGS_STDOUT=0 rails s, but this allows showing warnings/errors rather than binning everything :heart_eyes:

9 Likes

I’m starting to incline towards this school of thought lately :wink:

3 Likes