What user is running my Rails app?

2019-03-16 21:52发布

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

3条回答
欢心
2楼-- · 2019-03-16 22:26

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

查看更多
beautiful°
3楼-- · 2019-03-16 22:40

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"
查看更多
▲ chillily
4楼-- · 2019-03-16 22:43

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

查看更多
登录 后发表回答