Issue with Rails + Passenger + Nginx - ruby-on-rails

I have cloned an instance by creating AMI and then create a new from instance from that AMI on AWS EC2.
Everything is working find excepting the Passenger server on new instance.
Here is the output of command $ sudo /usr/sbin/passenger-memory-stats
Version: 6.0.14
Date : 2022-07-27 05:27:54 +0000
------------- 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
--------------------------------------
29997 1 221.3 MB 0.6 MB nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
30000 29997 223.5 MB 0.7 MB nginx: worker process
30001 29997 223.5 MB 0.7 MB nginx: worker process
### Processes: 3
### Total private dirty RSS: 2.10 MB
----- Passenger processes ------
PID VMSize Private Name
--------------------------------
29971 390.4 MB 2.8 MB Passenger watchdog
29981 1010.9 MB 3.8 MB Passenger core
### Processes: 2
### Total private dirty RSS: 6.52 MB
Inside the Passenger processes section, Passenger Server is missing that is the problem. I am unable to start passenger app caused by It.

Related

Passenger not running (Ruby on Rails + Nginx)

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.

Why Passenger Apache in Centos 7 does not find my ruby on rails application?

I have my ruby on rails application installed in the path /var/www/sugnc
My linux user name is usersugnc, so I have a passenger configuration file with the same name in the path /etc/httpd/conf.d/usersugnc.conf
The content of that file is
<VirtualHost *:80>
RackEnv production
RailsEnv production
ServerName Nombredelservidor
DocumentRoot /var/www/sugnc/public
PassengerUser usersugnc
PassengerDisableAnonymousTelemetry on
PassengerInstanceRegistryDir /var/run/passenger-instreg
PassengerRoot /usr/share/ruby/vendor_ruby/phusion_passenger/locations.ini
PassengerRuby /usr/local/rvm/gems/ruby-2.5.1/wrappers/ruby
<Directory /var/www/sugnc/public>
Allow from all
Options -MultiViews
# si apache es >= 2.4 (sudo httpd -v)
Require all granted
</Directory>
</VirtualHost>
When I restart apache all is ok. But passenger does not find or serves my application. When I run passenger-status I get this:
Version : 6.0.7
Date : 2020-12-06 12:32:23 +0000
Instance: zFQDHZbP (Apache/2.4.6 (CentOS) Phusion_Passenger/6.0.7)
Phusion Passenger is currently not serving any applications.
And when I run sudo tail -f /var/log/httpd/error_log I get
[Sun Dec 06 12:32:16.014559 2020] [lbmethod_heartbeat:notice] [pid 23285] AH02282: No slotmem from mod_heartmonitor
[ N 2020-12-06 12:32:16.0297 23290/T1 age/Cor/CoreMain.cpp:1325 ]: Passenger core shutdown finished
[ N 2020-12-06 12:32:16.0389 23310/T1 age/Wat/WatchdogMain.cpp:1373 ]: Starting Passenger watchdog...
[ N 2020-12-06 12:32:16.0647 23317/T1 age/Cor/CoreMain.cpp:1340 ]: Starting Passenger core...
[ N 2020-12-06 12:32:16.0648 23317/T1 age/Cor/CoreMain.cpp:256 ]: Passenger core running in multi-application mode.
[ N 2020-12-06 12:32:16.0727 23317/T1 age/Cor/CoreMain.cpp:1015 ]: Passenger core online, PID 23317
[Sun Dec 06 12:32:16.078759 2020] [mpm_prefork:notice] [pid 23285] AH00163: Apache/2.4.6 (CentOS) Phusion_Passenger/6.0.7 configured -- resuming normal operations
[Sun Dec 06 12:32:16.078796 2020] [core:notice] [pid 23285] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[ N 2020-12-06 12:32:18.5868 23317/T5 age/Cor/SecurityUpdateChecker.h:519 ]: Security update check: no update found (next check in 24 hours)
And this is the output when I run passenger-memory-stats
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Version: 6.0.7
Date : 2020-12-06 12:39:57 +0000
---------- Apache processes ----------
PID PPID VMSize Private Name
--------------------------------------
23285 1 289.5 MB ? /usr/sbin/httpd -DFOREGROUND
23331 23285 291.5 MB ? /usr/sbin/httpd -DFOREGROUND
23332 23285 291.5 MB ? /usr/sbin/httpd -DFOREGROUND
23333 23285 291.5 MB ? /usr/sbin/httpd -DFOREGROUND
23334 23285 291.5 MB ? /usr/sbin/httpd -DFOREGROUND
23335 23285 291.5 MB ? /usr/sbin/httpd -DFOREGROUND
### Processes: 6
### Total private dirty RSS: 0.00 MB (?)
-------- Nginx processes --------
### Processes: 0
### Total private dirty RSS: 0.00 MB
----- Passenger processes -----
PID VMSize Private Name
-------------------------------
23310 355.1 MB ? Passenger watchdog
23317 923.6 MB ? Passenger core
### Processes: 2
### Total private dirty RSS: 0.00 MB (?)
*** WARNING: Please run this tool with rvmsudo. Otherwise the private dirty RSS (a reliable metric for real memory usage) of processes cannot be determined.
What am I missing? What needs to be done?

