omf_rc_shm 0.1.15 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTJmMDM5Mjk2NjQ0YmYxNDViNjliYjA0OTA4MDc4OTZkNDRkMTFlZg==
4
+ MGFmMDYyMWEyZGU3ZmQ4NzRiYjFjYzBhOTdkNTRmMjQ3YWEwYjZjOQ==
5
5
  data.tar.gz: !binary |-
6
- ZjMxN2E3YmJlY2UwZDhiYjc3Y2IxMTNhYTkyNTNkMDQ2ODQyMjdlNA==
6
+ M2Y1ZTBmMzNkMmE5NmRiMzY4Y2VmNTZkYzNkMGEzNzBlNWFlMjBiOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NWFhMmVhMTJkZjBjODY4YmFkZWMzMTQ0ZDI1NTg1NTQxODYzMGI3NTVjMmRh
10
- ODBjODQxMzlkMWI4OTI0MTRkMGEyMTRhNjI4YTNhNGE5NGUyN2VmODY0MDk3
11
- Yjc0ODc1ZGZkNDI5Yjk2NTQ4ZDI5NTUyNjhlYzU3MWRkZDhjNjg=
9
+ MWZmYTAwMjE4M2U3NjEzM2EwN2YyYTQ3ZDEyNGUwZDY2MTJhNmZmNzVkYTNj
10
+ NGJhYWE2MGVlOTljZTY4YzFlNzBmNmE3ZDBjY2NkYWZmNDdjYWUyY2NjM2Rh
11
+ MTY0ZDkzNjY1NjUzMGM5NmNiNTc3NGQ4NjBiOWM5NTA5M2VmNDE=
12
12
  data.tar.gz: !binary |-
13
- OTk3MDg3MDcyN2RmM2Q1N2M3OGEyZDdhMjNjMjg5YjY1ZWNjYzcyMzcwZGJh
14
- ZGMxZGYxODRlNzMzYzg1NjZjNDA0ZWM4M2ZmMjI2Y2I4ZTdhYTk3YTIzODhh
15
- NWRjNGM1ZTFlNDhmMzU5YjA4ZTJkMjViNjFhNzE5OTJhMzkxZDM=
13
+ NmU1NDdhOGU2MTAyM2YwODkxMTEzYmE4MjYyYzQ4ZjAyNDY5MDFjMTYwZjY0
14
+ ODZkZWUxMjJjYjBhNzRlNTgwOGQ4ZTk1OWUyNDNiOTI5MzdiNDU5MTJmNGI0
15
+ MzgxNDA1ZTRiMDI1Yzc2ODJjNDI2ZDIyMDg3YTczZGQxYzUyYmE=
data/config/config.yml CHANGED
@@ -2,8 +2,9 @@
2
2
  ---
3
3
  # URI to the communication system
4
4
  # - local://local for no oustide communication
5
+ # - amqp://my.amqp.server.com to use AMQP communication
5
6
  # - xmpp://user:password@some.xmpp.server to use XMPP communication via
6
- # some.xmpp.server, using the specified user and password
7
+ # some.xmpp.server, using the specified user and password
7
8
  :uri: local://local
8
9
  :environment: production
9
10
  :debug: false
@@ -13,7 +14,8 @@
13
14
  # ID to give to this SHM node
14
15
  # by default construct 'node1234' ID based on IP address of the br0 interface
15
16
  # as requested by the SHM team
16
- :uid: '<%= ip = `ifconfig br0`.match(/inet addr:(\d*\.\d*\.\d*\.\d*)/)[1].split('.') ; (ip[2].to_i*256+ip[3].to_i).to_s.rjust(5,'0') %>'
17
+ #:uid: '<%= ip = `ifconfig br0`.match(/inet addr:(\d*\.\d*\.\d*\.\d*)/)[1].split('.') ; (ip[2].to_i*256+ip[3].to_i).to_s.rjust(5,'0') %>'
18
+ :uid: '<%= mac = `/sbin/ifconfig br0`.match(/HWaddr (\h*\:\h*\:\h*\:\h*:\h*:\h*)/)[1].split(':') ; (mac[4]+mac[5]).hex.to_s.rjust(5,'0') %>'
17
19
  # Path to the file with the default application schedule
18
20
  :app_definition_file: /etc/omf_rc/scheduled_app.rb
19
21
  # Path to find the Ruby binary
@@ -21,9 +23,20 @@
21
23
  # The top-up value in second for the watchdog timer (must be lower than timeout value)
22
24
  # Comment that line to disable the watchdog timer
23
25
  :watchdog_timer: 15
