Skip to content

Instantly share code, notes, and snippets.

@hoshinotsuyoshi
Created July 15, 2014 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoshinotsuyoshi/627362efc554e2fd9a5f to your computer and use it in GitHub Desktop.
Save hoshinotsuyoshi/627362efc554e2fd9a5f to your computer and use it in GitHub Desktop.
VultrVPSへCoreOSを入れる。ipxe/cloud-configでBootstrap/Configurationする用のサンプルスクリプト(embedded)
@time = Time.now
@reporter = []
require 'pry'
require 'vultrlife'
require 'net/ssh'
account = Vultrlife::Account.new do |account|
account.api_key = 'xxxxxxxxxxxxxxxxxxx'
end
#binding.pry
#account.servers.first.destroy!
#exit
# TODO サーバーを1つにしたいときはコメントイン
#puts 'check server exists...'
#if account.servers.size.nonzero?
# account.servers.first.destroy!
# puts 'server destroyed'
#end
@reporter << {period: :destroying, time: Time.now-@time}; @time = Time.now
puts 'trying create server....'
server = account.server_create! do |server|
server.plan = '768 MB RAM,15 GB SSD,0.10 TB BW, Custom ISO'
server.region = :tokyo
server.os = 'Custom'
server.ipxe_chain_url = 'http://young-dawn-7740.herokuapp.com/script.txt'
end
puts 'server created'
@reporter << {period: :creating, time: Time.now-@time}; @time = Time.now
ip = ''
loop do
ip = account.servers.last['main_ip']
if ip == '0.0.0.0' || ip == '0'
puts 'waiting for ip...'
sleep 2
else
puts "ip is #{ip}"
break
end
end
@reporter << {period: :ip_waiting, time: Time.now-@time}; @time = Time.now
username = 'core'
puts 'you can login by below command'
puts '---------------------------'
puts "ssh #{username}@#{ip}"
puts '---------------------------'
`sed -i -e '/#{ip}/d' ~/.ssh/known_hosts` #MacOSX
puts 'trying coreos install...'
while !@connectable
puts 'trying ssh login...'
Net::SSH.start(ip, username, :keys => ['/Users/berlin/.ssh/id_rsa']) do |ssh|
ssh.exec!('/bin/true')
@connectable = true
end rescue nil
sleep 2
end
@reporter << {period: :ssh_waiting, time: Time.now-@time}; @time = Time.now
output = ''
Net::SSH.start(ip, username, :keys => ['/Users/berlin/.ssh/id_rsa']) do |ssh|
output = ssh.exec!('curl -L https://gist.githubusercontent.com/hoshinotsuyoshi/4421f1d7754db9629903/raw/7b005f4e8438434f48b7f03b50946c9c6731c0a1/test-config.config > ~/config && sudo coreos-install -d /dev/vda -c ~/config && sudo mount -o subvol=root /dev/vda9 /mnt/')
puts 'trying reboot...'
#binding.pry
output = ssh.exec!('sudo reboot')
end rescue nil
@reporter << {period: :coreos_installing, time: Time.now-@time}; @time = Time.now
`sed -i -e '/#{ip}/d' ~/.ssh/known_hosts` #MacOSX
puts 'bootstraping completed'
puts @reporter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment