Foreman does not kill processes - ruby-on-rails

For start application i use Foreman.
Foreman start process from Procfile
web: bundle exec rails server thin -p $PORT
worker: bundle exec rake environment resque:work QUEUE=send_mail
api: bundle exec rails server thin -p $PORT
If i press control+C in console where i run foreman, foreman is ended but ran process is not killed. Is it possible to kill process that foreman ran when foreman killed.

Example below assumes port used is 4567, then do:
lsof -i :4567
This gives you the pid of the process, say 34564, then kill it with
kill -9 34564
If you are on windows, install cygwin to get lsof and kill commands.

Thin doesn't terminate as long as there are open connections.
Faye uses long-polling or WebSockets (long lasting connections).
So the end result is that Thin is waiting for your Faye connections to close.
Try to turn of the signal handlers installed by Thin and you should be fine.

I've assembled a little one-liner which finds the process ids and kills the processes
kill -9 `lsof -P -i :5000 | sed -n 's/python *\([0-9]*\).*\:5000.*/\1/p'`
In this case, I'm running python processes on port 5000, but you may be running some other type of processes on other ports, so you'll need to customize this one-liner accordingly.

Related

Ruby on Rails => Server is sleeping before some time

I have installed Redmine on my computer, i can run it with the command:
bundle exec rails server webrick -e production
And that's working good
But it's just for work with localhost.
I need to access to Redmine from another station. For this, i have found this command:
rails s -p 3000 -b 0.0.0.0
And that's working good, but in this case, after some time without query, the rail server turn in sleep.
And if i clic in redmine, the server don't response. I have to enter in console and press a key for wake up it.
That's working with
bundle exec rails server webrick -p3000 -b 0.0.0.0 -e production
Thanks to MAX for telling me that WebRick was a webserver

Unicorn rails server running always

I am using unicorn server for locomotive cms installed on digital ocean in ubuntu 12.04. I am wondering how I keep the server running so when I log out of the ssh session the site stays up and running.
This is currently the command I use to get it running
bundle exec unicorn_rails -p 80
Thanks! in advance
you need to set up unicorn with apache or nginx. here is a guide for apache + unicorn. with that setup you can start and stop server by starting and stopping apache service.
This is a guide on how to setup Unicorn with nginX which I have followed and used numerous times.
https://gist.github.com/billie66/3696537
Run Unicorn via bundler:
bundle exec unicorn -c config/unicorn.rb -E production -D -p 8089
Stop Unicron (if you have followed the guide from above)
kill -9 'cat /path/to/your/app/tmp/pids/unicorn.pid'

Rails deployment from foreman to supervisord

I would like to deploy my rails app, which locally runs with foreman to a server, where supervisord handles the restarts.
Unfortunatley the app throws this error and I have no idea where $PORT comes from, nor from where this part gets started. Locally everything runs nice.
My app uses redis (which is the second part in the procfile) and puma as a webserver
.../.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/uri/generic.rb:213:in 'initialize': the scheme tcp does not accept registry part: 0.0.0.0:$PORT
Check your supervisor config.
bundle exec puma -p $PORT
won't use the environment variable PORT. It should work setting the port manually.
For example:
bundle exec puma -p 3000

Unstoppable server - rails

I am using an ubuntu machine and rubymine ide. The problem is that I am unable to stop the server which makes the debugg impossible. The app I am working on is exclusively running with ssl security, so listening to the 443 port. I tried everything
when I run pgrep -l rails, no such process is found. So I am only able to kill ruby processes, but the server won't stop.
Then I tried ./script/server stop but it didn't stop the server
I tried kill -INT $(cat tmp/pids/server.pid) but there is no server.pid file inside app_root/tmp/pids
I tried lsof -wni tcp:3000, and lsof -wni tcp:443 : but no output
I tried killall -9 rails, but no rails process is found
I tried CTRL-C but the server is still running
I tried fuser -n tcp 3000 and the server is still running
You have to kill allruby processes if any are. THere are no rails process, since rails its just a framework written on ruby, so the ruby does all interpretation
you can find the process that is running the rails server with the following command. Then use kill to stop the server
ps -ef | grep rails

Stop rails server --daemon

I know how to start a Rails server with
rails server
But now i started the rails server with daemon. The result is that the server runs in the background and the commandline is accessible. Hoe can I stop this server that is running in the background. So how do I end this code?
rails server --daemon
There's no easy way that I know of, but you should be able to run
kill -9 $(cat tmp/pids/server.pid)
The default port used by a Rails server (WEBrick) is 3000. If you simply started the server with the command mentioned, use:
kill -9 $(lsof -i tcp:3000 -t)
Or you can replace the port in 'tcp:3000' with the port used in case you used some different port, although it doesn't seem so as per the details provided by you.
To list all processes which are using network, use this:
lsof -i
You can find a process listening on localhost here, use that process ID (PID) in
kill -9 PID
pkill --pidfile tmp/pids/server.pid

Resources