system preference
This commit is contained in:
1 parent
62fa589e8a
commit
b198b1a17b
19 files changed
+251
-83
No files matched your search
@@ -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
|
||||
+4
-1
@@ -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>
|
||||
Reference in new issue
Block a user