2012-03-02 79 views
4

我繼承了一個Rails應用程序,我試圖理解它。然而,當我運行:如何更改Thin的配置?

rails s 

我收到此日誌:

=> Booting Thin 
=> Rails 3.2.1 application starting in development on http://0.0.0.0:3000 
=> Call with -d to detach 
=> Ctrl-C to shutdown server 
>> Thin web server (v1.3.1 codename Triple Espresso) 
>> Maximum connections set to 1024 
>> Listening on 0.0.0.0:3000, CTRL+C to stop 

不過,這似乎有問題給我,因爲兩個服務器都試圖在3000聽什麼使導軌推出薄,當我運行rails s

回答

5

當安裝了gem的thin時,ra​​ils會默認使用它作爲服務器。

您可以使用-p選項更改端口,例如-p 3001。還有更多選項可用於設置環境,綁定地址和類似信息。有關Rails guide中的更多信息。

+0

我不知道爲什麼我下的印象的Rails試圖在同一端口上啓動2臺服務器。 – Geo 2012-03-02 09:27:20

3

你可以做這樣的事情:

thin start -p 3000 -e production ....等等每個參數。但它太無聊了...

最好的辦法是在你的app_name/config/目錄下創建配置yml文件。

#config/my_thin.yml 

user: www-data 
group: www-data 
pid: tmp/pids/thin.pid 
timeout: 30 
wait: 30 
log: log/thin.log 
max_conns: 1024 
require: [] 
environment: production 
max_persistent_conns: 512 
servers: 1 
threaded: true 
no-epoll: true 
daemonize: true 
socket: tmp/sockets/thin.sock 
chdir: /path/to/your/apps/root 
tag: a-name-to-show-up-in-ps aux 

並運行它指定該配置文件:thin start -C config/mythin.yml

5

實施例,與nginx的和薄服務器Padrinorb應用:

# config/thin.yml 

port: 3000 
user: padrino 
group: padrino 
pid: tmp/pids/thin.pid 
timeout: 30 
wait: 30 
log: log/thin.log 
max_conns: 1024 
require: [] 
environment: production 
max_persistent_conns: 512 
servers: 4 
threaded: true 
no-epoll: true 
daemonize: true 
socket: tmp/sockets/thin.sock 
chdir: /home/padrino/my-padrino-app 
tag: my-padrino-app 

Nginx的

# /etc/nginx/sites-enabled/my-padrino-app 

server { 
    listen 80 default_server; 
    server_name my-padrino-app.com; 
    location/{ 
     proxy_pass http://padrino; 
    } 
} 

upstream padrino { 
    server unix:/home/padrino/my-padrino-app/tmp/sockets/thin.0.sock; 
    server unix:/home/padrino/my-padrino-app/tmp/sockets/thin.1.sock; 
    server unix:/home/padrino/my-padrino-app/tmp/sockets/thin.2.sock; 
    server unix:/home/padrino/my-padrino-app/tmp/sockets/thin.3.sock; 
} 

腳本來啓動,停止,重新啓動,狀態

#!/usr/bin/env bash 
# bin/my-padrino-app-service.sh 

APPDIR="/home/padrino/my-padrino-app" 
CURDIR=$(pwd) 

if [[ $# -lt 1 ]] 
then 
    echo 
    echo "Usage:" 
    echo " $0 <start|stop|restart|status>" 
    echo 
    exit 1 
fi 

case $1 in 
    "status") 
     cat $APPDIR/tmp/pids/thin.* &> /dev/null 
     if [[ $? -ne 0 ]] 
     then 
      echo "Service stopped" 
     else 
      for i in $(ls -C1 $APPDIR/tmp/pids/thin.*) 
      do 
       echo "Running: $(cat $i)" 
      done 
     fi 
    ;; 
    "start") 
     echo "Making thin dirs..." 
     mkdir -p $APPDIR/tmp/thin 
     mkdir -p $APPDIR/tmp/pids 
     mkdir -p $APPDIR/tmp/sockets 

     echo "Starting thin..." 
     cd $APPDIR 
     # Production 
     thin start -e production -C $APPDIR/config/thin.yml 
     cd $CURDIR 
     sleep 2 
     $0 status 
    ;; 
    "stop") 
     cat $APPDIR/tmp/pids/thin.* &> /dev/null 
     if [[ $? -eq 0 ]] 
     then 
      for i in $(ls -C1 $APPDIR/tmp/pids/thin.*) 
      do 
       PID=$(cat $i) 
       echo -n "Stopping thin ${PID}..." 
       kill $PID 
       if [[ $? -eq 0 ]] 
       then 
        echo "OK" 
       else 
        echo "FAIL" 
       fi 
      done 
     fi 
     $0 status 
    ;; 
    "restart") 
     $0 stop 
     $0 start 
     $0 status 
    ;; 
esac