Class: IntercityCLI::Application
- Inherits:
-
Thor
- Object
- Thor
- IntercityCLI::Application
- Defined in:
- lib/intercity/cli/application.rb
Instance Method Summary collapse
Instance Method Details
#add(application) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/intercity/cli/application.rb', line 104 def add(application) address = [:server] configuration = IntercityCLI::Configuration.new() node_file = File.join(configuration.config_directory, "#{address}.json") if File.exists?(node_file) raw_json = File.read(node_file) json = JSON.parse(raw_json) else raise "No configuration file for this server yet! Please create one by running:\n\n$ intercity server install <ip address>\n\n" end json["active_applications"] ||= {} json["active_applications"][application] ||= {} json["active_applications"][application].merge!( { "domain_names" => [[:domain_name]], "rails_env" => [:rails_environment], "database_info" => { "adapter" => [:database_adapter], "host" => [:database_host], "username" => [:database_user], "password" => [:database_password], "database" => [:database_name] }, "ruby_version" => [:ruby_version] } ) File.open(node_file, "w+") do |f| f.write(JSON.pretty_generate(json)) end server = address user = [:user] on server do |host| with debian_frontend: :noninteractive do host.user = user upload! node_file, "/root/server_config.json" execute 'chef-client -z -j ~/server_config.json -o "recipe[rails::passenger],recipe[rails::databases]"' end end end |
#edit(application) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/intercity/cli/application.rb', line 30 def edit(application) address = [:server] configuration = IntercityCLI::Configuration.new() node_file = File.join(configuration.config_directory, "#{address}.json") user = [:user] raw_json = File.read(node_file) json = JSON.parse(raw_json) json["active_applications"][application]["env_vars"] ||= {} env_vars = json["active_applications"][application]["env_vars"] temp_contents = [] env_vars.each do |key, val| temp_contents << [key,val].join("=") end tmp_file = temp_contents.join("\n") tmp_filename = "tmp_" + SecureRandom.hex() File.open(tmp_filename, "w") do |f| f.write(tmp_file) end file_stamp_before_editing = File.mtime(tmp_filename) response = system("$EDITOR #{tmp_filename}") if file_stamp_before_editing != File.mtime(tmp_filename) new_vars = {} new_vars_file = File.read(tmp_filename) new_vars_file.each_line() do |line| key, value = line.strip.split("=") new_vars[key] = value end File.unlink(tmp_filename) raw_json = File.read(node_file) json = JSON.parse(raw_json) json["active_applications"][application]["env_vars"] = new_vars File.open(node_file, "w") do |f| f.write(JSON.pretty_generate(json)) end server = address user = [:user] on server do |host| with debian_frontend: :noninteractive do host.user = user upload! node_file , "/root/server_config.json" execute 'chef-client -z -j ~/server_config.json -o "recipe[rails::env_vars]"' end end else File.unlink(tmp_filename) end end |
#list ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/intercity/cli/application.rb', line 14 def list() configuration = IntercityCLI::Configuration.new() server = [:server] user = [:user] on server do |host| host.user = user applications = capture("ls /u/apps") puts applications end end |