26
+ # Ensure local time is synced with NTP time before doing anything else.
27
+ # Local time is considered synced if it is within 'time_sync_maxdrift' second drift of NTP time.
28
+ # It will try 'time_sync_tries' times to do time sync using the command 'time_sync_cmd'.
29
+ # Each failed sync attempt will trigger a random sleep up to 'time_sync_interval' second before the next attempt.
30
+ :time_sync_tries: 20
31
+ :time_sync_maxdrift: 600
32
+ :time_sync_interval: 20
33
+ :time_sync_cmd: "/usr/bin/ntpdate -b -t 10 -u au.pool.ntp.org"
24
34
 
25
35
  :add_default_factories: false # Not loading default type factories
26
36
 
27
37
  :factories: # Additional resources which can be created by this RC
28
- - :require: omf_rc_shm
29
-
38
+ load: [
39
+ 'omf_rc_shm',
40
+ 'omf_rc/resource_proxy/scheduled_application',
41
+ 'omf_rc/resource_proxy/application'
42
+ ]
@@ -7,6 +7,10 @@ module OmfRc::ResourceProxy::ShmNode
7
7
  property :oml_uri
8
8
  property :ruby_path
9
9
  property :watchdog_timer, :default => nil
10
+ property :time_sync_tries, :default => nil
11
+ property :time_sync_maxdrift, :default => 600
12
+ property :time_sync_interval, :default => 20
13
+ property :time_sync_cmd, :default => "/usr/bin/ntpdate -b -t 10 -u au.pool.ntp.org"
10
14
 
11
15
  request :cron_jobs do |node|
12
16
  node.children.find_all { |v| v.type =~ /scheduled_application/ }.map do |v|
@@ -15,6 +19,35 @@ module OmfRc::ResourceProxy::ShmNode
15
19
  end
16
20
 
17
21
  hook :after_initial_configured do |node|
22
+ # 1) Do not continue unless we have some 'ok' time sync!
23
+ unless node.property.time_sync_tries.nil?
24
+ require 'net/ntp'
25
+ info "Option 'time_sync_tries' is set. Continue only if local time is accurate, will try to sync #{node.property.time_sync_tries} times with random wait of up to #{node.property.time_sync_interval}s."
26
+ (1..node.property.time_sync_tries.to_i).each do |i|
27
+ dt = node.property.time_sync_maxdrift.to_i
28
+ lt = 0
29
+ rt = 0
30
+ begin
31
+ lt = Time.now ; rt = Net::NTP.get.time ; dt = (lt-rt).abs
32
+ rescue Exception => e
33
+ info "Time sync try #{i} - Cannot contact NTP server (#{e})"
34
+ end
35
+ if dt > node.property.time_sync_maxdrift.to_i
36
+ info "Time sync try #{i} - Local: #{lt.to_i} - NTP: #{rt.to_i} - Diff: #{dt} - (sync: #{node.property.time_sync_cmd.to_s})"
37
+ res = `#{node.property.time_sync_cmd.to_s}`
38
+ else
39
+ break
40
+ end
41
+ sleep(rand(node.property.time_sync_interval.to_i))
42
+ end
43
+ lt = Time.now ; rt = Net::NTP.get.time ; dt = (lt-rt).abs
44
+ if dt > node.property.time_sync_maxdrift.to_i
45
+ info "Time sync FAILED! EXITING NOW!"
46
+ exit
47
+ end
48
+ info "Time sync OK - Local: #{lt.to_i} - NTP: #{rt.to_i} - Diff: #{dt}"
49
+ end
50
+ # 2) if present, load and set default app schedule
18
51
  unless node.request_app_definition_file.nil?
19
52
  OmfRcShm.app.load_definition(node.request_app_definition_file)
20
53
  info "Loaded scheduled app definition from '#{node.request_app_definition_file}'"
@@ -27,7 +60,7 @@ module OmfRc::ResourceProxy::ShmNode
27
60
  OmfCommon.el.after(5) { s_app.configure_state(:scheduled) }
28
61
  end
29
62
  end
30
- # if required, start the watchdog timer and periodically top it
63
+ # 3) if required, start the watchdog timer and periodically top it
31
64
  unless node.property.watchdog_timer.nil?
32
65
  info "Watchdog Timer started with interval: #{node.property.watchdog_timer}"
33
66
  OmfRcShm.app.watchdog = File.open('/dev/watchdog', 'w')
@@ -36,6 +69,8 @@ module OmfRc::ResourceProxy::ShmNode
36
69
  OmfRcShm.app.watchdog.flush
37
70
  end
38
71
  end
72
+ # 4) Finally display our SHM Node ID:
73
+ info "SHM Node ID: #{node.uid}"
39
74
  end
40
75
 
41
76
  hook :before_ready do
@@ -1,3 +1,3 @@
1
1
  module OmfRcShm
2
- VERSION = "0.1.15"
2
+ VERSION = "0.1.17"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omf_rc_shm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - NICTA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-11 00:00:00.000000000 Z
11
+ date: 2014-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler