Last active
August 29, 2015 14:06
-
-
Save aeden/4435503566665b8cc267 to your computer and use it in GitHub Desktop.
Example code for Go Remote Control talk
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.exports = (robot) -> | |
# Stop a DNSimple name server, run chef-client and start it back up | |
robot.respond /deploy nameserver (\w+-\w+-\w+)$/i, (msg) -> | |
host = msg.match[1] | |
callGoRemoteControl(msg, host, 'update') |
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
callGoRemoteControl = (msg, host, action, callback) -> | |
baseUrl = "https://#{host}.example.com:9876" | |
actionUrl = "#{baseUrl}/#{action}" | |
httpAuthToken = "<auth token>" | |
msg.http(baseUrl) | |
.headers | |
'Authorization': httpAuthToken | |
.get() (err, res, body) -> | |
if err | |
msg.send "Failed to connect to node: #{err}" | |
else | |
msg.send "Executing #{action} on #{host} - this may take some time" | |
msg.http(actionUrl) | |
.headers | |
'Authorization': httpAuthToken | |
.get() (err, res, body) -> | |
if callback | |
callback(host, action, body) | |
else | |
message = "Result of #{action} on #{host}:\n" | |
message += body | |
msg.send(message) |
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
#!/usr/bin/env ruby | |
require 'open3' | |
require_relative 'stop' | |
require_relative 'start' | |
require_relative 'status' | |
def run_chef_client | |
puts "Running chef client" | |
o, e, s = Open3.capture3("chef-client") | |
puts "Chef client exit status: #{s.exitstatus}" | |
if s.exitstatus == 0 | |
notify("chef client run completed", true) | |
else | |
notify("chef client run failed: #{e}", false) | |
end | |
end | |
def main | |
silence | |
stop_exabgp | |
stop_erldnsimple | |
remove_erldnsimple_run_file | |
run_chef_client || return | |
while !erldnsimple_started? | |
sleep 3 | |
end | |
if name_server_answering? | |
puts "erldnsimple started" | |
start_exabgp || return | |
unsilence | |
else | |
puts "erldnsimple failed to start properly" | |
end | |
end | |
if __FILE__==$0 | |
main | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment