system preference
This commit is contained in:
parent
62fa589e8a
commit
b198b1a17b
|
@ -14,6 +14,13 @@ class Admin::SitesController < OrbitBackendController
|
|||
# @site = Site.new
|
||||
# end
|
||||
|
||||
def show_system_preference
|
||||
@git_commit_list_file = File.new(OrbitSystemPreference::GitCommitListPath, "r") rescue nil
|
||||
@db_backup_list_file = File.new(OrbitSystemPreference::ArchiveDbListPath, "r") rescue nil
|
||||
@resque_logs_file = File.new(OrbitSystemPreference::ResqueLogFile, "r") rescue nil
|
||||
@site = Site.first
|
||||
end
|
||||
|
||||
def update
|
||||
@site.update_attributes(params[:site])
|
||||
site_restart
|
||||
|
|
|
@ -5,9 +5,13 @@ class BackupServer
|
|||
#CronMail.time_check("Going to backup Orbit").deliver
|
||||
dbhost = Mongoid.config.database.connection.primary.join ':'
|
||||
dbname = Mongoid.config.database.name
|
||||
archive_db_list_path = OrbitSystemPreference::ArchiveDbListPath
|
||||
dbdirectory = "#{Rails.root}/tmp/#{dbname}-"+Time.now.strftime("%Y-%m-%d-%H-%M")
|
||||
%x[mongodump -h #{dbhost} -d #{dbname} -o #{dbdirectory} ]
|
||||
|
||||
# %x[touch #{Rails.root}/tmp/restart]
|
||||
%x[rm #{archive_db_list_path}]
|
||||
%x[ls #{Rails.root}/tmp/#{dbname}* | du -h --max-depth=1 --block-size=1M |sort -h >> #{archive_db_list_path}]
|
||||
OrbitJobLogger.info "DB backup done Path:#{dbdirectory}"
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
class DashboardCounter < Resque::Plugins::RestrictionJob
|
||||
@queue = :high
|
||||
|
||||
def self.perform(*args)
|
||||
site = Site.first
|
||||
obj = new(*args)
|
||||
site.dashboard_counter[:visitors_this_week] = obj.display_visitors_this_week
|
||||
site.dashboard_counter[:visitors_this_month] = obj.display_visitors_this_month
|
||||
site.dashboard_counter[:visitors_this_year] = obj.display_visitors_this_year
|
||||
site.save
|
||||
OrbitJobLogger.info "DashboardCounter done #{site.dashboard_counter.to_s}"
|
||||
end
|
||||
|
||||
|
||||
def display_visitors(options={})
|
||||
impressions = Impression.where(options).and(:referrer.ne => nil)
|
||||
impressions.map{|i| i[:session_hash]}.uniq.count
|
||||
end
|
||||
|
||||
def display_visitors_today
|
||||
display_visitors(created_at: {'$gte' => Date.today.beginning_of_day, '$lte' => Date.today.end_of_day})
|
||||
end
|
||||
|
||||
def display_visitors_this_week
|
||||
display_visitors(created_at: {'$gte' => Date.today.beginning_of_week, '$lte' => Date.today.end_of_week})
|
||||
end
|
||||
|
||||
def display_visitors_this_month
|
||||
display_visitors(created_at: {'$gte' => Date.today.beginning_of_month, '$lte' => Date.today.end_of_month})
|
||||
end
|
||||
|
||||
def display_visitors_this_year
|
||||
display_visitors(created_at: {'$gte' => Date.today.beginning_of_year, '$lte' => Date.today.end_of_year})
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,46 @@
|
|||
class GenerateSystemSummary
|
||||
@queue = :high
|
||||
|
||||
def self.perform()
|
||||
@site = Site.first
|
||||
get_disk_free
|
||||
get_git_log_list
|
||||
get_package_info
|
||||
@site.save
|
||||
end
|
||||
|
||||
def self.get_package_info
|
||||
@info = {}
|
||||
get_nginx_version
|
||||
get_MongoDB_version
|
||||
get_Linux_version
|
||||
@site.system_package_info = @info
|
||||
end
|
||||
|
||||
def self.get_git_log_list
|
||||
git_commit_list_path = OrbitSystemPreference::GitCommitListPath
|
||||
%x[rm #{git_commit_list_path}]
|
||||
%x[cd #{Rails.root};#{OrbitSystemPreference::GitLogCommend} >>#{git_commit_list_path} ]
|
||||
end
|
||||
|
||||
def self.get_disk_free
|
||||
@site.disk_space= %x[#{OrbitSystemPreference::DiskFree}]
|
||||
end
|
||||
|
||||
def self.get_nginx_version
|
||||
@info[:nginx] = %x[#{OrbitSystemPreference::SystemPackage::NginxVersion} ]
|
||||
end
|
||||
|
||||
def self.get_MongoDB_version
|
||||
@info[:mongodb] = %x[#{OrbitSystemPreference::SystemPackage::MongodbVersion} ]
|
||||
end
|
||||
|
||||
def self.get_Linux_version
|
||||
@info[:linux] = %x[#{OrbitSystemPreference::SystemPackage::SystemVersion} ]
|
||||
end
|
||||
|
||||
def self.check_system_has_enough_space( limit =OrbitSystemPreference::DefaultDiskSpaceLimit )
|
||||
binding.pry
|
||||
end
|
||||
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
class NccuCalendar
|
||||
require 'open-uri'
|
||||
require 'tempfile'
|
||||
|
||||
@queue = :high
|
||||
|
||||
def self.perform()
|
||||
# temp_file = Tempfile.new('new_cal')
|
||||
# open('http://events.nccu.edu.tw/Month').read{|data|
|
||||
# temp_file << data
|
||||
# }
|
||||
|
||||
open(File.join(Rails.root, 'public/static', 'nccu_calendar.xml'), 'wb') do |fo|
|
||||
fo.print open('http://events.nccu.edu.tw/Month').read
|
||||
end
|
||||
|
||||
# FileUtils.mv(temp_file, File.join(Rails.root, 'public/static', 'nccu_calendar.xml'))
|
||||
|
||||
puts "[#{ DateTime.now.strftime("%Y %D %H:%M")}]NccuCalendar Synced #{File.join(Rails.root, 'public/static', 'nccu_calendar.xml')}"
|
||||
end
|
||||
end
|
|
@ -1,25 +0,0 @@
|
|||
class SyncDb
|
||||
|
||||
@queue = :high
|
||||
|
||||
def self.perform()
|
||||
puts "[ #{DateTime.now.strftime("%Y %D %H:%M") }]\t SyncDb Starting"
|
||||
self.start_sync
|
||||
self.set_admin
|
||||
end
|
||||
|
||||
def self.start_sync
|
||||
task = 'mid_site:sync'
|
||||
args = []
|
||||
%x[rake #{task} --trace >> #{Rails.root}/log/rake.log]
|
||||
User.all.each{|ur| ur.create_dept_cache}
|
||||
puts "[#{ DateTime.now.strftime("%Y %D %H:%M")}]\tSyncDb Synced"
|
||||
end
|
||||
|
||||
def self.set_admin
|
||||
task = 'mid_site:install_admin'
|
||||
args = []
|
||||
%x[rake #{task} --trace >> #{Rails.root}/log/rake.log]
|
||||
puts "[#{ DateTime.now.strftime("%Y %D %H:%M")}]\tAdmin done"
|
||||
end
|
||||
end
|
|
@ -5,5 +5,6 @@ class UpdateTagCloud
|
|||
Tag.all.each do |tag|
|
||||
tag.update_attribute(:cloud_view_count, tag.impressionist_count(:created_at.gte => 14.days.ago, :created_at.lte => Time.now))
|
||||
end
|
||||
OrbitJobLogger.info "UpdateTagCloud Done"
|
||||
end
|
||||
end
|
|
@ -18,7 +18,10 @@ class Site
|
|||
field :title_always_on, :type => Boolean, :default => false
|
||||
field :dashbroad_allow_visitor, :type => Boolean, :default => false
|
||||
field :mail_settings, :type => Hash
|
||||
|
||||
|
||||
field :disk_space, :type => String
|
||||
field :system_package_info, :type => Hash,:default=>{}
|
||||
|
||||
field :school
|
||||
field :department
|
||||
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<h1><%= I18n.t("site.system_preference") %></h1>
|
||||
<ul class="nav nav-tabs" id="myTab">
|
||||
<li class="active"><a href="#summary" data-toggle="tab"><%= I18n.t("site.system_preference_.tab_summary") %></a></li>
|
||||
<li><a href="#commits" data-toggle="tab"><%= I18n.t("site.system_preference_.tab_commits") %></a></li>
|
||||
<li><a href="#backups" data-toggle="tab"><%= I18n.t("site.system_preference_.tab_backups") %></a></li>
|
||||
<li><a href="#resque_logs" data-toggle="tab"><%= I18n.t("site.system_preference_.tab_logs") %></a></li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active in" id="summary">
|
||||
<h2><%= I18n.t("site.system_preference_.summary.disk_space") %>:</h2>
|
||||
<%= content_tag :p,@site.disk_space %>
|
||||
<h2><%= I18n.t("site.system_preference_.summary.code_update_at") %>: </h2>
|
||||
<% @site.system_package_info.each do |index,value| %>
|
||||
<h2><%= index.titleize %> <%= I18n.t("site.system_preference_.summary.version") %>:</h2>
|
||||
<%= content_tag :p,value %>
|
||||
<% end %>
|
||||
<h2><%= I18n.t("site.system_preference_.summary.weekness_report") %>:<%= '' %></h2>
|
||||
</div>
|
||||
<div class="tab-pane" id="commits">
|
||||
<% if @git_commit_list_file %>
|
||||
<% @git_commit_list_file.lines do |line|%>
|
||||
<%= (line + "<br/>").html_safe %>
|
||||
<% end%>
|
||||
<% else %>
|
||||
<div class="well"><%= I18n.t("site.system_preference_.summary.no_data") %></div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="tab-pane" id="backups">
|
||||
<%if @db_backup_list_file %>
|
||||
<% @db_backup_list_file.lines do |line|%>
|
||||
<%=(line + "<br/>").html_safe %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div class="well"><%= I18n.t("site.system_preference_.summary.no_data") %></div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="tab-pane" id="resque_logs">
|
||||
<%if @db_backup_list_file %>
|
||||
<% @resque_logs_file.lines do |line|%>
|
||||
<%=(line + "<br/>").html_safe %>
|
||||
<% end if @resque_logs_file%>
|
||||
<%else %>
|
||||
<div class="well"><%= I18n.t("site.system_preference_.summary.no_data") %></div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
|
@ -5,4 +5,5 @@ YAML::ENGINE.yamler = 'syck'
|
|||
|
||||
# Initialize the rails application
|
||||
Orbit::Application.initialize!
|
||||
Me = Site.first
|
||||
Me = Site.first
|
||||
OrbitJobLogger = OrbitJobLog.new
|
|
@ -0,0 +1,13 @@
|
|||
module OrbitSystemPreference
|
||||
ArchiveDbListPath = "#{Rails.root}/log/archive_db.list.log"
|
||||
GitCommitListPath = "#{Rails.root}/log/git_commit.list.log"
|
||||
ResqueLogFile ="#{Rails.root}/log/orbit_job.log"
|
||||
GitLogCommend = 'git log --pretty=format:"%x09%ad%x09%s" --date=short'
|
||||
DiskFree= 'df -h /'
|
||||
DefaultDiskSpaceLimit = 3 #in GB
|
||||
module SystemPackage
|
||||
MongodbVersion = "mongod --version"
|
||||
NginxVersion = "nginx -V"
|
||||
SystemVersion = "uname -a"
|
||||
end
|
||||
end
|
|
@ -389,6 +389,18 @@ en:
|
|||
search_help: Please Enter the search argument for Google search.
|
||||
settings: Site setting
|
||||
sub_menu: Site sub-menu
|
||||
system_preference: System Preference
|
||||
system_preference_:
|
||||
tab_backups: Backups
|
||||
tab_commits: Commits
|
||||
tab_summary: Summary
|
||||
tab_logs: Logs
|
||||
summary:
|
||||
code_update_at: Code Update histroy
|
||||
disk_space: Disk Free
|
||||
no_data: No Data
|
||||
version: Version
|
||||
weekness_report: Weekness Report
|
||||
title: Site Title
|
||||
title_help: Site Title Guide
|
||||
site_: Site
|
||||
|
|
|
@ -389,6 +389,18 @@ zh_tw:
|
|||
search_help: 請輸入送交Google搜尋的參數
|
||||
settings: 基本設定
|
||||
sub_menu: 次選單
|
||||
system_preference: 系統狀態
|
||||
system_preference_:
|
||||
tab_backups: 備份記錄
|
||||
tab_commits: 程式版本
|
||||
tab_summary: 總覽
|
||||
tab_logs: 登錄檔
|
||||
summary:
|
||||
code_update_at: 程式更新紀錄
|
||||
disk_space: 硬碟空間
|
||||
no_data: 沒有資訊
|
||||
version: 版本
|
||||
weekness_report: 弱點掃瞄資訊
|
||||
title: 網站標題
|
||||
title_help: 網站標題說明
|
||||
site_: 網站
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
#developer pls change here
|
||||
rails_root = "/home/nccu/stage/NCCU" #keep this blank when development
|
||||
rails_env = ENV['RAILS_ENV'] || "production"
|
||||
rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/..'
|
||||
user_home = ENV['HOME'] || File.dirname(__FILE__) + '/../..'
|
||||
development_uid = ''
|
||||
development_gid = ''
|
||||
|
||||
development_uid = 'kaito' #when dev
|
||||
development_gid = 'staff' #when dev
|
||||
|
||||
#rails_env = "developement"
|
||||
rails_env = "production"
|
||||
|
||||
development_rails_root = File.expand_path("..",File.dirname(__FILE__))
|
||||
#rails_root = (rails_env == 'production' )? production_rails_root : development_rails_root
|
||||
num_workers = rails_env == 'production' ? 5 : 2
|
||||
|
||||
num_workers.times do |num|
|
||||
|
@ -16,16 +11,26 @@ num_workers.times do |num|
|
|||
|
||||
w.dir = rails_root
|
||||
w.name = "resque-#{num}"
|
||||
w.group = 'resque-stage'
|
||||
w.group = 'nccu_production'
|
||||
|
||||
w.interval = 30.seconds
|
||||
w.env = {"QUEUE"=>"critical,high,low", "RAILS_ENV"=>rails_env}
|
||||
w.start = "rake -f #{rails_root}/Rakefile resque:work QUEUE=* RAILS_ENV=#{rails_env}"
|
||||
|
||||
queue = case num
|
||||
when 0
|
||||
'critical'
|
||||
when 1..2
|
||||
'high,low'
|
||||
when 3..num_workers
|
||||
'low'
|
||||
end
|
||||
|
||||
w.env = {"QUEUE"=>queue, "RAILS_ENV"=>rails_env}
|
||||
w.start = "HOME=#{user_home} rake -f #{rails_root}/Rakefile resque:work QUEUE=* RAILS_ENV=#{rails_env}"
|
||||
|
||||
w.uid = (rails_env == 'production' )? "root" : development_uid
|
||||
w.gid = (rails_env == 'production' )? "root" : development_gid
|
||||
|
||||
w.log = (rails_env == 'production' )? "/var/log/#{w.name}-stage.log":"#{rails_root}/log/#{w.name}.log"
|
||||
w.log = (rails_env == 'production' )? "/var/log/#{w.group}-#{w.name}":"#{rails_root}/log/dev_resque-#{w.name}.log"
|
||||
|
||||
# restart if memory gets too high
|
||||
w.transition(:up, :restart) do |on|
|
||||
|
|
|
@ -1,27 +1,21 @@
|
|||
#developer pls change here
|
||||
rails_root = "/home/nccu/NCCU/" #keep this blank when development
|
||||
|
||||
development_uid = 'kaito' #when dev
|
||||
development_gid = 'staff' #when dev
|
||||
|
||||
#rails_env = "developement"
|
||||
rails_env = "production"
|
||||
|
||||
development_rails_root = File.expand_path("..",File.dirname(__FILE__))
|
||||
#rails_root = (rails_env == 'production' )? production_rails_root : development_rails_root
|
||||
rails_env = ENV['RAILS_ENV'] || "production"
|
||||
rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/..'
|
||||
user_home = ENV['HOME'] || File.dirname(__FILE__) + '/../..'
|
||||
development_uid = ''
|
||||
development_gid = ''
|
||||
|
||||
God.watch do |w|
|
||||
w.dir = rails_root
|
||||
w.name = "resque-scheduler"
|
||||
w.group = 'resque'
|
||||
w.group = 'nccu_production'
|
||||
w.interval = 30.seconds
|
||||
w.env = {"QUEUE"=>"critical,high,low", "RAILS_ENV"=>rails_env}
|
||||
w.start = "rake -f #{rails_root}/Rakefile resque:scheduler RAILS_ENV=#{rails_env}"
|
||||
w.start = "HOME= #{user_home} rake -f #{rails_root}/Rakefile resque:scheduler RAILS_ENV=#{rails_env}"
|
||||
|
||||
w.uid = (rails_env == 'production' )? "root" : development_uid
|
||||
w.gid = (rails_env == 'production' )? "root" : development_gid
|
||||
|
||||
w.log = (rails_env == 'production' )? "/var/log/#{w.name}.log":"#{rails_root}/log/#{w.name}.log"
|
||||
w.log = (rails_env == 'production' )? "/var/log/#{w.group}-#{w.name}.log":"#{rails_root}/log/dev_resque-#{w.name}.log"
|
||||
|
||||
# restart if memory gets too high
|
||||
w.transition(:up, :restart) do |on|
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
# do_mail_matt:
|
||||
# every: 10s
|
||||
# class: FetchTime
|
||||
# args:
|
||||
# description: Runs the perform method in FetchTime
|
||||
|
||||
update_tag_cloud:
|
||||
cron: 0 0 [0,12] * * *
|
||||
class: UpdateTagCloud
|
||||
args:
|
||||
description: UpdateTagCloud
|
||||
|
||||
generate_system_summary:
|
||||
cron: 0 0 12 * * *
|
||||
class: GenerateSystemSummary
|
||||
args:
|
||||
description: Generate the system status such as disk free space,package version list for showing at site tab
|
|
@ -17,6 +17,7 @@ Orbit::Application.routes.draw do
|
|||
|
||||
# routes for admin
|
||||
namespace :admin do
|
||||
match 'system_preference' => "sites#show_system_preference",:as=>"system_preference"
|
||||
mount Resque::Server.new, :at => "/resque"
|
||||
resources :assets do
|
||||
collection do
|
||||
|
|
BIN
lib/NewBlog.zip
BIN
lib/NewBlog.zip
Binary file not shown.
|
@ -0,0 +1,32 @@
|
|||
class OrbitJobLog < Logger
|
||||
FORMAT = "%m/%d/%Y %H:%M%p: "
|
||||
def initialize
|
||||
case Rails.env
|
||||
when 'production'
|
||||
# Logger::Syslog.new("orbit_routine", Syslog::LOG_LOCAL5)
|
||||
super(Orbit::Application.config.root.to_s+'/log/orbit_job.log','daily')
|
||||
when 'development'
|
||||
super(Orbit::Application.config.root.to_s+'/log/orbit_job.dev.log','daily')
|
||||
end
|
||||
end
|
||||
|
||||
def debug(msg)
|
||||
super(Time.now.strftime()+msg)
|
||||
end
|
||||
|
||||
def info(msg)
|
||||
super(Time.now.strftime(FORMAT)+msg)
|
||||
end
|
||||
|
||||
def warn(msg)
|
||||
super(Time.now.strftime(FORMAT)+msg)
|
||||
end
|
||||
|
||||
def error(msg)
|
||||
super(Time.now.strftime(FORMAT)+msg)
|
||||
end
|
||||
|
||||
def fatal(msg)
|
||||
super(Time.now.strftime(FORMAT)+msg)
|
||||
end
|
||||
end
|
Reference in New Issue