Rails production with puma and nginx puma.sock missing - ruby-on-rails

I'm setting up my rails production server on digital ocean with puma and nginx.
Following tutotials I have entered this in my /etc/nginx/sites-available/default
server unix:/home/deploy/appname/shared/sockets/puma.sock fail_timeout=0;
But on the server the folder home/deploy/appname/shared/sockets/ is empty.
I double checked the tutorials and none of them mentions creating such file.
If I run ps aux | grep pumaI get
root 2076 0.0 0.3 52992 3544 pts/0 T 05:51 0:00 sudo
nano require capistrano/puma root 2077 0.0 0.3 23872 3888
pts/0 T 05:51 0:00 nano require capistrano/puma rails 2407
0.0 0.0 14484 1012 pts/0 S+ 06:38 0:00 grep puma
which it doesn't really makes sense to me as I'm not using capistrano.
My question is. How is puma.sock created? During puma installation? What step have I missed if that directory is empty?

Without capistrano you need to start puma with -b option to create sock file:
puma -b unix:///__abs_path_to_your_app__/puma.sock
and in /etc/nginx/sites-available/default you need to change path to .sock file:
server unix:///__abs_path_to_your_app__/puma.sock fail_timeout=0;

Related

setup ROR application using puma nginx and capistrano

I'm trying to deploy ruby on rails application to the Amazon EC2 instance, using puma as an application server, nginx server and capistrano for deployments. Currently I'm stuck with the error message:
nginx logs are not showing any error,
puma logs are also not showing what's the error
I have verified that puma server is started and running, using the following command:
ubuntu#ip-nnnnn:~$ ps aux | grep puma
deployer 89555 0.0 1.5 652040 248180 ? Sl 21:48 0:00 puma 3.12.1 (unix://nnnn/nnn/current/tmp/sockets/puma.sock) [20211130214658]
deployer 89561 0.0 1.5 854804 259336 ? Sl 21:48 0:00 puma: cluster worker 0: 89555 [20211130214658]
deployer 89566 0.0 1.5 787216 247824 ? Sl 21:48 0:00 puma: cluster worker 1: 89555 [20211130214658]
ubuntu 89845 0.0 0.0 8168 740 pts/0 S+ 22:23 0:00 grep --color=auto puma
capistrano deploys without any error, all tasks are completed fine, the puma server is restarted fine during the capistrano deployment.
application log has no recent data, it looks like it doesn't reach to that point, it breaks before that.
In my particular case it was due to the stopped REDIS service. The application was configured to utilize REDIS for caching, however REDIS service wasn't running. This wasn't reflected in the logs for some reason and I spent a good amount of time figuring out what was wrong.

docker on upstart on scaleway

I have docker container based on ubuntu 12.04 and wish start it on scaleway This instantApp run on ubuntu 15.04 with systemd. For my container I need upstart. I turn on upstart by this recommendation:
Install the upstart-sysv package, which will remove ubuntu-standard and systemd-sysv (but should not remove anything else -- if it does, yell!), and run sudo update-initramfs -u. After that, grub's "Advanced options" menu will have a corresponding "Ubuntu, with Linux ... (systemd)" entry where you can do an one-time boot with systemd.
Now my server running with upstart:
# ps aux|grep upstart
root 1447 0.0 0.0 2632 1744 ? S 13:44 0:00 upstart-udev-bridge --daemon
root 1598 0.0 0.0 2044 176 ? S 13:44 0:00 upstart-file-bridge --daemon
root 2571 0.0 0.0 2032 1128 ? S 13:44 0:00 upstart-socket-bridge --daemon
root 32408 0.0 0.0 3156 1472 pts/4 S+ 14:27 0:00 grep --color=auto upstart
but docker not running:
# service docker status
* Docker is managed via upstart, try using service docker status
# service docker start
* Docker is managed via upstart, try using service docker start
How I can start docker as daemon?
See answer for this Ask Ubuntu question - it's a workaround to get things running again until the Kernel bug is address: https://askubuntu.com/questions/683462/docker-is-managed-via-upstart-try-using-service-docker

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.

Deployed Rails missing secret key

I'm trying to deploy my Rails app to my Digital Ocean VPS. I've done all the steps in the GoRails guide but when I deploy my project and visit my ip adres I'm greeted by a message:
An error occurred.
Sorry, the page you are looking for is currently unavailable.
Please try again later.
If you are the system administrator of this resource then you should check the error log for details.
Faithfully yours, nginx.
I've checked the nginx error log which shows me:
Exception RuntimeError in Rack application object (Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`) (process 2490, thread 0x007fbd33665ce0(Worker 1)):
On the VPS I've created a secret by running rake secret and then running export SECRET_KEY_BASE= + key. Now when I echo $SECRET_KEY_BASE it shows me my key. But still I'm getting the error message.
In my deploy.rb I have this:
set :linked_files, %w{config/database.yml config/secrets.yml}
And my secrets.yml on the VPS is this:
development:
secret_key_base: 89dacb16fd905ff4c6352ac93f4676a5dd&^%3f93edce9a5be796712d54b57b91e1335598fd73e3998fddbbdeaf3ee7f65157f2fb01ce1bea5658aa7bf745d1f
test:
secret_key_base: cf351585b2cb43459f5a073cbfd885b3dd2af44124f13a855522f678c1cf06625c121cd3b7857&&6e7fe2ba11180066753142143231c79c513e71e20372a0462
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
I just restarted nginx, but still no result.
Update
deploy#movieseat:~$ ps aux | grep nginx
root 4545 0.0 0.6 98936 3360 ? Ss 11:32 0:00 nginx: master process /usr/sbin/nginx
www-data 4548 0.0 0.9 99304 4608 ? S 11:32 0:00 nginx: worker process
www-data 4549 0.0 0.9 99304 4608 ? S 11:32 0:00 nginx: worker process
www-data 4550 0.0 0.9 99304 4608 ? S 11:32 0:00 nginx: worker process
www-data 4551 0.0 0.9 99304 4608 ? S 11:32 0:00 nginx: worker process
deploy 4655 0.0 0.3 9436 1660 pts/1 S+ 11:33 0:00 grep --color=auto nginx
I would assume that you hadn't checked in the secrets.yml file in the repository as you have defined it as a linked file in deploy.rb i.e
set :linked_files, %w{config/database.yml config/secrets.yml}
You can do the same for the secrets.yml like database.yml. My recommendation is to put the value of secret_key_base itself in the secret.yml file instead of reading it from the ENV as the person who have access to linked file in the deploy server would have access to ENV vars anyway.
But, if you have added the secrets.yml file in the repository, it makes sense to try to read the value from the system environments.

passenger + nginx fails when I disconnect from terminal

I use Ubuntu 12.04 LTS, rvm, passenger and nginx installed by passenger.
I connect to my server with Putty, start nginx via init.d/nginx and my Rails application works well.
But when I disconnect from terminal, I see standard application errors (Something went wrong, etc.).
nginx error log output:
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- rubygems (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:gem_prelude>:167:in `load_full_rubygems_library'
from <internal:gem_prelude>:217:in `try_activate'
from <internal:lib/rubygems/custom_require>:32:in `rescue in require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /var/lib/passenger-standalone/3.0.18-x86_64-ruby1.9.3-linux-gcc4.6.3-1002/support/helper-scripts/passenger-spawn-server:75:in `<main>'
*** Passenger ERROR (ext/common/ApplicationPool/../SpawnManager.h:220):
Could not start the spawn server: /home/torteg/.rvm/wrappers/ruby-1.9.2-p320/ruby: No such file or directory (2)
*** Passenger ERROR (ext/common/ApplicationPool/../SpawnManager.h:220):
Could not start the spawn server: /home/torteg/.rvm/wrappers/ruby-1.9.2-p320/ruby: No such file or directory (2)
ps aux output:
root 5066 0.0 0.0 220928 1936 ? Ssl 15:46 0:00 PassengerWatchdog
root 5069 0.0 0.0 1872956 2340 ? Sl 15:46 0:00 PassengerHelperAgent
root 5071 0.5 0.2 114348 10172 ? Sl 15:46 0:00 Passenger spawn server
nobody 5074 0.0 0.1 169324 4688 ? Sl 15:46 0:00 PassengerLoggingAgent
root 5105 0.0 0.0 39472 1028 ? Ss 15:46 0:00 nginx: master process /opt/nginx/sbin/nginx
torteg 5106 0.0 0.0 39892 2276 ? S 15:46 0:00 nginx: worker process
torteg 5116 13.2 1.5 225720 62432 ? Sl 15:46 0:03 Passenger ApplicationSpawner: /webapps/ngt-storage
torteg 5132 2.4 1.5 230940 64520 ? Sl 15:46 0:00 Rack: /webapps/ngt-storage
root 5141 0.1 0.1 160656 7272 ? Ss 15:47 0:00 sshd: torteg [priv]
torteg 5145 0.0 0.0 164168 1820 ? S 15:47 0:00 sshd: torteg [priv]
torteg 5291 0.0 0.0 160656 2656 ? S 15:47 0:00 sshd: torteg#pts/3
So when you ssh into your production server, somewhere else in the world (or in the cloud) and you visit mydomain.com it works. As soon as you log out of that ssh connection, nginx and passenger stop working? How are these two independent events tied to each other?
What service are you using to host this app?
Possible answer (will clean this up when you get answers to us)
I see you are using rvm too... unless the rvm path isn't set in your deploy user (just thinking out loud)
Created new user deploy with default bash shell. Installed rvm for this user. Then I set user and passenger_user to deploy in nginx.conf. Cleaned precompiled assets.. Works well!

Resources