forked from nsip/nias
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch_core.rb
executable file
·140 lines (93 loc) · 3.42 KB
/
launch_core.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
101
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
#!/usr/bin/env ruby
require 'fileutils'
puts "\n\nStarting in: #{__dir__}\n\n"
# create root node for data files in /tmp
FileUtils.mkdir '/tmp/nias' unless File.directory? '/tmp/nias'
# create storage area for redis - directory needs to pre-exist
FileUtils.mkdir '/tmp/nias/redis' unless File.directory? '/tmp/nias/redis'
# create working area for moneta key-value store - needs to pre-exist
FileUtils.mkdir '/tmp/nias/moneta' unless File.directory? '/tmp/nias/moneta'
def banner( text )
puts "\n\n********************************************************"
puts "**"
puts "** #{text}"
puts "**"
puts "**"
puts "********************************************************\n\n"
end
@pids = {}
@pid_file = 'core.pid'
def launch
# just in case an old one gets left behind, delete on startup
File.delete( @pid_file ) if File.exist?( @pid_file )
# daemonise launched processes
Process.daemon( true, true )
banner 'Starting zookeeper'
@pids['zk'] = Process.spawn( './kafka/bin/zookeeper-server-start.sh', './kafka/config/zookeeper.properties' )
banner 'Waiting for ZK to come up'
sleep 5
banner 'Starting kafka'
@pids['kafka'] = Process.spawn( './kafka/bin/kafka-server-start.sh', './kafka/config/server.properties' )
banner 'Starting SMS Redis'
@pids['sms-redis'] = Process.spawn( 'redis-server', './sms/sms-redis.conf' )
banner 'Starting Web Services'
# @pids['ssf'] = Process.spawn( 'ruby', './ssf/ssf_server.rb', '-e', 'production', '-p', '4567' )
@pids['web'] = Process.spawn( 'rackup' )
banner 'Web services running on localhost:9292/'
banner 'Kafka logs will be created under /tmp/nias/kafka'
banner 'Zookeeper logs will be created under /tmp/nias/zookeeper'
banner 'Redis backups will be created under /tmp/nias/redis'
banner 'SIF Key Value store will be created under /tmp/nias/moneta'
File.open(@pid_file, 'w') {|f|
f.puts "#{@pids['kafka']}"
f.puts "#{@pids['zk']}"
f.puts "#{@pids['sms-redis']}"
f.puts "#{@pids['web']}"
}
banner "pid file written to #{@pid_file}"
banner 'Creating known topics'
topics = [
'sifxml.validated',
'sms.indexer',
'sifxml.ingest',
'sifxml.errors',
'oneroster.validated',
'nsip.test',
'naplan.sifxml',
'naplan.csv',
'test.test1',
'json.test'
]
topics.each do | topic |
pid = Process.spawn( './kafka/bin/kafka-topics.sh',
'--zookeeper localhost:2181',
'--create',
"--topic #{topic}",
'--partitions 1',
'--replication-factor 1')
Process.wait pid
end
banner 'Core topics created.'
banner 'Core NIAS services are up.'
end
def shut_down
banner "\n Core Services shutting down...\n\n"
File.readlines( @pid_file ).each do |line|
begin
Process.kill :INT, line.chomp.to_i
sleep 2
rescue Exception => e
puts e.message
puts e.backtrace.inspect
end
end
File.delete( @pid_file ) if File.exist?( @pid_file )
banner "All core services shut down"
end
if ARGV[0] == '-K' then
shut_down
exit 130
else
launch
exit 130
end