Phusion Passenger process stuck on (forking...) Rails

Today I updated to the newest updated package for Nginx and Passenger. After the update, my app now has a (forking...) process that wasn't there before and doesn't seem to go away. Yet it is taking up memory and sudo /usr/sbin/passenger-memory-stats reports the following.
--------- Nginx processes ----------
PID PPID VMSize Private Name
------------------------------------
1338 1 186.0 MB 0.8 MB nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
1345 1338 186.3 MB 1.1 MB nginx: worker process
### Processes: 2
### Total private dirty RSS: 1.91 MB
---- Passenger processes -----
PID VMSize Private Name
------------------------------
1312 378.8 MB 2.1 MB Passenger watchdog
1320 663.8 MB 4.2 MB Passenger core
1768 211.5 MB 29.0 MB Passenger AppPreloader: /home/ubuntu/my-app
1987 344.1 MB 52.2 MB Passenger AppPreloader: /home/ubuntu/my-app (forking...)
2008 344.2 MB 41.1 MB Passenger AppPreloader: /home/ubuntu/my-app (forking...)
### Processes: 5
### Total private dirty RSS: 128.62 MB
I have the passenger_max_pool_size 2. sudo /usr/sbin/passenger-status reports that two are currently open. The server is receiving no hits at the moment besides me using the site.
Version : 5.3.0
Date : 2018-05-14 00:41:05 +0000
Instance: ql2TTnkw (nginx/1.14.0 Phusion_Passenger/5.3.0)
----------- General information -----------
Max pool size : 2
App groups : 1
Processes : 2
Requests in top-level queue : 0
----------- Application groups -----------
/home/ubuntu/my-app (production):
App root: /home/ubuntu/my-app
Requests in queue: 0
* PID: 1987 Sessions: 0 Processed: 1 Uptime: 3m 36s
CPU: 0% Memory : 52M Last used: 3m 36s ago
* PID: 2008 Sessions: 0 Processed: 1 Uptime: 3m 35s
CPU: 0% Memory : 41M Last used: 3m 35s ago
Passenger never did this before the update and keeps the (forking...) always there now and it seems to have two apps running when it only needs one. I have searched their documents and know when it uses forking and when it doesn't and when it kills app automatically after a certain amount of time. Did they update something with the newest update that I missed in the docs? It seems that 2008 344.2 MB 89.4 MB Passenger AppPreloader: /home/ubuntu/my-app (forking...) always shows now and sometimes even has two of those when before the update I always had the process show without the (forking...).
This is normal for Passenger >= 5.3.
Source: I'm a dev at Phusion who works on Passenger.

CentOS *** ERROR: Phusion Passenger doesn't seem to be running

