Thin processes die without message - ruby-on-rails

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

Related

Sidekiq consumes too much memory

I am using Sidekiq with God in my Rails app. I am using Passenger and Nginx.
I see many processes (30-50) running by sidekiq which consume about 1000MB of RAM.
Processes like:
sidekiq 3.4.1 my_app_name [0 of 1 busy] - about 30 processes.
ruby /home/myuser/.rvm/ruby-2.1.5/bin/sidekiq --environment ... - about 20 processes.
How to tell sidekiq to not run so many threads.
my config for sidekiq (config/sidekiq.yml):
---
:concurrency: 1
:queues:
- default
- mailer
and config for sidekiq for god:
num_workers = 1
num_workers.times do |num|
God.watch do |w|
...
w.start = "bundle exec sidekiq --environment #{rails_env} --config #{rails_root}/config/sidekiq.yml --daemon --logfile #{w.log}"
The problem is with "--daemon" (or "-d") parameter which runs it as a daemon. No need to run it as daemon. Just remove this parameter.

Will ruby on rails project start automatically when thin start

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.

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 start thin process at system boot

I am using Debian flavor linux system. I am using thin web server to get live status of call in my application. This process gets started, when I use /etc/init.d/thin start. I used update-rc.d -f thin defaults to make thin process to be started at system boot. After adding the entry, I rebooted the system but thin process not getting started. I checked apache2 and it gets started properly at system boot. My thin script in init.d is as follows,
DAEMON=/usr/local/lib/ruby/gems/1.9.1/bin/thin
SCRIPT_NAME=/etc/init.d/thin
CONFIG_PATH=/etc/thin
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
case "$1" in
start)
$DAEMON start --all $CONFIG_PATH
;;
stop)
$DAEMON stop --all $CONFIG_PATH
;;
restart)
$DAEMON restart --all $CONFIG_PATH
;;
*)
echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
exit 3
;;
esac
My configuration file in /etc/thin is as follows.
user_status.yml
---
chdir: /FMS/src/FMS-Frontend
environment: production
address: localhost
port: 5000
timeout: 30
log: log/thin.log
pid: tmp/pids/thin.pid
max_conns: 1024
max_persistent_conns: 512
require: []
wait: 30
servers: 1
rackup: user_status.ru
threaded: true
daemonize: false
You need a wrapper for 'thin'.
See https://rvm.io/integration/init-d.
The wrapper path then needs substituting for DAEMON in the init.d script.
I keep forgetting this and it has cost a good few hours!
Now I've checked it out, as root, enter the two commands
rvm wrapper current bootup thin
which bootup_thin
The first creates the wrapper, and the second gives the path to it.
Edit the DAEMON line in /etc/init.d/thin to use this path, and finish off with
systemctl daemon-reload
service thin restart
I have assumed a multi-user installation of rvm, also you have to enter root
with
su -
to get the rvm environment right.

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