What user is running my Rails app? - ruby-on-rails

I'm trying to get a bare bones Rails app deployed under Apache, Passenger 3.0.0 and Rails 3.0.3. I'm getting all kinds of weird errors. mostly revolving around what I think is related to bundler or RAILS_ENV.
Only non-default thing about the app is that development & test environments use SQLite3 and production uses MySQL.
When hitting app from web browser Passenger is throwing errors regarding gems (sqlite3) that are specifically (in the Gemfile AND in the database.yml) declared as NOT part of the production environment.
How can I tell what user the server is trying to run my Rails app as? I would like to make sure the RAILS_ENV is set correctly for that user as I think Passenger is trying to run this app in development mode for some reason.
Edit: added results of ps aux | grep httpd
myserver:current elvis$ ps aux | grep httpd
elvis 4424 0.4 0.0 66152 192 s000 S+ 11:03AM 0:00.00 grep httpd
_www 1950 0.0 0.2 93024 2544 ?? S 11:40PM 0:01.23 /usr/sbin/httpd -D FOREGROUND
root 1918 0.0 1.0 93024 10244 ?? Ss 11:39PM 0:02.75 /usr/sbin/httpd -D FOREGROUND
_www 4084 0.0 0.2 93024 2536 ?? S 9:41AM 0:00.15 /usr/sbin/httpd -D FOREGROUND
and ls -l ...
myserver:current elvis$ ls -l config
total 48
-rw-rw-r-- 1 aaron admin 1923 Nov 19 21:40 application.rb
-rw-rw-r-- 1 aaron admin 326 Nov 19 21:40 boot.rb
-rw-rw-r-- 1 aaron admin 741 Nov 19 21:40 database.yml
-rw-rw-r-- 1 aaron admin 1257 Nov 19 21:40 deploy.rb
-rw-rw-r-- 1 aaron admin 149 Nov 19 21:40 environment.rb
drwxrwxr-x 5 aaron admin 170 Nov 19 21:40 environments
drwxrwxr-x 7 aaron admin 238 Nov 19 21:40 initializers
drwxrwxr-x 3 aaron admin 102 Nov 19 21:40 locales
-rw-rw-r-- 1 aaron admin 1808 Nov 19 21:40 routes.rb

By default, passenger will run your app as the user who owns the config/environment.rb or config.ru file, see http://www.modrails.com/documentation/Users%20guide%20Apache.html#user_switching
Passenger will run in the production environment by default unless you tell it otherwise with the RailsEnv, see http://www.modrails.com/documentation/Users%20guide%20Apache.html#rails_env

You could run ps aux | grep httpd to see what user is running your apache process.

That's what I use to detect what user should run the rails app
RAILS_USER=$(stat -c '%U' /YOUR_PATH/environment.rb)
echo "Detected rails user: $RAILS_USER"

Related

Why Docker mounts only specific files in volume?

$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.13.6
BuildVersion: 17G65
$ docker -v
Docker version 18.06.0-ce, build 0ffa825
I have some docker-compose file that actually has this string of line:
volumes:
- .:/sql
And In "." directory I have plenty of directories and files:
$ ls -l
total 32
-rw-r--r-- 1 michael staff 161 Nov 9 13:35 README.ms
drwxr-xr-x 12 michael staff 384 Nov 9 13:35 backend
-rwxr-xr-x 1 michael staff 1438 Nov 9 13:35 manage.py
drwxr-xr-x 12 michael staff 384 Nov 10 13:28 ops
drwxr-xr-x 5 michael staff 160 Nov 9 13:35 requirements
-rw-r--r-- 1 michael staff 38 Nov 9 13:35 requirements.txt
But when I start this container and go inside, all I see there:
# ls -1 /sql
docker-compose.yml
ops
Pay attention: file docker-compose.yml is even not from this directory. It is from ops/
Who has an idea of the cause?
Figured out the reason.
No matter where you start docker-compose from, it takes "." as a location of docker-compose.yml file. Thus, all you expect to see inside container have to be located within the very same directory where docker-compose.yml resides at.

DSE upgrade deleted datastax-agent conf folder

