forked from nsip/nias
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch_nias.rb
executable file
·123 lines (72 loc) · 2.35 KB
/
launch_nias.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
#!/usr/bin/env ruby
require 'fileutils'
puts "\n\nStarting in: #{__dir__}\n\n"
def banner( text )
puts "\n\n********************************************************"
puts "**"
puts "** #{text}"
puts "**"
puts "**"
puts "********************************************************\n\n"
end
@pids = {}
@core_pid_file = 'core.pid'
@pid_file = 'nias.pid'
# check core pid file exists, if not core probably not running
if !File.exist?( @core_pid_file )
banner 'No core.pid file found, likely core not running, run lauch_core.rb before launch.nias'
exit 130
end
def launch
# just in case an old one gets left behind, delete on startup
File.delete( @pid_file ) if File.exist?( @pid_file )
banner 'Starting NIAS SSF services'
ssf_services = [
{:name => 'cons-prod-privacyfilter.rb', :options => ''},
{:name =>'cons-prod-sif-ingest-validate.rb', :options => ''}
]
ssf_services.each_with_index do | service, i |
@pids["#{service}:#{i}"] = Process.spawn( 'ruby', "#{__dir__}/ssf/services/#{service[:name]}", service[:options] )
end
banner 'Starting NIAS SMS services'
sms_services = [
'cons-prod-sif-parser.rb',
'cons-sms-indexer.rb',
'cons-sms-storage.rb',
'cons-oneroster-sms-storage.rb',
'cons-prod-oneroster-parser.rb',
'cons-prod-sif2scv-studentpersonal-naplanreg-parser.rb'
# 'cons-prod-csv2sif-studentpersonal-naplanreg-parser.rb'
]
sms_services.each_with_index do | service, i |
@pids["#{service}:#{i}"] = Process.spawn( 'ruby', "#{__dir__}/sms/services/#{service}" )
end
# write pids to file for shutdown
File.open(@pid_file, 'w') {|f|
@pids.each do | _, pid |
f.puts pid
end
}
banner "pid file written to #{@pid_file}"
end
def shut_down
banner "\n NIAS 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 NIAS services shut down"
end
if ARGV[0] == '-K' then
shut_down
exit 130
else
launch
exit 130
end