我在使用Passenger和Nginx的Centos 6.5服务器上运行rails应用程序。如何在不停止的情况下检查它运行的环境?
答案 0 :(得分:7)
您的环境位于Rails.env
。
Loading development environment (Rails 4.2.3)
2.1.2 :001 > Rails.env
=> "development"
您还可以在问题格式中使用环境:条件:
2.1.2 :002 > Rails.env.production?
=> false
2.1.2 :003 > Rails.env.pickle?
=> false
2.1.2 :004 > Rails.env.development?
=> true
警告 - 如果您想在代码中编写一些检查环境的内容。
答案 1 :(得分:6)
使用production
命令。例如,这表明我的乘客正在运行Application groups
环境((production-web) ubuntu@ip-10-0-3-146 ~% sudo passenger-status
Version : 5.0.15
Date : 2015-08-20 17:40:24 +0000
Instance: lNNFwV1C (Apache/2.4.7 (Ubuntu) Phusion_Passenger/5.0.15)
----------- General information -----------
Max pool size : 12
App groups : 1
Processes : 6
Requests in top-level queue : 0
----------- Application groups -----------
/home/my-app/deploy/current (production):
App root: /home/my-app/deploy/current
Requests in queue: 0
* PID: 11123 Sessions: 0 Processed: 12997 Uptime: 21h 14m 2s
CPU: 0% Memory : 190M Last used: 1s ago
* PID: 11130 Sessions: 0 Processed: 140 Uptime: 21h 14m 2s
CPU: 0% Memory : 153M Last used: 9m 32s a
* PID: 11137 Sessions: 0 Processed: 15 Uptime: 21h 14m 2s
CPU: 0% Memory : 103M Last used: 57m 54s
* PID: 11146 Sessions: 0 Processed: 6 Uptime: 21h 14m 2s
CPU: 0% Memory : 101M Last used: 7h 47m 4
* PID: 11153 Sessions: 0 Processed: 5 Uptime: 21h 14m 1s
CPU: 0% Memory : 100M Last used: 8h 42m 3
* PID: 11160 Sessions: 0 Processed: 2 Uptime: 21h 14m 1s
CPU: 0% Memory : 81M Last used: 8h 42m 3
标题下的第一行):
package internet;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
public class internet {
public static void main(String[] args) {
try {
URL url = new URL("http://www.wikipedia.org");
HttpURLConnection hc = (HttpURLConnection) url.openConnection();
int length = hc.getContentLength();
System.out.println(length);
InputStream input = url.openStream();
byte[] binput = new byte[100000];
input.read(binput);
input.close();
final String result = new String(binput);
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}
rails console不可靠 - 它只告诉您控制台在哪个环境下运行。可以将乘客配置为在不同的环境中运行。