Commit 5a5e0a64 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Create "gitlab" InfluxDB database

parent 7b917355
#!/usr/bin/env ruby
require 'socket'
if ARGV.count != 1
abort "Usage: #$0 INFLUXDB_HTTP_PORT"
end
host = '127.0.0.1'
port = ARGV.shift
success = false
HOST = '127.0.0.1'
DATABASE = 'gitlab'
begin
foreman_pid = spawn('./run', 'db')
socket_ready = false
def wait_for_socket(host,port)
30.times do
begin
TCPSocket.new(host, port)
socket_ready = true
break
return true
rescue Errno::ECONNREFUSED
sleep 1
end
end
false
end
abort "#$0: could not connect to InfluxDB at #{host}:#{port}" unless socket_ready
def main(host, port)
foreman_pid = spawn('./run', 'db')
success = system(*%W(bundle exec rake INFLUX_HOST=#{host} INFLUX_PORT=#{port}), chdir: 'influxdb/influxdb-management')
abort "#$0: could not connect to InfluxDB at #{host}:#{port}" unless wait_for_socket(host, port)
IO.popen(%W(influxdb/bin/influx -host #{host} -port #{port}), 'w') do |influx|
influx.puts "CREATE DATABASE #{DATABASE} WITH duration 1d REPLICATION 1;"
end
if !$?.success?
abort "#$0: failed to create InfluxDB database #{DATABASE}"
end
env = {
'INFLUX_HOST' => "#{host}",
'INFLUX_PORT' => "#{port}",
'INFLUX_USER' => "",
'INFLUX_PASSWORD' => "",
'INFLUX_DATABASE' => "#{DATABASE}",
}
if !system(env, *%W(bundle exec rake), chdir: 'influxdb/influxdb-management')
abort "#$0: failed to run influxdb-managemant Rake script"
end
ensure
Process.kill('TERM', foreman_pid)
end
exit success
if ARGV.count != 1
abort "Usage: #$0 INFLUXDB_HTTP_PORT"
end
port = ARGV.shift
main(HOST, port)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment