Class: Wco::Serverhost

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/wco/serverhost.rb

Constant Summary collapse

WORKDIR =
"/opt/projects/docker"

Instance Method Summary collapse

Instance Method Details

#add_docker_service(app = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/wco/serverhost.rb', line 56

def add_docker_service app={}
  puts! app, '#add_docker_service'

  ac   = ActionController::Base.new
  ac.instance_variable_set( :@app, app )
  ac.instance_variable_set( :@workdir, WORKDIR )
  rendered_str = ac.render_to_string("docker-compose/dc-#{app[:kind]}")
  puts '+++ add_docker_service rendered_str:'
  print rendered_str

  file = Tempfile.new('prefix')
  file.write rendered_str
  file.close
  puts! file.path, 'file.path'

  `scp #{file.path} #{ssh_host}:#{WORKDIR}/dc-#{app[:service_name]}.yml`
  `ssh #{ssh_host} 'cd #{WORKDIR} ; \
    docker compose -f dc-#{app[:service_name]}.yml up -d #{app[:service_name]} ; \
    echo ok #add_docker_service ' `
end

#create_volume(app = {}) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/wco/serverhost.rb', line 77

def create_volume app={}
  # puts! app, '#create_volume'

  ac   = ActionController::Base.new
  ac.instance_variable_set( :@app, app )
  ac.instance_variable_set( :@workdir, WORKDIR )
  rendered_str = ac.render_to_string("scripts/create_volume")
  # puts '+++ create_volume rendered_str:'
  # print rendered_str

  file = Tempfile.new('prefix')
  file.write rendered_str
  file.close
  # puts! file.path, 'file.path'

  `scp #{file.path} #{ssh_host}:#{WORKDIR}/scripts/create_volume`
  `ssh #{ssh_host} 'chmod a+x #{WORKDIR}/scripts/create_volume ; \
    #{WORKDIR}/scripts/create_volume ' `
end

#nginx_add_site(rendered_str = nil, config = {}) ⇒ Object

def nginx_add_site rendered_str=nil, config={}

# puts! config, '#nginx_add_site'
File.write( "/usr/local/etc/nginx/sites-available/#{config[:service_name]}", rendered_str )
out = `sudo nginx enable-site #{config[:service_name]} ; \
  nginx -s reload ; \
  echo ok
`;
puts! out, 'out'

end



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/wco/serverhost.rb', line 37

def nginx_add_site rendered_str=nil, config={}
  puts! rendered_str, '#nginx_add_site // rendered_str'
  puts! config, '#nginx_add_site // config'

  File.write( "tmp/#{config[:service_name]}", rendered_str )
  Net::SSH.start( ssh_host, ssh_username, keys: ssh_key ) do |ssh|

    out = ssh.scp.upload! "tmp/#{config[:service_name]}", "#{nginx_root}/conf/sites-available/"
    puts! out, 'out'

    out = ssh.exec! "#{nginx_root}/nginx enable-site #{config[:service_name]} ; #{nginx_root}/nginx -s reload"
    puts! out, 'out'

  end

end

#ssh_hostObject

net-ssh, sshkit



20
# File 'lib/wco/serverhost.rb', line 20

field :ssh_host