2011-11-14 42 views
0

我必須創建一個腳本來管理維護網頁服務器,我的託管公司。您推薦使用哪種寶石來實現這種自動化?

我需要做一個CLI界面,會像這個(示例場景):

(在這裏,讓我們假設MCLI是腳本的名稱,1.1.1.1原始服務器地址(主機該網站,www.exemple.com)

在這裏,我只是創建原始IP地址,維護服務器的環回接口,並創建nginx的站點特定的配置文件的網站啓用

$ mcli register www.exemple.com 1.1.1.1 
[DEBUG] Adding IP 1.1.1.1 to new loopback interface lo:001001001001 
[WARNING] No root directory specified, setting default maintenance page. 
[DEBUG] Registering www.exemple.com maintenance page and reloading Nginx: OK 

然後當我想啓用維護Ë頁面並完全關閉網站:

$ mcli maintenance www.exemple.com 
[DEBUG] Connecting to router with SSH: OK 
[DEBUG] Setting new route to 1.1.1.1 to maintenance server: OK 
[DEBUG] Writing configuration: Ok 

然後取出維護頁:

$ mcli nomaintenance www.exemple.com 
[DEBUG] Connecting to router with SSH: OK 
[DEBUG] Removing route to 1.1.1.1: Ok 
[DEBUG] Writing configuration: Ok 

而且我會需要一個功能,看網站的實際狀態

$ mcli list 
+------------------+-----------------+------------------+ 
| Site Name  | Server I.P  | Maintenance mode | 
+------------------+-----------------+------------------+ 
| www.example.com | 1.1.1.1   | Enabled   | 
| www.example.org | 1.1.1.2   | Disabled   | 
+------------------+-----------------+------------------+ 

$ mcli show www.example.org 
Site Name:  www.example.org 
Server I.P:  1.1.1.1 
Maintenance Mode: Enabled 
Root Directory : /var/www/maintenance/default/ 

但我從來沒有用Ruby做這種腳本。你對這類事情推薦什麼寶石?對於命令行解析?列/彩色輸出? SSH連接(需要連接到Cisco路由器)

您是否建議我使用本地數據庫(sqlite)來存儲元數據(階段更改,實際狀態)還是您推薦我通過分析nginx來實時計算/ interfaces配置文件並使用syslog監視對此腳本所做的更改?

這個腳本會在第一時間用於大規模數據中心的物理遷移,和明年的標準用法爲計劃的停機時間。

謝謝

回答

1

首先,我建議你得到Build awesome command-line applications in Ruby副本。

這就是說,你可能要檢查

就個人而言,我會去SQLite的存儲數據的方法,但我有偏見(具有強大的SQL背景)。

+0

做SQL是不是我的問題。可能會成爲問題的是「真實」狀態和數據庫中狀態的同步,以確保數據庫沒有失效。但也許我可以使用數據庫只是爲了記錄更改和站點註冊(名稱 - > IP),並從運行配置中獲取真實狀態 – Kedare

+0

GLI看起來很棒:) – Kedare

0

托爾是處理CLI選擇一個好的寶石。它可以在你的腳本這種類型的組織:

class Maintenance < Thor 
    desc "maintenance", "put up maintenance page" 
    method_option :switch, :aliases => '-s', :type => 'string' 
    #The method name is the name of the task that would be run => mcli maintenance 
    def maintenance 
    #do stuff 
    end 

    no_tasks do 
    #methods that you don't want cli tasks for go here 
    end 
end 
Maintenance.start 

我真的沒有列/彩色輸出什麼好的建議,但。

我絕對推薦使用某種數據庫來存儲狀態,雖然。也許不是sqlite,我可能會選擇一個redis數據庫來存儲鍵/值對與你正在尋找的信息。

0

我們有類似的任務。我用下一個架構

  • 小應用程序(C)產生什麼配置文件
  • 添加的nginx的init.d腳本新開關update_clusters。這個腳本會重啓nginx的僅在配置文件被更改的bash腳本的
update_clusters() { 
    ${CONF_GEN} --outfile=/tmp/nginx_clusters.conf 
    RETVAL=$?    
    if [[ "$RETVAL" != "0" ]]; then 
    return 5 
    fi 
    if ! diff ${CLUSTER_CONF_FILE} /tmp/nginx_clusters.conf > /dev/null; then 
     echo "Cluster configuration changed. Reload service" 
     mv -f /tmp/nginx_clusters.conf ${CLUSTER_CONF_FILE} 
     reload 
    fi     
}
  • 集將記錄添加到數據庫中。
  • Web控制檯添加/修改/刪除記錄在數據庫中(ExtJS的+ nginx的模塊)
相關問題