I'm running a 3-node cluster in AWS. Yesterday, I upgraded my cluster from DSE 4.7.3 to 4.8.0.
After the upgrade, the datastax-agent service is no longer registered and the /usr/share/datastax-agent/conf folder has been removed.
PRE-UPGRADE:
$ ls -alr
total 24836
drwxrwxr-x 3 cassandra cassandra 4096 Aug 10 14:57 tmp
drwxrwxr-x 2 cassandra cassandra 4096 Aug 10 14:56 ssl
drwxrwxr-x 2 cassandra cassandra 4096 Sep 28 15:14 doc
-rw-r--r-- 1 cassandra cassandra 25402305 Jul 14 18:55 datastax-agent-5.2.0-standalone.jar
drwxrwxr-x 2 cassandra cassandra 4096 Sep 28 18:23 conf
drwxrwxr-x 3 cassandra cassandra 4096 Sep 28 18:13 bin
drwxr-xr-x 118 root root 4096 Oct 2 18:02 ..
drwxrwxr-x 7 cassandra cassandra 4096 Oct 7 19:03 .
POST-UPGRADE:
$ ls -al
total 24976
drwxr-xr-x 3 cassandra cassandra 4096 Oct 5 20:45 .
drwxr-xr-x 114 root root 4096 Oct 5 18:23 ..
drwxr-xr-x 3 cassandra cassandra 4096 Oct 5 20:45 bin
-rw-r--r-- 1 cassandra cassandra 25562841 Sep 10 20:43 datastax-agent-5.2.1-standalone.jar
Also, /etc/init.d/datastax-agent file has been deleted. I don't know how I'm supposed to start/stop the service now.
Can I restore the files from the rollback directory? What effect will that have?
In this particular case what happened was that the dpkg install found a preexisting /etc/init.d/datastax-agent file and only put /etc/init.d/datastax-agent.fpk.bak into place. A "sudo dpkg -P datastax-agent" followed by a "sudo dpkg -i /usr/share/dse/datastax-agent/datastax-agent_5.2.1_all.deb" fixed the issue. We had to first kill the already running agent processes and then do a service restart.
Will investigate how that could have happened... that's still a little bit of a mystery to me.

PostgreSQL wrong ownership

