Class: Publisher::Dweb
- Inherits:
-
Object
- Object
- Publisher::Dweb
- Defined in:
- lib/depengine/publisher/dweb.rb
Instance Attribute Summary collapse
-
#siteid ⇒ Object
Returns the value of attribute siteid.
-
#ssh_key_file ⇒ Object
Returns the value of attribute ssh_key_file.
-
#staging_host ⇒ Object
Returns the value of attribute staging_host.
Instance Method Summary collapse
- #remote_symlink(source, symlink, options = {}) ⇒ Object
-
#send_command(command, options = {}) ⇒ Object
debug with: ssh -i apps/deploy_engine/etc/ssh/id_rsa.deployadmin dwebuser@dei2s.dweb.intranet.db.com > ‘enter command’.
- #upload(source, target, options = {}) ⇒ Object
Instance Attribute Details
#siteid ⇒ Object
Returns the value of attribute siteid.
5 6 7 |
# File 'lib/depengine/publisher/dweb.rb', line 5 def siteid @siteid end |
#ssh_key_file ⇒ Object
Returns the value of attribute ssh_key_file.
4 5 6 |
# File 'lib/depengine/publisher/dweb.rb', line 4 def ssh_key_file @ssh_key_file end |
#staging_host ⇒ Object
Returns the value of attribute staging_host.
3 4 5 |
# File 'lib/depengine/publisher/dweb.rb', line 3 def staging_host @staging_host end |
Instance Method Details
#remote_symlink(source, symlink, options = {}) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/depengine/publisher/dweb.rb', line 171 def remote_symlink(source, symlink, ={}) Helper.validates_presence_of staging_host, "Staging Host not set" Helper.validates_presence_of ssh_key_file, "SSH keyfile not set" result = '' joined_filename = File.join(File.dirname($exec_file_path), ssh_key_file) ssh_key_file = joined_filename # overwrite siteid for multi target deployments if not [:siteid].nil? self.siteid = [:siteid] end Helper.validates_presence_of siteid, "Siteid not set" # check ssh keyfile if not File.file? ssh_key_file $log.writer.error "Can not find SSH keyfile #{ssh_key_file}" exit 1 end begin Net::SFTP.start(staging_host, siteid + 'f', \ :auth_methods => ['publickey'], \ :forward_agent => false, \ :keys => ssh_key_file, \ :timeout => 90 ) do |session| begin if session.lstat!(symlink).type == Net::SFTP::Protocol::V01::Attributes::T_SYMLINK $log.writer.debug "Delete already existing link #{symlink}" session.remove!(symlink) end rescue # maybe the link does not exist yet, or the remove faild # anyway, we try to create it end session.symlink!(source, symlink) end rescue Exception => e $log.writer.error "Can not create remote symlink #{symlink} to #{source} " $log.writer.error e. $log.writer.error e.backtrace.join("\n") exit 1 end true end |
#send_command(command, options = {}) ⇒ Object
debug with: ssh -i apps/deploy_engine/etc/ssh/id_rsa.deployadmin dwebuser@dei2s.dweb.intranet.db.com > ‘enter command’
23 24 25 26 27 28 29 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 92 93 94 95 96 97 98 99 100 |
# File 'lib/depengine/publisher/dweb.rb', line 23 def send_command(command, ={}) Helper.validates_presence_of staging_host, "Staging Host not set" Helper.validates_presence_of ssh_key_file, "SSH keyfile not set" Helper.validates_presence_of siteid, "Siteid not set" result = '' joined_filename = File.join(File.dirname($exec_file_path), ssh_key_file) ssh_key_file = joined_filename # overwrite siteid for multi target deployments if not [:siteid].nil? self.siteid = [:siteid] end # check ssh keyfile if not File.file? ssh_key_file $log.writer.error "Can not find SSH keyfile #{ssh_key_file}" exit 1 end ### Probleme auf UAT und PROD if command.include? "list" return result end Net::SSH.start(staging_host, "dwebuser", \ :auth_methods => ['publickey'], \ :forward_agent => false, \ :keys => ssh_key_file, \ :timeout => 90 ) do |session| session.open_channel do |ch| ch.exec "/scripts/dwebuser #{siteid}" do |ch, success| if not success $log.writer.error "Can not execute dwebuser command" exit 1 end ch.on_data do |ch, data| if not data.empty? result << data if command.include? "list" result_a = result.split("\n") test = result_a.last if not test.nil? and test.length > 0 $log.writer.info "Deployment Status: #{test}" end end end end # something on stderr? ch.on_extended_data do |ch, type, data| # dirty filter for non critical return messages if data =~ /^ERROR.*/ $log.writer.error \ "Received error from dwebuser command: #{data}" exit 1 else $log.writer.debug \ "Received output from dwebuser command: #{data}" end end ch.on_close do |ch| result << "all done, closing ssh channel!" end ch.send_data command + "\n" end ch.wait end end $log.writer.debug result return result end |
#upload(source, target, options = {}) ⇒ Object
102 103 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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/depengine/publisher/dweb.rb', line 102 def upload(source, target, ={}) Helper.validates_presence_of staging_host, "Staging Host not set" Helper.validates_presence_of ssh_key_file, "SSH keyfile not set" result = '' joined_filename = File.join(File.dirname($exec_file_path), ssh_key_file) ssh_key_file = joined_filename # overwrite siteid for multi target deployments if not [:siteid].nil? self.siteid = [:siteid] end Helper.validates_presence_of siteid, "Siteid not set" # check ssh keyfile if not File.file? ssh_key_file $log.writer.error "Can not find SSH keyfile #{ssh_key_file}" exit 1 end # first connection to delete files begin if not [:cleanup] == false Net::SFTP.start(staging_host, siteid + 'f', \ :auth_methods => ['publickey'], \ :forward_agent => false, \ :keys => ssh_key_file, \ :timeout => 90 ) do |session| # delete all files in target, but not the target-dir itself $log.writer.debug "Cleaning remote directory #{target}" session.rm_r!(target) end end # second connection to upload files processing_file = "" Net::SCP.start(staging_host, siteid + 'f', \ :auth_methods => ['publickey'], \ :forward_agent => false, \ :keys => ssh_key_file, \ :timeout => 90 ) do |session| Dir.glob(File.join(source, '/*'), File::FNM_DOTMATCH) do |entry| if not entry =~ /\.$/ processing_file = entry if not [:excludes].nil? if [:excludes].any? {|term| entry.include? term } $log.writer.debug "Exclude #{entry} from upload" else $log.writer.debug "Upload #{entry}" session.upload!(entry, File.join(target, '/'), \ :recursive => true) end else $log.writer.debug "Upload #{entry}" session.upload!(entry, File.join(target, '/'), \ :recursive => true) end end end end rescue Exception => e $log.writer.error "Can not upload file #{processing_file} to #{target}" $log.writer.error e. $log.writer.error e.backtrace.join("\n") exit 1 end end |