5

I am trying to run my rails server and slackbot in two processes using Procfile and gem 'foreman'.

But when I use foreman start the bot is only running the server is not starting up. I tried removing the line bot and tried to run web only but in that case, also my server is not starting up it just shows started with pid 1502. But when I start it from another terminal with rails s it starts up with no problem. I have googled a lot and can't seem to find out a solution for this. Help is much appreciated. Thanks.

This is my Procfile :

web: bundle exec rails server -p $PORT
bot: rails runner -e development slackbot/slack.rb
Amal
  • 212
  • 2
  • 9
  • What is the foreman command you are running? – Kris Sep 17 '19 at 10:04
  • @Kris ```foreman start``` – Amal Sep 17 '19 at 10:08
  • What happens when you point a browser at `localhost:3000` (or whatever the port is)? – Kris Sep 17 '19 at 10:10
  • It returns an error ```Could not get any response from server``` when i try to fire an api from postman. – Amal Sep 17 '19 at 10:25
  • Are you sure you have the right port? Try hardcoding it in the Procfile. – Kris Sep 17 '19 at 10:27
  • I tried ```bundle exec rails server -p 3000``` but still the same. – Amal Sep 17 '19 at 10:30
  • @Kris Thanks hardcoding -p 3000 worked and i would like to know when i push it to production if removing -p 3000 will work ? – Amal Sep 17 '19 at 10:35
  • Removing `-p 3000` will mean the server starts on the default port, for webrick it is 3000, but for other servers it is different. I have posted an answer. – Kris Sep 17 '19 at 14:26

2 Answers2

2

It sounds like you perhaps need to specify the port, either set the environment var PORT:

export PORT=3000
foreman start

or hardcode the port in Procfile:

web: bundle exec rails server -p 3000

or remove the -p option, in which case the default port will be used:

web: bundle exec rails server
Kris
  • 19,188
  • 9
  • 91
  • 111
0

Try the following config:

web: bundle exec rails server -p 3000
bot: rails runner -e development slackbot/slack.rb

Then run foreman start -f Procfile (or what file name you added)

Access: http://localhost:3000

Usually, I like using screen command to open the foreman process in the background, but this is not required here... it looks like: screen foreman start -f Procfile then I can just click ctrl + A + D to detach and the processes run in the background. This is useful for SSH connections e.g., EC2 instances.

Rares R
  • 209
  • 1
  • 13
  • My server is running when i hardcode 3000 but the application is not working in heroku. I guess heroku uses a different port for hosting applications do you know which port is it ? – Amal Sep 18 '19 at 07:25