Passenger standalone can't start server after enabling SSL on Rails project - ruby-on-rails

I have a Rails project up on an EC2 server at AWS. To deploy it, I followed this Passenger tutorial to the letter:
https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/ownserver/standalone/oss/deploy_app_main.html
Everything worked fine. Then I followed this Passenger tutorial to get SSL working:
https://www.phusionpassenger.com/library/deploy/standalone/prod_ssl.html
My Passengerfile and nginx conf file look the same as the ones in the link (with the paths replaced to point to the correct files). But now, best I can gather, the nginx server isn't starting when I use the command sudo bundle exec passenger start.
I found this on the nginx log:
May 29 18:46:20 ip-172-31-38-233 systemd[18230]: nginx.service: Failed to execute command: No such file or directory
May 29 18:46:20 ip-172-31-38-233 systemd[18230]: nginx.service: Failed at step EXEC spawning /usr/sbin/nginx: No such file or directory
Which doesn't make sense to me as nginx was working fine before the SSL certificates. Note I'm using Passenger standalone, so I'm not managing nginx myself.

Related

Deploying a Rails Application with Puma and Nginx [without sudo]

All the how-to, tutorial and manuals I can find on nginx and Puma assume the user following them has sudo access on the server.
Is it possible to deploy an application with nginx and puma in an environment in which you do not have sudo?
Presume for the purposes of this question that working tightly with someone who does have sudo to run all the necessary commands when you request them is not an option.
You can build from source without installing it. As long as you aren't trying to use ports under 1024, you should be able to download and compile nginx yourself. I know puma can be installed as a gem, so it wouldn't need to be sudoed in there. I think the syntax once you download the tarball is:
./configure --sbin-path=~/nginx/sbin/nginx --conf-path=~/nginx/etc/nginx.conf --pid-path=~/nginx/pid/nginx.pid
make
Building Nginx from Source
Unless you do some modification to users and groups (which will require sudo) it would be very hard if not impossible to do this.
Assuming Ubuntu and init.d you need sudo to start/stop/reset the services and modify the nginx conf files.
Here is a great resource for automated deployment and easily customize-able. RailsBox.io

Dokku domains:add <app> <domain> returns unsupported vhost config found. disabling vhost support

This is my first site I've were I've tried to use Dokku to deploy a rails app on Digital Ocean.
This is a default Dokku install on a basic Ubuntu VM hosted on Digital Ocean
When I try to run:
dokku domains:add myapp mydomain.com
I get the following error
=====> unsupported vhost config found. disabling vhost support
=====> config:set-norestart is deprecated as of v0.3.22
-----> Setting config vars
NO_VHOST: 1
-----> VHOST support disabled, deleting four-heroes/VHOST
-----> Added mydomain.com to myapp
The last line looks like it may have worked despite the errors. However, when I run:
dokku domains myapp
I get this message.
=====> unsupported vhost config found. disabling vhost support
=====> config:set-norestart is deprecated as of v0.3.22
-----> Setting config vars
NO_VHOST: 1
=====> myapp Domain Names
cat: /home/dokku/myapp/VHOST: No such file or directory
Aside from the Postgresql plugin this is a default Dokku install. The application works well and Im able to access it at the the ip.ad.dr.ess:port combination, and I'm able to SSH to the domain(ssh root#mydomain.com).
I can't figure out where I messed up here.
Any help is appriciated.
If you didn't fill in the HOSTNAME option on initial setup of dokku you'll run into your current problem. The VHOST file has yet to be created causing the current error.
To remedy this we have to create the missing VHOST file and populate with your domain name. First SSH into your droplet and run the following (Depending on your permissions you may require sudo to create and edit the VHOST file)
cd /home/dokku
touch VHOST
chmod 0755 VHOST
# Use your editor of choice nano, vim etc.
# to add your hostname to VHOST file, eg. mydomain.com
Now for each app we're going to need to trigger a rebuild of the nginx.conf file. To do this run dokku nginx:build-config myapp for each app.
Note: Deleting the app's dir from /home/dokku/myapp and redeploying will also have the same effect but will require you to re-link other containers e.g. db plugins.
If everything has gone smoothly running dokku domains myapp should now ouput in your terminal
=====> myapp Domain Names
myapp.mydomain.com
You now should be able to remove and add domains for your app successfully using the dokku domains commands
See this answer also for reference

