#如何将 Rails 应用程序部署到 VPS 上
如果已经在 VPS 上假设好了 Rails 生产环境,接下来就可以将部署应用程序了。
###需要用到的工具
module Rubber | |
def self.try(diftimes = [3, 8, 2], options = { }, &block) | |
val = timeout(diftimes.shift) do | |
block.call | |
end | |
rescue options[:on] || Exception => e | |
Rails.logger.info("#{Time.now}:#{__FILE__}:#{__LINE__}}:#{e.backtrace.join("\n")}") | |
retry if diftimes.first | |
return "" |
# From http://www.mattsears.com/articles/2011/11/27/ruby-blocks-as-dynamic-callbacks | |
class Proc | |
def callback(callable, *args) | |
self === Class.new do | |
method_name = callable.to_sym | |
define_method(method_name) { |&block| block.nil? ? true : block.call(*args) } | |
define_method("#{method_name}?") { true } | |
def method_missing(method_name, *args, &block) false; end | |
end.new |
#如何将 Rails 应用程序部署到 VPS 上
如果已经在 VPS 上假设好了 Rails 生产环境,接下来就可以将部署应用程序了。
###需要用到的工具
class Lisp | |
def initialize | |
@env = { | |
:label => lambda { |(name,val), _| @env[name] = val }, | |
:quote => lambda { |sexpr, _| sexpr[0] }, | |
:car => lambda { |(list), _| list[0] }, | |
:cdr => lambda { |(list), _| list.drop 1 }, | |
:cons => lambda { |(e,cell), _| [e] + cell }, | |
:eq => lambda { |(l,r), _| l == r }, | |
:if => lambda { |(cond, thn, els), ctx| eval(cond, ctx) ? eval(thn, ctx) : eval(els, ctx) }, |
install CentOS 6
yum update
yum upgrade
check the server time. sync the time to a time server if needed (service 'ntpd')
download and install Postgresql Server v9.1 rpm package:
rpm -Uvh http://yum.pgrpms.org/9.1/redhat/rhel-6-x86_64/pgdg-centos91-9.1-4.noarch.rpm
This should have installed the necessary server package: postgresql91-server.x86_64
.
# 用于维护状态列表 | |
# Example: | |
# | |
# sm = StatusMapper.new({ | |
# '购买彩票失败' => '-3', | |
# '默认' => ['-1', '未做任何处理'], | |
# '投注成功' => '0', | |
# '购买彩票成功' => '1' | |
# }) | |
# sm['默认'].code #=> '-1' |
class Dogmatism | |
def initialize(process_name) | |
@process_name = process_name | |
@uuid = SecureRandom.uuid | |
end | |
def protect | |
begin | |
if File.exists? pidfile_path |
# -*- coding: utf-8 -*- | |
# 竞彩注码算法 | |
# 用例 | |
# teams = [ | |
# [1, '3', '0', '*'], | |
# [2, '3', '-'], | |
# [3, '3', '-'], | |
# [4, '3', '1', '*'], | |
# [5, '3', '0', '*'], | |
# [6, '3', '1', '-'], |
# 计算排列组合 | |
module LotMath | |
extend self | |
# 阶乘 | |
def F(n) | |
return 1 if n == 0 | |
(1..n).inject(:*) | |
end |
# 用于维护状态列表 | |
# Example: | |
# | |
# sm = CodeNoteMapper.new({ | |
# '-3' => '购买彩票失败', | |
# '-1' => ['默认', '未做任何处理'], | |
# '0' => '投注成功', | |
# '1' => '购买彩票成功' | |
# }) | |
# sm['默认'].code #=> '-1' |