to start the thin server with monit is just start program = "/etc/init.d/thin start"
but to start private_pub or faye is needed to bundle the rackup.
and how to stop the pid?
someone have a idea?
check process private_pub_myapp
with pidfile "/home/ubuntu/myapp/shared/tmp/pids/private_pub.pid"
start program = "bundle exec rackup /home/ubuntu/myapp/shared/config/private_pub.ru -s thin -E production" with timeout 90 seconds
stop program = "kill -s TERM `cat /home/ubuntu/myapp/shared/config/private_pub.yml`" with timeout 90 seconds
if totalmem is greater than 200 MB for 2 cycles then restart # eating up memory?
group private_pub_myapp
monit spitting out
/conf.d/private_pub.conf:3: Warning: Program does not exist: 'bundle'
/etc/monit/conf.d/private_pub.conf:5: Warning: Program does not exist:
'kill'
You always need to give a full, absolute path when using Monit. For example start program = "/usr/local/bin/bundle exec ..." and similar. That said, I suspect this still won't work. You seem to be trying to cat the config YAML to find the PID to kill which is probably a copy-paste issue and you'll need to make sure your rackup config is actually writing out the PID file.
i've installed and running redmine in my domain. something went wrong and i cant access redmine admin panel. i tried to reset password and also did some google and changed password in database. but no luck still cant login. then i removed all app files but its still running same as before..
this was the code i used to run redmine server
bundle exec ruby script/rails server webrick -e -s production
now i'm trying to stop or restart but nothing is working.
is there any way to stop the server.
Thanks in advance.
Kill the process
kill -INT $(cat tmp/pids/server.pid)
Its cleaner to write a rake task to do that:
task :stopserver do
pid_file = 'tmp/pids/server.pid'
if File.file?(pid_file)
print "Shutting down WEBrick\n"
pid = File.read(pid_file).to_i
Process.kill "INT", pid
end
File.file?(pid_file) && File.delete(pid_file)
end
Delete the file tmp/pids/server.pid) and then restart the server.
Usually you'll hit Ctrl-C to stop webrick when it's started without -d option. The Ctrl-C makes INT signal, so youcould try with kill -INT <pid> to stop webrick started with -d option.
If it doesn't stop you can try with kill -9 <pid> sending a KILL signal, that's not a proper clean shutdown but seems the only way to stop it. It's not a 'best practice' but it's the only method i've ever found.
$ killall -9 ruby
this command wil kill all the running instance of ruby on your system and you can restart ur server again
I am new to rails and I am using an ubuntu machine and the rubymine IDE. The problem is that I am unable to stop the rails server. I tried to stop the server by killing the rails process. But, 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.
I tried ./script/server stop (since I started it by running ./script/server start), but, that didn't work. Googling around and finding some stackoverflow posts, I tried to change the localhost port's listening port but without success. Could someone help?
You can use other ports like the following:
rails server -p 3001
Normally in your terminal you can try Ctrl + C to shutdown the server.
The other way to kill the Ruby on Rails default server (which is WEBrick) is:
kill -INT $(cat tmp/pids/server.pid)
In your terminal to find out the PID of the process:
$ lsof -wni tcp:3000
Then, use the number in the PID column to kill the process:
For example:
$ kill -9 PID
And some of the other answers i found is:
To stop the rails server while it's running, press:
CTRL-C
CTRL-Z
You will get control back to bash. Then type (without the $):
$ fg
And this will go back into the process, and then quit out of Rails s properly.
It's a little annoying, but this sure beats killing the process manually. It's not too bad and it's the best I could figure out.
Updated answer:
You can use killall -9 rails to kill all running apps with "rails" in the name.
killall -9 rails
you can use grep command in following way,
ps aux | grep rails
and then
kill -9 {process_id}
pkill -9 rails to kill all the process of rails
Updated answer
ps aux|grep 'rails'|grep -v 'grep'|awk '{ print $2 }'|xargs kill -9
This will kill any running rails process. Replace 'rails' with something else to kill any other processes.
On my MAC the killall -9 rails does not work. But killall -9 ruby does.
Following are steps to kill server process:
1. lsof -i tcp:3000
2. kill -9 1234
where 1234 is the PID of process: localhost:3000 display in step 1.
OR
Remove file(server.pid) under Rails.root/tmp/pids/ and restart server.
OR
open app in another port by using command:
rails s -p 3001
I generally use:
killall ruby
OR
pkill -9 ruby
which will kill all ruby related processes that are running like rails server, rails console, etc.
1. Simply Delete the pid file from rails app directory
Rails_app -> tmp -> pids -> pid file
Delete the file and run
rails start
2. For Rails 5.0 and above, you can use this command
rails restart
If you are using a more modern version of Rails and it uses Puma as the web server, you can run the following command to find the stuck Puma process:
ps aux | grep puma
It will result in output similar to this:
85923 100.0 0.8 2682420 131324 s004 R+ 2:54pm 3:27.92 puma 3.12.0 (tcp://0.0.0.0:3010) [my-app]
92463 0.0 0.0 2458404 1976 s008 S+ 3:09pm 0:00.00 grep puma
You want the process that is not referring to grep. In this case, the process ID is 85923.
I can then run the following command to kill that process:
kill -9 85923
Use ctrl+c to shutdown your Webrick Server.
Unfortunately if its not works then forcefully close the terminal and restart it.
Another trick is that
1. open your system-monitor(a gui application) on ubuntu
2. Select processes tab
3. Then look for a process having name 'ruby'
4. End that process
Delete the server.pid from tmp/pids folder.
In my case, the error was: A server is already running. Check /home/sbhatta/myapp/tmp/pids/server.pid.
So, I delete server.pid
rm /home/sbhatta/myapp/tmp/pids/server.pid
then run rails s
Ctrl-Z should normally do the trick.
Step 1: find what are the items are consuming 3000 port.
lsof -i:3000
step 2 : Find the process named
For Mac
ruby TCP localhost:hbci (LISTEN)
For Ubuntu
ruby TCP *:3000 (LISTEN)
Step 3: Find the PID of the process and kill it.
kill -9 PID
it's as simple as
pkill -9 ruby
nothing more nothing less
I used killall -9 rails like Sri suggested and it didn't work. I adjusted the command to killall -9 ruby and the server closed immediately.
Tl;dr: killall -9 ruby
When the rails server does not start it means that it is already running then you can start by using new port eg.
rails s -p 3001
or it starts and stops in that case you want to delete temp folder in rails directory structure it starts the rails server.
check the /tmp/tmp/server.pid
there is a pid inside.
Usually, I ill do "kill -9 THE_PID" in the cmd
I have noticed on Windows (Im using 10 but not sure if the same for oler). If you use cmd.exe and ctrl + c the raisl server stops correctly.
However, if you use Git Bash, it doesn't. It says it has but when you look at the tmp pids, its still there.
Maybe a bug with git bash?
killall -9 ruby will kill all the ruby processes, and at-least on my machine, rails servers appear as ruby processes. killall -9 rails is much more specific and doesn't work for older versions of rails servers (it gives a 'rails:no process found' because the process is named ruby)
Encountered this problem a while ago. After submitting a form in activeadmin, the rails server just hanged and I was unable to kill it using normal means (even after ctrl+z it was still running in the background). Learner's answer helped, but this command doesn't need process id.
Follow these steps:
open your project
select in tmp folder
select pids folder
delete server.pid file
now start your rails server
On rails 6 using
ps aux | grep rails was not returning the server process
I had to do
ps aux | grep puma
to find the actual process and then kill it using
kill -9 {process_id}
It is late for this question.
Here is my 2 cents. I made a rake task for stopping the server when I don't have access to it.
I only tested on Mac though.
With this you can simply add it to your project then run the rake command.
Here you go:
Gist link: -latest version will be here.
https://gist.github.com/houmanka/289184ca5d8d92de0499#file-server-rake
Some code in here:
# Make a file under: `project_root/lib/tasks/server.rake`
# Then paste the following code
namespace :server do
desc "Stop the running server by killing the PID"
task :kill do
STDOUT.puts "Enter port number: "
post_number = STDIN.gets.strip
system "pid=$(lsof -i:#{post_number.to_i} -t); kill -TERM $pid || kill -KILL $pid"
end
end
# Then to use it in the terminal: `rake server:kill`
Also, Make sure that you are doing command Cntrl+C in the same terminal (tab) which is used to start the server.
In my case, I had 2 tabs but i forgot to stop the server from correct tab and i was wondering why Cntrl+C is not working.
One super easy way would be
gem install shutup
then go in the current folder of your rails project and run
shutup # this will kill the Rails process currently running
You can use the command 'shutup' every time you want
DICLAIMER: I am the creator of this gem
NOTE: if you are using rvm install the gem globally
rvm #global do gem install shutup
For my windows 10 machine, Ctrl - C + Ctrl - D works.
We can kill rails session on Linux using PORT no
fuser -k 3000/tcp
here 3000 is a port no.
Now restart your server, you will see your server is in running state.
Just open the file using the location given
sudo vi /Users/user1/go/src/github.com/rails_app/rails_project/tmp/pids/server.pid
find the process_id / thread_id at which the process is runnning.
Kill the specified process / thread using kill -9 84699
Press Ctrl - C it will stop
if not check
i'm planning to add some tasks to my capistrano recipes file to give ability for admins to remote start/stop/restart private_pub server. But if for start i can use something like
desc "Start private_pub server"
task :start do
run "cd #{current_path};rackup private_pub.ru -s thin -E production -D"
end
i cannot find any documentation how to stop or restart rackup server. i see option
-P, --pid FILE file to store PID (default: rack.pid)
but maybe use kill command to stop server - not good idea?
I found this while searching for the same solution.
gist.github.com/3197633
basically while starting the process you have it write the pid number to a file in /tmp/pids and then when you go to stop it you read that file and it runs kill -9 ...
Hope it helps.
Your'e correct in that using kill -9 is a bad idea. This can lead to uneccesary loss of data, and as I understand it is recommended to use kill 2 or kill -INT which is equivalent to hitting 'control-c' and should close a normal server for you. I personally have started managing my servers with the God gem by TPW. Here is the script I use for running a local 'geminabox' server, for instance:
God.watch do |w|
w.name = 'gemserver'
w.dir = '/usr/local/gemserver'
w.pid_file = "#{ENV['HOME']}/.god/pids/#{w.name}.pid"
ru = File.expand_path `which rackup`
w.start = "#{ru} -D #{w.dir}/config.ru -P #{w.pid_file}"
# w.stop = lambda { Process.kill(3, `lsof -i :9292`.chomp.to_i) }
w.behavior :clean_pid_file
w.keepalive
end
If you start a Rails app with the script/server command, what command do you use to stop it?
You may not have a pid file to kill if you are using a server like webrick, but you can get at it with:
ps aux | grep ruby
which should show you all your Ruby processes, then kill the process running the server: kill x, where x is the process number.
Note that you will need to be running as the user running the Ruby command, otherwise sudo is in your future.
cat out the following file in your Rails tree:
tmp/pids/server.pid
and send any variety of kill command to that pid, or simply execute the following (assuming your tree looks like: /my/rails/app:
kill -9 $(cat /my/rails/app/tmp/pids/server.pid)
pgrep ruby
to see what servers are running and then:
kill -9 serverNumber
To kill the server.