I'll preface this with the fact that I haven't used PostgreSQL much. I tried using it with RoR but the fact that it uses an ORM, I never got why PostgreSQL was the flavor of choice.
After fighting with getting the damn thing installed on Ubuntu 14.04, I need to clone a repo that depends on it.
After about 30 minutes of dealing trying a few things, I discovered:
$ /usr/lib/postgresql/9.4/bin/postgres -d 3 -D /var/lib/postgresql/9.4/main -c config_file=/etc/postgresql/9.4/main/postgresql.conf
LOG: skipping missing configuration file "/var/lib/postgresql/9.4/main/postgresql.auto.conf"
2015-02-14 21:05:01 PST [7665-2] FATAL: data directory "/var/lib/postgresql/9.4/main" has wrong ownership
2015-02-14 21:05:01 PST [7665-3] HINT: The server must be started by the user that owns the data directory.
2015-02-14 21:05:01 PST [7665-4] DEBUG: shmem_exit(1): 0 before_shmem_exit callbacks to make
2015-02-14 21:05:01 PST [7665-5] DEBUG: shmem_exit(1): 0 on_shmem_exit callbacks to make
2015-02-14 21:05:01 PST [7665-6] DEBUG: proc_exit(1): 0 callbacks to make
2015-02-14 21:05:01 PST [7665-7] DEBUG: exit(1)
One, I don't know what this auto.conf file it's looking for as I'm specifying the conf file.
However... (edited to what I think are the appropriate line[s])
$ sudo gedit /etc/postgresql/9.4/main/pg_hba.conf
local all postgres 127.0.0.1 peer
(I added in the local IP after nothing working. Still doesn't work.)
And (/etc/postgresql/9.4/main/)
-rw-r--r-- 1 postgres postgres 315 Feb 14 20:20 environment
-rw-r--r-- 1 postgres postgres 143 Feb 14 20:20 pg_ctl.conf
-rw-r----- 1 postgres postgres 4641 Feb 14 20:55 pg_hba.conf
-rw-r----- 1 postgres postgres 4641 Feb 14 20:20 pg_hba.conf~
-rw-r----- 1 postgres postgres 1636 Feb 14 20:20 pg_ident.conf
-rw-r--r-- 1 postgres postgres 21461 Feb 14 20:20 postgresql.conf
-rw-r--r-- 1 postgres postgres 378 Feb 14 20:20 start.conf
Seems to me the configuration files are owned by postgres. What gives?
Update (9:30p)
Running the following command (as postgres) gives the same result.
$ su - postgres; /usr/lib/postgresql/9.4/bin/postgres -d 3 -D /var/lib/postgresql/9.4/main -c config_file=/etc/postgresql/9.4/main/postgresql.conf
Judging from the error message, ownership for the data directory seems to be misconfigured. If so, fix with (as privileged system user):
chown postgres:postgres /var/lib/postgresql/9.4
chown postgres:postgres /var/lib/postgresql/9.4/main
Use the "recursive" option -R if anything inside those directories is owned by different users.

Unable to start passenger watchdog but passenger installed

I want to setup nginx with passenger support on ubuntu 12.04 VM (vagrant box). Therefore I created the following chef cookbook recipe (https://github.com/i42n/wrapper-nginx-passenger/blob/master/recipes/default.rb):
#
# Cookbook Name:: wrapper-nginx-passenger
# Recipe:: default
#
# Copyright 2014, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
apt_repository 'nginx-passenger' do
uri 'https://oss-binaries.phusionpassenger.com/apt/passenger'
distribution node['lsb']['codename']
components ['main']
keyserver 'keyserver.ubuntu.com'
key '561F9B9CAC40B2F7'
end
# install nginx which contains passenger support
package "nginx-extras"
package "passenger"
# define nginx service as the nginx::passenger recipe restarts the service
# and fails if the service does not exist
service 'nginx' do
supports :status => true, :restart => true, :reload => true
action :start
end
# installs the passenger gem
include_recipe "nginx::passenger"
# create server config template in nginx config directory
template "/etc/nginx/sites-available/plantasy" do
source "plantasy.erb"
mode 0644
owner "root"
group "root"
end
# symlink the config to the active sites directory
link "/etc/nginx/sites-enabled/plantasy" do
to "/etc/nginx/sites-available/plantasy"
end
It follows the passenger installation guide from here: https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#install_add_apt_repo
However if I try to start nginx I get the following error:
vagrant#vagrant:/etc/nginx/conf.d$ sudo service nginx restart
* Restarting nginx nginx
nginx: [alert] Unable to start the Phusion Passenger watchdog because its executable (/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45/buildout/agents/PassengerWatchdog) does not exist. This probably means that your Phusion Passenger installation is broken or incomplete, or that your 'passenger_root' directive is set to the wrong value. Please reinstall Phusion Passenger or fix your 'passenger_root' directive, whichever is applicable. (-1: Unknown error)
...done.
This actually seems a common error if nginx has not been compiled correctly with passenger support. However if I check the nginx modules my nginx does have passenger support:
vagrant#vagrant:~$ nginx -V
nginx version: nginx/1.6.0
TLS SNI support enabled
configure arguments: --with-cc-opt= --with-ld-opt= --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_flv_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_spdy_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-mail --with-mail_ssl_module --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/headers-more-nginx-module --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-auth-pam --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-cache-purge --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-dav-ext-module --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-development-kit --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-echo --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/ngx-fancyindex --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-http-push --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-lua --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-upload-progress --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/nginx-upstream-fair --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/ngx_http_substitutions_filter_module --add-module=/tmp/buildd/nginx-1.6.0/debian/modules/passenger/ext/nginx
The error is actually correct. The file/folder passenger is looking for on nginx startup is not present:
vagrant#vagrant:/etc/nginx/conf.d$ ls -l /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45
total 196
-rw-r--r-- 1 vagrant root 80232 Jul 7 13:38 CHANGELOG
-rw-r--r-- 1 vagrant root 15919 Jul 7 13:38 CONTRIBUTING.md
-rw-r--r-- 1 vagrant root 1035 Jul 7 13:38 CONTRIBUTORS
-rw-r--r-- 1 vagrant root 363 Jul 7 13:38 INSTALL.md
-rw-r--r-- 1 vagrant root 1056 Jul 7 13:38 LICENSE
-rw-r--r-- 1 vagrant root 2880 Jul 7 13:38 README.md
-rw-r--r-- 1 vagrant root 1814 Jul 7 13:38 Rakefile
-rw-r--r-- 1 vagrant root 2345 Jul 7 13:38 Vagrantfile
drwxr-xr-x 2 vagrant root 4096 Jul 7 13:38 bin
drwxr-xr-x 2 vagrant root 4096 Jul 7 13:38 build
-rwxr-xr-x 1 vagrant root 287 Jul 7 13:38 configure
drwxr-xr-x 4 vagrant root 4096 Jul 7 13:38 debian.template
drwxr-xr-x 4 vagrant root 4096 Jul 7 13:38 dev
drwxr-xr-x 5 vagrant root 4096 Jul 7 13:38 doc
drwxr-xr-x 2 vagrant root 4096 Jul 7 13:38 download_cache
drwxr-xr-x 10 vagrant root 4096 Jul 7 13:38 ext
drwxr-xr-x 3 vagrant root 4096 Jul 7 13:38 helper-scripts
drwxr-xr-x 3 vagrant root 4096 Jul 7 13:38 lib
drwxr-xr-x 2 vagrant root 4096 Jul 7 13:38 man
drwxr-xr-x 3 vagrant root 4096 Jul 7 13:38 node_lib
-rw-r--r-- 1 vagrant root 6514 Jul 7 13:38 npm-shrinkwrap.json
-rw-r--r-- 1 vagrant root 722 Jul 7 13:38 package.json
-rw-r--r-- 1 vagrant root 1243 Jul 7 13:38 passenger.gemspec
drwxr-xr-x 4 vagrant root 4096 Jul 7 13:38 resources
drwxr-xr-x 2 vagrant root 4096 Jul 7 13:38 rpm
drwxr-xr-x 10 vagrant root 4096 Jul 7 13:38 test
I have a default nginx.conf and /etc/nginx/conf.d/passenger.conf looks like this:
vagrant#vagrant:/etc/nginx/conf.d$ cat /etc/nginx/conf.d/passenger.conf
passenger_root /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45;
passenger_ruby /usr/local/rvm/rubies/ruby-2.1.2/bin/ruby;
passenger_max_pool_size 6;
passenger_spawn_method smart-lv2;
passenger_buffer_response on;
passenger_min_instances 1;
passenger_max_instances_per_app 0;
passenger_pool_idle_time 300;
passenger_max_requests 0;
If I remove the passenger.conf nginx starts without errors and serves the default test page fine. As expectable passenger does not work.
My passenger app nginx config looks like this:
vagrant#vagrant:~$ cat /etc/nginx/sites-enabled/plantasy
# Only for development purposes.
# For production environment, set it accordingly (i.e. production)
# Remove this line when you upload an actual application.
# For * TESTING * purposes only.
passenger_app_env development;
server {
listen 8080;
server_name example.com;
passenger_enabled on;
passenger_ruby /usr/local/rvm/rubies/ruby-2.1.2/bin/ruby;
root /home/vagrant/app/public;
}
If I try to access this page, I get a 403:
vagrant#vagrant:~$ curl localhost:8080
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.6.0</center>
</body>
</html>
Ruby is installed correctly:
vagrant#vagrant:~$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
Also the passenger gem is installed.
vagrant#vagrant:~$ gem list passenger
*** LOCAL GEMS ***
passenger (4.0.45)
I really do not know what's wrong. I checked out this thread but as you can see above, I have nginx present with passenger support. It's just the passenger binary missing?
Any ideas how to fix this?
And before anyone suggests it: I do not want to compile nginx myself. I want to use the version from the apt repository as it speeds up performance on vagrant VM setup very much.
Your passenger_root directive is incorrect. You can discover the correct value for it by following the guide here:
https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#inserting_passenger_root_for_apt
Check passenger-install-nginx-module is properly installed.
By 'which passenger-install-nginx-module'
if not installed, try with:
rvmsudo passenger-install-nginx-module
This is for rvm users. Will solve problem

How to use foreman to export to upstart?

I am trying to export my application to another process management format/system (specifically, upstart). In doing so, I have come across a number of roadblocks, mostly due to lacking documentation.
As a non-root user, I ran the following command (as shown here):
-bash> foreman export upstart /etc/init
ERROR: Could not create: /etc/init
I "could not create" the directory due to inadequate permissions, so I used sudo:
-bash> sudo foreman export upstart /etc/init
Password:
ERROR: Could not chown /var/log/app to app
I "could not chown... to app" because there is no user named app.
Where is app coming from?
How should I use forman to export to upstart?
app is default for both the name of the app and the name of the user the application should be run as when the corresponding options (--app and --user) are not used. See the foreman man page for the available options, but note that at the time of this writing the official synopsis did not include [options]:
foreman export [options] <format> [location]
Example:
-bash> sudo foreman export --app foo --user bar upstart /etc/init
Password:
[foreman export] writing: foo.conf
[foreman export] writing: foo-web.conf
[foreman export] writing: foo-web-1.conf
[foreman export] writing: foo-worker.conf
[foreman export] writing: foo-worker-1.conf
Result:
-bash> l /etc/init/
total 80
drwxr-xr-x 12 root wheel 408 20 Oct 09:31 .
drwxr-xr-x 94 root wheel 3196 20 Oct 08:05 ..
-rw-r--r-- 1 root wheel 236 20 Oct 09:31 foo-web-1.conf
-rw-r--r-- 1 root wheel 41 20 Oct 09:31 foo-web.conf
-rw-r--r-- 1 root wheel 220 20 Oct 09:31 foo-worker-1.conf
-rw-r--r-- 1 root wheel 41 20 Oct 09:31 foo-worker.conf
-rw-r--r-- 1 root wheel 315 20 Oct 09:31 foo.conf
-bash> l /var/log/foo/
total 0
drwxr-xr-x 2 bar wheel 68 20 Oct 09:31 .
drwxr-xr-x 45 root wheel 1530 20 Oct 09:31 ..

Resources