Phusion passenger-status: what value for passenger_instance_registry_dir?

I've done a new install of nginx 1.6.3 and passenger 5.0.15 on Ubuntu 14.04 from source in order to add tracing components from AppNeta for my ROR 4.2 app on one of my servers. Nginx and passenger are running and serving pages. I am getting the trace data for server monitoring. All seems well,
However, when I run "passenger-status" (as root), I get the following:
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:
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 passenger-status 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.
The problem with this is that it seems to be blocking capistrano deploys; this same error is displayed by cap before exiting.
Passenger is running (it's in the ps output and pages are being served). I just need to tell passenger-status where to find the current running instance. (This is from the Design and Architecture documentation.) Therefore, it seems that setting this instance registry directory value is the required step. But to what value?
According to the Nginx Reference, the defaults are /tmp and /var/run/passenger-instreg And I've found an instance directory in /tmp. So, I've tried setting the PASSENGER_INSTANCE_REGISTRY_DIR to a number of different values:
/tmp
/tmp/passenger.JxmCeiA (the current instance directory, but this changes with each startup of Nginx)
I've even tried creating a directory at /run/passenger, setting that value in the nginx configuration file and restarting nginx. The temporary directory is being created, but passenger-status still gives the same message. Even if I use the /opt/passenger-5.0.15/bin/passenger-status script to make sure I'm using the latest version of that script.
There are some configuration values in the original 'location.ini' directory for passenger, but none were the instance registry directory, so there was nothing to reuse.
Interestingly, the /opt/passenger-5.0.15/lib/phusion_passenger/nginx/config_options.rb file does not have an entry for passenger_instance_registory_dir. It has other nginx configuration options, I would have expected it to have this one as well.
I've tried setting the environment variable as well as the Nginx passenger_instance_registry_dir option, but I must be missing something in my understanding because I can't seem to connect the passenger-status command with the current running instance.
Any help would be greatly appreciated.
Passenger author here.
/tmp/passenger.JxmCeiA is an example of an instance directory. This changes indeed with every startup (because it is specific to an instance).
The parent directory (the directory in which instance directories are located) is the instance registry directory. So in your case, the instance registry directory that is being used is /tmp.
I'm guessing that you have some kind of Passenger installation version mismatch. We've changed the structure of the instance directory a few times in the past, and every time we did this we bump an internal version number to indicate that it's incompatible with previous Passenger versions. Can you double check the following?
Does Passenger appear to be otherwise running correctly?
What Passenger version is compiled inside Nginx?
What is your passenger_root set to? Does it match the Passenger version compiled inside Nginx?
Where is the full path to the first passenger-status in PATH? Does it match passenger_root?
You also seem to be mixing the Phusion Passenger APT repository with source tarball install. Having multiple installations around is generally a bad idea. Try cleaning up your other installs so that you only end up with one.
Also check whether you are setting the PASSENGER_INSTANCE_REGISTRY_DIR environment variable correctly. Note that sudo nukes environment variables, so you need to run passenger-status like this:
# Correct:
sudo env PASSENGER_INSTANCE_REGISTRY_DIR=/tmp passenger-status
# Incorrect, sudo nukes environment variables
export PASSENGER_INSTANCE_REGISTRY_DIR=/tmp
sudo passenger-status
Regarding lib/phusion_passenger/nginx/config_options.rb: that file mainly lists per-server and per-location config options. Many config options in the main context are either not yet ported to the config_options.rb system, or not possible because they require custom attention. At present, passenger_instance_registry_dir is implemented in ext/common/nginx/Configuration.c. As we continue to cleanup and refactor the codebase, this option may eventually be moved to config_options.rb.
In case anyone else is having this problem when starting Passenger using a systemd service, this might be due to systemd's private /tmp. The problem was solved by adding PrivateTmp=false to the service file.
Source
step one check phusion passenger is installed correctly
sudo passenger-config validate-install
"if you see an ouput saying, 'Everything is looks good :-)'" then you are fine, if not you need to reinstall phusion passenger, refer to https://www.phusionpassenger.com/library/walkthroughs/start/
step two check the phusion passenger memory status
sudo passenger-memory-stats
"if you see processes running, then that's good, if not you either have to start some passenger app, or install nginx or apache with extra library for them. For nginx you need nginx and the nginx-extras".
step three uncomment the passenger_root in the nginx.conf file (for ubuntu it's usually /etc/nginx/nginx.conf) or the apache.conf file
restart nginx or apache
sudo service nginx restart # (or systemctl restart nginx, for new version of linux such as ubuntu 15.04, CentOS7)
now you can run
passenger-status
the error should go away now. The mostly likely output you will get is saying "Phusion Passenger is currently not serving any applications."
I'm running Passenger in Nginx integration mode, on Ubuntu 20.04 and I've installed it via apt from the official repos.
What worked for me was adding this to /etc/nginx/conf.d/mod-http-passenger.conf :
passenger_instance_registry_dir /tmp;
Restarting passenger the Capistrano way from the command line should now work:
$ passenger-config restart-app <your_app's_root_path> --ignore-app-not-running
If this works, Capistrano deployments should now work again.

Capistrano foreman cannot export upstart scripts because it's trying to run commands as root

I'm using capistrano3-foreman gem to deploy my app into production which is in a centOS server but capistrano is trying to run foreman export command from root. Since I have installed rvm and other stuff from a user which has no password privilege in sudoers file, foreman export cannot be completed.
I'm getting the following error.
sh: /root/.rvm/bin/rvm: No such file or directory
How can I prevent capistrano-foreman from trying to run the command as root and make it set to my user home path.
Thanks in advance
Ok, since RHEL & CentOS 7 migrated to systemd, first mistake was trying to export foreman to upstart.
But When I exported foreman to systemd, systemd did not recognised foreman export scripts as a service so it didn't work either.
After many hours of work & research I decided to take my chance with supervisord on CentOS 7 and now It works like a charm.
http://supervisord.org/installing.html
And please note that Debian & Ubuntu are also getting rid of upstart...

Can't Get Mongrel_Service Gem to Start Mongrel as a Windows Service

I’m more or less a newb to Ruby on Rails, but I’ve been tasked with debuging a Rails app that guy that’s no longer around wrote. The app is running on a manchine using:
• Windows XP Professional
• Apache 2.2
• Rails 2.3.8
• mongrel (1.1.5 x86-mingw32)
• mongrel_service (0.3.4 i386-mswin32)
I copied the app from the server and did some debugging on it on my personal machine. I just setup a Git repository on my personal machine and cloned it back over to the server. Everything seems to be working great except mongrel_service doesn’t work anymore. Each time I try to start the service from Windows “Services” tool I get this error:
The MYAPP_Mongrel_As_Service service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service
I tried removing the service with:
C:\MyApp>mongrel_rails service::remove --name MYAPP_Mongrel_As_Service
Stopping MYAPP_Mongrel_As_Service if running...
MYAPP_Mongrel_As_Service service removed
and reinstalling it with:
C:\MyApp>mongrel_rails service::install --name MYAPP_Mongrel_As_Service -c "C:\MyApp" --port 3001 --env
ironment production --address localhost --log "log\mongrel_as_service.log" --pid "tmp\pids\mongrel_a
s_service.pid"
MYAPP_Mongrel_As_Service service created.
But no matter how many times I try, or what options I use, I can’t get the service to run. What’s weird is that I can get mongrel to startup by itself just fine.
C:\MyApp>mongrel_rails start -c c:\MyApp --port 3001 --environment production --address localhost --
g "c:\MyApp\log\mongrel_as_service.log" --pid "C:\MyApp\tmp\pids\mongrel_as_service.pid"
** Starting Mongrel listening at localhost:3001
** Starting Rails with production environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. INT => stop (no restart).
** Mongrel 1.1.5 available at localhost:3001
** Use CTRL-C to stop.
It just won’t work when I try to start it as a service. I've done a lot of googling on the subject, but I can't find anything to fix the problem. It's odd that it was working before but now it doesn't. There must be something wrong with my service::install line because I can't get the original unedited Rails app to work with mongrel_as_service either.
I figured it out. It turns out that the log file for mongrel_service didn't exist on my file. To fix the problem, I just made a blank text file and renamed it to the name of my log file. It worked like a charm. It's odd that mongrel_service doesn't make it's own log file if it can't detected it, but oh well.

Resources