diaspora-prosody-config 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51d3827fb7cb49b8541a26121c7815643aa0e89e
4
- data.tar.gz: a0ceb0f04f825c91eeab6d0c47c4e130bcf2b285
3
+ metadata.gz: b407a1828f500d4286581d984e8087a60316346c
4
+ data.tar.gz: 363ee05249238782d2585bba1854b564611b5fa8
5
5
  SHA512:
6
- metadata.gz: bf3edcf393680f1d7a95730ce453ce711f3d7b9021951e7504e968382402aea6546e47615da393959d81905d919c134f7cfdfac0ac77055fc046b9fe8e5215c7
7
- data.tar.gz: da2540715ad90b2124d04efc42cf7883e3d624d32102e96c429e52740bc39eb55dac6bd830d8236ef9317ff8d013808235ef847c99eade8669d06f0bc2b2c506
6
+ metadata.gz: 46678b6750009021721d722db8f5023cc56eac72bc3e76364a633bd7ad1eb96dd07a7ba1779649b6e5c2ff134beaec701a5fbec49bbd87633f35de3131f5143b
7
+ data.tar.gz: 86ac1a3c7252342388e9afdd312c1fc9b761b46d95b6f95ccb2acb9019f4fa3c2b963b7d1e0e49a7687117cce805b3f27943c6716131f8eca115abc2ebac29c2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- diaspora-prosody-config (0.0.5)
4
+ diaspora-prosody-config (0.0.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Diaspora Prosody Config Wrapper
2
+
3
+ [![Build Status](https://travis-ci.org/Zauberstuhl/gem_diaspora-prosody-config.svg?branch=master)](https://travis-ci.org/Zauberstuhl/gem_diaspora-prosody-config)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'diaspora-prosody-config'
3
- s.version = '0.0.5'
3
+ s.version = '0.0.6'
4
4
  s.summary = 'Diaspora Configuration Wrapper For Prosodoy'
5
5
  s.description = 'This gem maps configuration options from Diaspora to Prosody.'
6
6
  s.license = 'GPL-3.0'
@@ -17,17 +17,29 @@
17
17
  #
18
18
 
19
19
  require 'fileutils'
20
+ require 'digest/md5'
20
21
 
21
22
  module Prosody
22
- GEMDIR = Gem::Specification.find_by_name(
23
- 'diaspora-prosody-config'
24
- ).gem_dir.freeze
25
-
23
+ NAME = 'diaspora-prosody-config'.freeze
24
+ GEMDIR = Gem::Specification.find_by_name(NAME).gem_dir.freeze
26
25
  WRAPPERCFG = "#{GEMDIR}/etc/prosody.cfg.lua".freeze
27
26
  DIASPORACFG = "#{FileUtils.pwd}/config/prosody.cfg.lua".freeze
28
27
 
28
+ # Catch signal interrupt
29
+ # for a clean shutdown
30
+ Signal.trap("TERM") {
31
+ shutdown
32
+ exit
33
+ }
34
+
29
35
  def self.start
30
- check_sanity.nil? && system("#{find_binary} --config #{WRAPPERCFG}")
36
+ if check_sanity.nil?
37
+ @prosody_pid = Process.spawn("#{find_binary} --config #{WRAPPERCFG}")
38
+ # Prosody was forked into background
39
+ # Let's wait till the Wrapper
40
+ # will be killed or prosody itself
41
+ Process.waitpid(@prosody_pid)
42
+ end
31
43
  end
32
44
 
33
45
  def self.update_configuration(opts = {})
@@ -42,6 +54,8 @@ module Prosody
42
54
  config.gsub!(/\#\{#{k}\}/, "#{v}")
43
55
  end
44
56
  File.open(WRAPPERCFG, 'w') {|f| f.write(config) }
57
+ # check if prosody is available
58
+ check_sanity
45
59
  end
46
60
 
47
61
  def self.find_binary
@@ -49,23 +63,56 @@ module Prosody
49
63
  prosodybin = "#{p}/prosody"
50
64
  return prosodybin if File.exist?(prosodybin)
51
65
  end
52
- abort('Prosody executable is missing please update your PATH variable')
66
+ abort <<-eos
67
+ FATAL:
68
+ *****************************************************************
69
+ #{NAME} wasn't able to find your prosody binary.
70
+ Have you installed prosody (http://prosody.im/download/start)?
71
+
72
+ If you run Prosody or any other XMPP server by yourself you can
73
+ disable #{NAME} by editing your diaspora.yml:
74
+ configuration:
75
+ chat:
76
+ server:
77
+ enabled: false
78
+ *****************************************************************
79
+ eos
53
80
  end
54
81
 
55
82
  def self.check_sanity
83
+ # check if configuration is matching
84
+ usrcfg = Digest::MD5.hexdigest(File.read(DIASPORACFG))
85
+ gemcfg = Digest::MD5.hexdigest(File.read("#{WRAPPERCFG}.tpl"))
86
+ unless usrcfg.eql?(gemcfg)
87
+ abort <<-eos
88
+ FATAL:
89
+ *****************************************************************
90
+
91
+ #{usrcfg} != #{gemcfg}
92
+
93
+ You modified #{DIASPORACFG}
94
+ Please run:
95
+ rails runner config/initializers/prosody.rb
96
+
97
+ Otherwise your configuration changes will not take effect!
98
+ *****************************************************************
99
+ eos
100
+ end
56
101
  # check on bcrypt and warn
57
102
  bcrypt_so = %x(find /usr/local/lib -name bcrypt.so) rescue ''
58
- warn('bcrypt is required for diaspora authentication') if bcrypt_so.empty?
103
+ if bcrypt_so.empty?
104
+ warn("#{NAME}: bcrypt is required for diaspora authentication")
105
+ end
59
106
  # check prosody version
60
- about = %x(#{find_binary}ctl about)
107
+ about = %x(#{find_binary}ctl --config #{WRAPPERCFG} about)
61
108
  version_string = begin
62
109
  about.match(/prosody\s(\d+\.\d+\.\d+)/i).captures[0]
63
110
  rescue
64
- abort('something went wrong with prosdoyctl')
111
+ abort "#{NAME}: #{about}"
65
112
  end
66
113
  version = Gem::Version.new(version_string)
67
114
  if version < Gem::Version.new('0.9.0')
68
- abort('your\'re prosody version should be >= 0.9.0')
115
+ abort "#{NAME}: Your're prosody version should be >= 0.9.0"
69
116
  end
70
117
  end
71
118
 
@@ -91,5 +138,11 @@ module Prosody
91
138
  opts
92
139
  end
93
140
 
94
- private_class_method :find_binary, :check_sanity, :config_params
141
+ def self.shutdown
142
+ unless @prosody_pid.nil?
143
+ Process.kill(9, @prosody_pid)
144
+ end
145
+ end
146
+
147
+ private_class_method :find_binary, :check_sanity, :config_params, :shutdown
95
148
  end
data/test/lib_dpc_test.rb CHANGED
@@ -12,6 +12,7 @@ describe Prosody do
12
12
  end
13
13
 
14
14
  def test_dpc
15
- assert_equal true, Prosody.start
15
+ pid = Prosody.start
16
+ assert pid > 0, msg = "Prosody wasn't forked correctly"
16
17
  end
17
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diaspora-prosody-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Matt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-05 00:00:00.000000000 Z
11
+ date: 2016-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pronto
@@ -92,6 +92,7 @@ files:
92
92
  - Gemfile
93
93
  - Gemfile.lock
94
94
  - LICENSE
95
+ - README.md
95
96
  - Rakefile
96
97
  - diaspora-prosody-config.gemspec
97
98
  - etc/prosody.cfg.lua.tpl