While i'm deploying my rails application through capistrano to my CentOS server all the time i have been receiving this error:
*** 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:
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.
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.
On my server i have apache and passenger 5.0.30
Firstly i was looking on others answers here on stack:
Link to one of these topics.
Unfortunately nothing hasn't helped me. I tried to set the env path and others settings from apache conf as well.
Any idea what should i change in order to deploy my rails app?
Where is the full path to the first passenger-status in PATH? Does it match passenger_root?
Below are my logs:
$ passenger-config validate-install
> What would you like to validate? Use <space> to select. If the menu
> doesn't display correctly, press '!'
>
> ⬢ Passenger itself ‣ ⬢ Apache
>
> -------------------------------------------------------------------------
>
> Checking whether there are multiple Apache installations... Only a
> single installation detected. This is good.
>
> -------------------------------------------------------------------------
>
> * Checking whether this Passenger install is in PATH... ✓ * Checking
> whether there are no other Passenger installations... ✓ * Checking
> whether Apache is installed... ✓ * Checking whether the Passenger
> module is correctly configured in Apache... ✓
>
> Everything looks good. :-)
$ rvmsudo passenger-memory-stats
Version: 5.0.30
Date : 2016-11-15 13:43:44 +0100
---------- Apache processes ----------
PID PPID VMSize Private Name
--------------------------------------
25188 1 476.6 MB 1.5 MB /usr/sbin/httpd -DFOREGROUND
25220 25188 270.4 MB 0.5 MB /usr/sbin/httpd -DFOREGROUND
25246 25188 478.6 MB 0.2 MB /usr/sbin/httpd -DFOREGROUND
25247 25188 478.6 MB 0.2 MB /usr/sbin/httpd -DFOREGROUND
25248 25188 478.6 MB 0.2 MB /usr/sbin/httpd -DFOREGROUND
25249 25188 478.6 MB 0.2 MB /usr/sbin/httpd -DFOREGROUND
25250 25188 478.6 MB 0.2 MB /usr/sbin/httpd -DFOREGROUND
### Processes: 7
### Total private dirty RSS: 3.08 MB
-------- Nginx processes --------
### Processes: 0
### Total private dirty RSS: 0.00 MB
----- Passenger processes -----
PID VMSize Private Name
-------------------------------
25222 421.0 MB 0.9 MB Passenger watchdog
25225 772.6 MB 1.5 MB Passenger core
25234 431.3 MB 1.0 MB Passenger ust-router
### Processes: 3
### Total private dirty RSS: 3.39 MB
My apache config file:
<VirtualHost *:80>
ServerName www.app.com
ServerAdmin admin
DocumentRoot "/srv/www/app_name/current/public"
LoadModule passenger_module /home/userr/.rvm/gems/ruby-2.2.5/gems/passenger-5.0.30/buildout/apache2/mod_passenger.so
#<IfModule mod_passenger.c>
# PassengerRuby /usr/local/rvm/gems/ruby-2.2.5
# PassengerRoot /usr/local/rvm/gems/ruby-2.2.5/gems/passenger-5.0.30
# PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.2.5/wrappers/ruby
# PassengerInstanceRegistryDir /tmp
#</IfModule>
<IfModule mod_passenger.c>
PassengerRoot /home/userr/.rvm/gems/ruby-2.2.5/gems/passenger-5.0.30
PassengerDefaultRuby /home/userr/.rvm/gems/ruby-2.2.5/wrappers/ruby
PassengerInstanceRegistryDir /tmp
</IfModule>
Options -Indexes -FollowSymLinks -MultiViews
LogLevel warn
ErrorLog logs/www.app.com-error.log
TransferLog logs/www.app.com-access.log
CustomLog logs/www.app.cp,.log combined
<Directory /srv/www/app_name/current/public>
AddDefaultCharset UTF-8
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
Require all granted
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from All
</IfModule>
</Directory>
</VirtualHost>
And my env path:
env file:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
LOGNAME=root
USER=root
USERNAME=root
HOME=/root
SUDO_COMMAND=/bin/env PASSENGER_INSTANCE_REGISTRY_DIR=/tmp
SUDO_USER=userr
SUDO_UID=1001
SUDO_GID=100
PASSENGER_INSTANCE_REGISTRY_DIR=/tmp
For sure i'm making something wrong. Thanks for every advice.
The problem seems to be systemd private temp feature, you can disable that for httpd:
mkdir /etc/systemd/system/httpd.service.d
echo "[Service]" > /etc/systemd/system/httpd.service.d/nopt.conf
echo "PrivateTmp=false" >> /etc/systemd/system/httpd.service.d/nopt.conf
systemctl daemon-reload
systemctl restart httpd
Passenger 5.0 no longer use /tmp for status information so it should work out of box even on private temps.
Finally i resolved my issue.
I have done two things.
Firstly i created new temp folder in my home directory. Then inside Apache config file i added
PassengerInstanceRegistryDir /home/userr/instancetemp
Then i pushed this to my env path with
echo 'PASSENGER_INSTANCE_REGISTRY_DIR=/home/userr/instancetemp' >> ~/.bash_profile
I think this is enough but i added also this path to my capistrano config
set :default_env, {
"PASSENGER_INSTANCE_REGISTRY_DIR" => "/home/userr/instancetemp"
}

docker apache passenger: error cannot load such file bundler/setup (LoadError)

