I have Phusion Passenger running my Ruby on Rails application on my local machine, but I'd like to be able to kill the process entirely and run a different (non-Apache) service on the same port. Unfortunately, when I kill the passenger spawn server and the httpd processes, the spawn-server restarts:
15:30:37 /usr/bin $ ps ax | grep passenger
64659 ?? S 0:00.00 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.8/ext/apache2/ApplicationPoolServerExecutable 0 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.8/bin/passenger-spawn-server /usr/local/bin/ruby /tmp/passenger.64642
15:34:43 /usr/bin $ sudo kill 64659
15:34:46 /usr/bin $ sudo kill 64642
15:34:52 /usr/bin $ ps ax | grep passenger
64698 ?? S 0:00.00 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.8/ext/apache2/ApplicationPoolServerExecutable 0 /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.8/bin/passenger-spawn-server /usr/local/bin/ruby /tmp/passenger.64681
How do I get phusion to stay dead (without rebooting the box)?
In your project directory, check out your "temp/pids" folder. There you will find that phusion passenger creates file like passenger.3000.pid, if you are running it say, on port 3000.
Now to stop this serevr on port 3000(Or any other port) just run the following command.
passenger stop --pid-file tmp/pids/passenger.3000.pid
Hm. This worked:
sudo apachectl stop
Related
My AWS instance was working fine with my app. But, today, the server was down without memory ram. Then I run:
sync; echo 1 > /proc/sys/vm/drop_caches
sudo service nginx start
After that, ram memory consumption is ok, but the app not.
I'm running a Rails 4.2.1 website with Ruby 2.2.2 and nginx/1.8.0 in a Ubuntu 14 AWS instance.
When I access the site, I have the error:
502 Bad Gateway
nginx/1.8.0
When I run passenger-config restart-app I have:
*** ERROR: Phusion Passenger doesn't seem to be running. If you are sure that it
is running, then the causes of this problem could be one of:
1. You customized the instance registry directory using Apache's
PassengerInstanceRegistryDir option, Nginx's
passenger_instance_registry_dir option, or Phusion Passenger Standalone's
--instance-registry-dir command line argument. If so, please set the
environment variable PASSENGER_INSTANCE_REGISTRY_DIR to that directory
and run this command again.
2. The instance directory has been removed by an operating system background
service. Please set a different instance registry directory using Apache's
PassengerInstanceRegistryDir option, Nginx's passenger_instance_registry_dir
option, or Phusion Passenger Standalone's --instance-registry-dir command
line argument.
In the file /var/log/nginx/error.log I have:
2021/06/19 13:21:12 [crit] 26618#0: *48688773 connect() to unix:/tmp/passenger.26EHXct/agents.s/server failed (2: No such file or directory) while connecting to upstream, client: XXX.XXX.34.163, server: www.XXX.com, request: "GET / HTTP/1.1", upstream: "passenger:unix:/tmp/passenger.26EHXct/agents.s/server:", host: "XXX.com"
I already tried this solution and not working.
When I run: passenger-config validate-install I have:
Use <space> to select.
If the menu doesn't display correctly, press '!'
‣ ⬢ Passenger itself
⬡ Apache
-------------------------------------------------------------------------
* Checking whether this Passenger install is in PATH... ✓
* Checking whether there are no other Passenger installations... ✓
Everything looks good. :-)
When I run: sudo passenger-memory-stats I have:
Version: 5.0.10
Date : 2021-06-19 13:31:40 -0300
------------- Apache processes -------------
*** WARNING: The Apache executable cannot be found.
Please set the APXS2 environment variable to your 'apxs2' executable's filename, or set the HTTPD environment variable to your 'httpd' or 'apache2' executable's filename.
---------- Nginx processes ----------
PID PPID VMSize Private Name
-------------------------------------
26615 1 230.7 MB 26.3 MB nginx: worker process
26616 1 230.4 MB 27.4 MB nginx: worker process
26617 1 229.7 MB 25.8 MB nginx: worker process
26618 1 233.3 MB 27.4 MB nginx: worker process
### Processes: 4
### Total private dirty RSS: 106.78 MB
--- Passenger processes ---
### Processes: 0
### Total private dirty RSS: 0.00 MB
Anyone knows how can I solve this?
When I ran sudo service nginx restart, I didn't notice the flag [fail] on the right of the terminal.
Then, I ran sudo service nginx status I got the message nginx is not running.
After ran sudo nginx -t I got the message
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
But I saw several nginx processes, then, I killed all nginx process with sudo kill $(ps aux | grep '[n]ginx' | awk '{print $2}') and then, sudo service nginx start.
Everything works fine again.
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
I am running Puma on Rails 4.2.1 application.
When I run the following command to start the server:
rails s
I get the following error:
puma-3.4.0/lib/puma/binder.rb:255:in `initialize': Address already in use - bind(2) for "localhost" port 3000 (Errno::EADDRINUSE)
When I look for the process that is running to kill it:
ps aux | grep ruby
I get the following:
mitchellgould 52496 0.0 0.0 2432772 648 s000 S+ 3:34PM 0:00.01 grep ruby
When I run:
sudo kill -9 52496
I get:
kill: 52496: No such process
I can start the server in another port but I would like to remove this issue and understand what is happening. Any help appreciated.
ps aux | grep puma
or
ps aux | grep rails
then copy its pid and kill the process:
kill -9 PUMAS_PID
and run the server again
chell.
Try to check port 3000, maybe this is not ruby.
lsof -i tcp:3000
Fast solution:
You can restart your OS, all ports will be reset...
Delete pid with server (your_project/tmp/pids/server.pid)
Puma
Check your config for Puma in your project and how you start puma server.
Puma start with Rails
I am trying to deploy Rails app with the Puma web server. When trying to start Puma server with a config file bundle exec puma -C config/puma.rb I get an error that the address is already in use.
Does someone know how to fix this?
bundle exec puma -C config/puma.rb
[23699] Puma starting in cluster mode...
[23699] * Version 2.11.3 (ruby 2.0.0-p353), codename: Intrepid Squirrel
[23699] * Min threads: 5, max threads: 5
[23699] * Environment: development
[23699] * Process workers: 2
[23699] * Preloading application
Jdbc-MySQL is only for use with JRuby
[23699] * Listening on tcp://0.0.0.0:3000
/.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:210:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE)
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:210:in `new'
from /Users/lexi87/.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:210:in `add_tcp_listener'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:96:in `block in parse'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:82:in `each'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:82:in `parse'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/runner.rb:119:in `load_and_bind'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/cluster.rb:302:in `run'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/cli.rb:216:in `run'
from /rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/bin/puma:10:in `<top (required)>'
from /.rvm/gems/ruby-2.0.0-p353/bin/puma:23:in `load'
from /.rvm/gems/ruby-2.0.0-p353/bin/puma:23:in `<main>'
from /.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval'
from /.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>'
You need to use kill -9 59780 with 59780 replaced with found PID number (use lsof -wni tcp:3000 to see which process used 3000 port and get the process PID).
Or you can just modify your puma config change the tcp port tcp://127.0.0.1:3000 from 3000 to 9292 or other port that not been used.
Or you can start your rails app by using:
bundle exec puma -C config/puma.rb -b tcp://127.0.0.1:3001
To kill the puma process first run
lsof -wni tcp:3000
to show what is using port 3000. Then use the PID that comes with the result to run the kill process.
For example after running lsof -wni tcp:3000 you might get something like
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ruby 3366 dummy 8u IPv4 16901 0t0 TCP 127.0.0.1:3000 (LISTEN)
Now run the following to kill the process. (where 3366 is the PID)
kill -9 3366
Should resolve the issue
you can also try this trick:
ps aux | grep puma
sample output:
myname 77921 0.0 0.0 2433828 1972 s000 R+ 11:17AM 0:00.00 grep puma
myname 67661 0.0 2.3 2680504 191204 s002 S+ 11:00AM 0:18.38 puma 3.11.2 (tcp://localhost:3000) [my_proj]
then:
kill -9 67661
Found the script below in this github issue. Works great for me.
#!/usr/bin/env ruby
port = ARGV.first || 3000
system("sudo echo kill-server-on #{port}")
pid = `sudo lsof -iTCP -sTCP:LISTEN -n -P | grep #{port} | awk '{ print $2 }' | head -n 1`.strip
puts "PID: #{pid}"
`kill -9 #{pid}` unless pid.empty?
You can either run it in irb or inside a ruby file.
For the latter, create server_killer.rb then run it with ruby server_killer.rb
SOLUTION FOR GENERAL Address already in use - bind(2) (Errno::EADDRINUSE)
This issue is because we are trying to use the same port which is already is use. so we have to stop the services running on that port so that we can run another services.
we can use kill like kill -9 {PID}where {PID} is the PID of the services running on that port. To know the PID of any services lets say "firefox" we can use commands like pidof firefox, ps aux | grep -i firefox ,pgrep firefox and then use the kill command to stop that service.
sometime we might get into the situation where we don't know the PID or the service name to search for in this case we can use the following little ruby code to do it for us.(in this case port 3000, you can change it according to your need)
#!/usr/bin/env ruby
port = ARGV.first || 3000
system("sudo echo kill-server-on #{port}")
pid = `sudo lsof -iTCP -sTCP:LISTEN -n -P | grep #{port} | awk '{ print $2 }' | head -n 1`.strip
puts "PID: #{pid}"
`kill -9 #{pid}` unless pid.empty?
save it as something.rb and run sudo ruby something.rb
If the above solutions don't work on ubuntu/linux then you can try this
sudo fuser -k -n tcp port
Run it several times to kill processes on your port of choosing. port could be 3000 for example. You would have killed all the processes if you see no output after running the command
You can find and kill the running processes: ps aux | grep puma
Then you can kill it with kill PID
I had this issue on my Macbook Air, running Rails 5.0.3, Puma 5.2.2
Tried running
lsof -wni tcp:3000 but there's no process on this port number.
Managed to fix this by running:
export PORT=3000 on my terminal, then I just added this extra line to my .bash_profile
It might be old but in my case, it was because of docker. Hope it will help others.
I am trying to run ruby on rails under passenger with apache2 under fedora 19 and I got this error in log:
[Tue Feb 25 09:37:52.367683 2014] [passenger:error] [pid 2779] ***
Passenger could not be initialized because of this error: Unable to
start the Phusion Passenger watchdog because it encountered the
following error during startup: Cannot change the directory
'/tmp/passenger.1.0.2779/generation-1/buffered_uploads' its UID to 48
and GID to 48: Operation not permitted (errno=1)
That directory (/tmp/passenger.1.0.2779) doesn't even exist. I think that problem is with selinux. I tried to solve it about 4 hours. Httpd is running under user apache and group apache, I tried:
cat /var/log/audit/audit.log | grep passenger | audit2allow -M
passenger semodule -i passenger.pp
but still nothing.
In your case, you should switch SELinux into Permissive mode at first, then try to capture the audit log from starting Apache to run your application.1
Once you got the home page of your application, you can build your custom policy with the logs.
Switch SELinux into Permissive mode and clean audit.log
]# setenforce 0
]# rm /var/log/audit/audit.log
]# service auditd restart
Restart Apache
]# service httpd restart
Try to open your application with a web browser
It might give more information about what is happenning when you application is running.
Make a custom policy module to allow these actions
]# mkdir work
]# cd work
]# grep httpd /var/log/audit/audit.log | audit2allow -M passenger
]# ls
passenger.pp passenger.te
Load postgrey policy module using the 'semodule' command into the current SELinux policy:
]# semodule -i passenger.pp
]# setenforce 1
Restart Apache
]# service httpd restart
References:
http://wiki.centos.org/HowTos/SELinux#head-faa96b3fdd922004cdb988c1989e56191c257c01
I ran into a similar error, with a startup error about being unable to create a directory that did not exist. (logs, not tmp, but same sort of thing) I, too, battled with it for an hour and couldn't make sense of it. I created/deleted/chmod the directory many ways without success.
The fix for me was to change the parameters to passenger-start. Initially, my Docker container started passenger with:
exec bundle exec passenger start --auto --disable-security-update-check --min-instances 20 --max-pool-size 20 --max-request-queue-size 500
I removed all parameters, leaving just this:
exec bundle exec passenger start
At this point, passenger could create the log folder and file, and all was well. I could have restored the params at this point, but we decided they were not needed for the development environment so left them out moving ahead.
In hindsight, I have a hunch that I deleted the log directory while a file in it was still open, and the file system persisted that condition in some way. But that's just a hunch. Perhaps simply rebooting my Mac would have fixed it...