Created
December 21, 2010 11:10
-
-
Save shouichi/749800 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Daemons | |
class Base | |
include SSH | |
attr_accessor :server | |
delegate :logger, :address, :to => :server | |
class << self | |
def inherited(klass) | |
klass.instance_eval do | |
cattr_accessor :path | |
end | |
end | |
def has_path(path) | |
self.path = path | |
end | |
end | |
def initialize(server) | |
@server = server | |
end | |
def reload | |
exec(:reload) | |
end | |
def restart | |
exec(:restart) | |
end | |
def exec(*args) | |
ssh("c4sa", address, "sudo #{self.class.path} #{args}") | |
end | |
end | |
class Nginx < Base | |
has_path "/etc/init.d/nginx" | |
end | |
class Syslog < Base | |
has_path "/etc/init.d/syslog-ng" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Server < ActiveRecord::Base | |
def nginx | |
@nginx ||= Daemons::Nginx.new(self) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SSH | |
def ssh(user, host, command) | |
ssh = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no #{user}@#{host} #{command}" | |
logger.info(ssh) | |
`#{ssh}` if Rails.env.production? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment