Will ruby on rails project start automatically when thin start - ruby-on-rails

As question state.
I'm trying to start ruby on rails when machine reboot.
I feel I have successfully auto start thin.
But my ROR page is still not working.
ie:when I open localhost:3000 ,this page cant get displayed.
Is ror project start automatically when thin start?
if not,what setting do I need to do?
I'm using ubuntu, ror project under /home/usr/test

You need to tell thin that which application you want to run automatically along with thin.
sudo thin config -C /etc/thin/testapp.yml -c /home/usr/test --servers 3 -e production
You can cross check the setting:
cat /etc/thin/testapp.yml
It should display something like:
---
pid: tmp/pids/thin.pid
address: 0.0.0.0
timeout: 30
port: 3000
log: log/thin.log
max_conns: 1024
require: []
environment: production
max_persistent_conns: 512
servers: 3
daemonize: true
chdir: /home/demo/public_html/testapp
Source: Rackspace's Knowledge Center

try this out:
you have to start thin server in the directory /home/usr/test.
try running thin by command bundle exec thin start.

Related

Rails 5 Address already in use - bind(2) for "127.0.0.1" port 3000

After some coding got this error on running rails s:
Address already in use - bind(2) for "127.0.0.1" port 3000 (Errno::EADDRINUSE)
My environment is:
$ rails -v
Rails 5.0.0
$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
I've tried:
Create a new project - the same
Checked Rails 4.2 - problem solved
Reinstall rails 5 and ruby - the same problem
lsof -wni tcp:3000 returns me nothing
ps aux | grep "rails" - nothing
ps aux | grep "puma" - nothing
ps aux | grep "ruby" -nothing
Use puma instead of rails s - problem solved
Use rails s -p 3001 - same problem, for other ports too
UPDATED
Use RAILS_ENV=production bundle exec rails s - problem solved
Any suggestions?
The same process is running somewhere
To see which process used 3000 port and get the process pid type below command
lsof -wni tcp:3000
This will give the process which is using this port
Sample result
process1 12345 0.0 0.0 12343566 1972 s000 R+ 11:17AM 0:00.00 grep puma
You can kill this process by typing below command
12345 this is the process ID
kill -9 12345
Now start server again
The problem appeared because of a bug in Puma's code. Downgrading to the oldest version helped me.
Bug ticket: https://github.com/puma/puma/issues/1022
What your error is saying is that there is something already running on port 3000. Without knowing more about your environment or what you have installed, it's impossible to know what to stop.
It's highly likely that another rails server is already running somewhere. Try going to localhost:3000 to see what's there.
It's possible that another program is piggybacking on this port for some unknown reason, if so and you can't stop it, use a differnt port
rails s -p 3001
or any other port you choose

Thin processes die without message

I have two Thin servers running for a Rails app. I start them up with bundle exec thin start.
chdir: /[root]/current
environment: production
address: 0.0.0.0
port: 3001
timeout: 30
log: /[root]/log/thin.log
pid: tmp/pids/thin.pid
max_conns: 1024
max_persistent_conns: 100
require: []
wait: 30
threadpool_size: 20
servers: 2
daemonize: true
When I wait a few hours usually one of the two servers is gone (e.g., only see one with htop or with pgrep -lf thin). And even worse, sometimes both of them are gone after 10 hours or so which results in a 500 error via the browser. Furthermore, when I start 3 or 4 servers 2 of the 4 processes die within 1 minute on average.
I don't see error messages in my Rails production.log nor in the thin.[port] log files specified in the app.yml file.
Is there a way to keep the Thin servers running?
Are you sure you can run your server with bundle exec -C app.yml start?
Try bundle exec thin -C app.yml start

Force Port in Foreman changes from 3000 to 3100

I have a .foreman file with the following line:
port: 3000
Then in my Procfile.dev I have the following:
web: bundle exec rails server -p $PORT
However, when running the server by doing:
foreman -f Procfile.dev, Ig get the following:
Rails 4.0.0 application starting in development on http://0.0.0.0:3100
Why is that happening? Why is not starting at 3000, but at the 3100?
After digging a little bit further, I realized that in my Procfile, I have the first line as:
redis: redis-server
When moving that to the second line, and placing the:
web: bundle exec rails server -p $PORT
As my first line, it works fine. Why would that order matter at all?

Ruby - no PID found in tmp/pids/thin.pid (Thin::PidFileNotFound)

I'm trying to start thin for my app but then the pid cannot be generated:
$ thin -C /var/www/project_path/current/config/myproject.testing.yml start
Now I can't stop it because there is no pid:
$ thin -C /var/www/project_path/current/config/myproject.testing.yml stop
/home/usr/.rvm/gems/ruby-1.9.2-p180#api/gems/thin-1.5.1/lib/thin/daemonizing.rb:131:in `send_signal': Can't stop process, no PID found in tmp/pids/thin.pid (Thin::PidFileNotFound)
This is the yml file:
pid: /home/usr/htdocs/testing/myproject/shared/pids/thin.pid
rackup: config.ru
log: /home/usr/htdocs/testing/myproject/shared/log/thin.log
timeout: 30
port: 1234
max_conns: 1024
chdir: /home/usr/htdocs/testing/myproject/current
max_persistent_conns: 128
environment: testing
address: 127.0.0.1
require: []
daemonize: true
update:
Now I can start the server but after some seconds process vanish automatically; means I can't see the pid which was generated by starting the server after some seconds.
lsof -wni tcp:1234
will give you the process ID
kill -9 PID
will kill the process
I had exactly the same annoying problem
I've found that if the server crashes on startup, the pid file gets created but there is no pid in the file. Try cat'ing the log file for the server ./logs/thin.3001.log and look for errors. You could also try starting the server manually via
rails s -p 3000
and see if there are any errors thrown.
Good luck
Chris

How to restart individual servers in thin cluster in rails 3.1 app

I have a thin cluster set up to start 3 servers:
/etc/thin/myapp.yml
...
wait: 30
servers: 3
daemonize: true
...
and the I use thin restart -C /etc/thin/myapp.yml to restart. However, I would like to restart each server at a time, to reduce downtime.
Is there a way to restart each server by pid number or location for example?
There is something better for you
try option: --onebyone
you may also add the following line to your config file
onebyone: true
afterwards you able to restart you thin cluster without any downtime.
I know the question has been answered, but I'd like to add the -o option to the mix.
So
thin restart -C /etc/thin/myapp.yml -o 3000
Will only start the server running on port 3000. If let's say you have two other servers running on 3001 and 3002, they'll be left untouched.
-o works with start and stop commands too.

Resources