I'm trying to build a docker-image with running apache (+passenger), rails and shibboleth.
Unfortunately I can't get apache + passenger running ...
I appreciate every hint! Maybe it is a permission problem? Everything was installed as root, but obviously some processes are running as nobody (as shown in the error log).
My docker base-image is "ruby:2.0.0" (debian 8). In this image I installed apache2, apache2-threaded-dev, libapr1-dev, libaprutil1-dev via apt-get and passenger via 'gem install passenger -v 4.0.59'. After this I used passenger-install-apache2-module to install the module.
Here is the error log:
cannot load such file -- bundler/setup (LoadError)
/usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:411:in `activate_gem'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:295:in `block in run_load_path_setup_code'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:416:in `running_bundler'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:294:in `run_load_path_setup_code'
/usr/share/passenger/helper-scripts/rack-preloader.rb:99:in `preload_app'
/usr/share/passenger/helper-scripts/rack-preloader.rb:153:in `<module:App>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'
Environment (value of RAILS_ENV, RACK_ENV, WSGI_ENV, NODE_ENV and PASSENGER_APP_ENV)
development
Ruby interpreter command
/usr/local/bin/ruby
User and groups
uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
Apache passenger.load:
LoadModule passenger_module /usr/local/bundle/gems/passenger-4.0.59/buildout/apache2/mod_passenger.so
Apache passenger.conf:
IfModule mod_passenger.c>
PassengerRoot /usr/local/bundle/gems/passenger-4.0.59
PassengerDefaultRuby /usr/local/bin/ruby
</IfModule>
And myapp.conf:
<VirtualHost *:80>
#ServerName yourserver.com
# Tell Apache and Passenger where your app's 'public' directory is
DocumentRoot /var/www/myapp/public
PassengerRuby /usr/local/bin/ruby
RailsEnv development
# Relax Apache security settings
<Directory /var/www/myapp/public>
Allow from all
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
Require all granted
</Directory>
Installed versions:
apache2 -v
Server version: Apache/2.4.10 (Debian)
ruby -v
ruby 2.0.0p645 (2015-04-13 revision 50299)
gem -v
2.0.14
rails -v
Rails 4.0.5
passenger-config validate-install says "Everything looks good". And 'passenger-status':
Version : 4.0.59
Date : 2015-10-13 09:03:32 +0000
Instance: 5578
----------- General information -----------
Max pool size : 6
Processes : 0
Requests in top-level queue : 0
----------- Application groups -----------
/var/www/myapp#default:
App root: /var/www/myapp
Requests in queue: 0
passenger-memory-stats:
Version: 4.0.59
Date : 2015-10-13 09:05:31 +0000
--------- Apache processes ---------
PID PPID VMSize Private Name
------------------------------------
5578 1 83.2 MB ? /usr/sbin/apache2 -k start
5599 5578 363.5 MB ? /usr/sbin/apache2 -k start
5600 5578 491.5 MB ? /usr/sbin/apache2 -k start
### Processes: 3
### Total private dirty RSS: 0.00 MB (?)
-------- Nginx processes --------
### Processes: 0
### Total private dirty RSS: 0.00 MB
---- Passenger processes -----
PID VMSize Private Name
------------------------------
5581 218.3 MB ? PassengerWatchdog
5584 564.5 MB ? PassengerHelperAgent
5590 217.8 MB ? PassengerLoggingAgent
### Processes: 3
### Total private dirty RSS: 0.00 MB (?)
All running processes:
ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 20300 1780 ? Ss 08:47 0:00 bash
root 6077 0.0 0.0 85160 3208 ? Ss 09:11 0:00 /usr/sbin/apache2 -k start
root 6080 0.0 0.0 223500 2044 ? Ssl 09:11 0:00 PassengerWatchdog
root 6083 0.0 0.0 578092 5556 ? Sl 09:11 0:00 PassengerHelperAgent
nobody 6089 0.0 0.0 223028 5008 ? Sl 09:11 0:00 PassengerLoggingAgent
www-data 6098 0.0 0.0 437788 5452 ? Sl 09:11 0:00 /usr/sbin/apache2 -k start
www-data 6099 0.0 0.0 437780 5300 ? Sl 09:11 0:00 /usr/sbin/apache2 -k start
EDIT
After 2 days searching and trying I found a solution (right after I post here my question ...):
I have to put this into my apache virtual host configuration of my app:
SetEnv GEM_HOME /usr/local/bundle
This solution was postet on https://stackoverflow.com/a/19099768/4846489
I don't know why this is necessary, because I don't have a previous installation (as stated there). This is really strange, because this environment variable is already there if I login into my docker container (docker exec -u nobody)...
Setting GEM_HOME just patches over the real problem. This information here is your hint:
User and groups:
id=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
Passenger is trying to run your app as the user 'nobody'. Most likely, this is not what you meant it to do. Your gem bundle is probably installed by a different user, and the 'nobody' user probably does not have access to that installed gem bundle.
Why is Passenger running your app as 'nobody'? Because of user sandboxing rules, most likely caused by wrong permissions on your app. You should fix that.
By the way, why are you building your own Docker image? Phusion provides its own passenger-docker base image.

Resources