jerbil 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. data/Bugs.rdoc +66 -0
  2. data/Gemfile +12 -0
  3. data/History.txt +359 -0
  4. data/Intro.txt +5 -0
  5. data/LICENCE.rdoc +159 -0
  6. data/README.md +335 -0
  7. data/README_SERVICES.md +410 -0
  8. data/README_TESTING.md +47 -0
  9. data/bin/jerbil +62 -0
  10. data/bin/jerbil-install +56 -0
  11. data/etc/conf.d/jerbild +15 -0
  12. data/etc/conf.d/jserviced +39 -0
  13. data/etc/init.d/jerbild +55 -0
  14. data/etc/init.d/jserviced +59 -0
  15. data/etc/jerbil/jerbil-client.rb +2 -0
  16. data/etc/jerbil/jerbil.rb +83 -0
  17. data/lib/jerbil.rb +636 -0
  18. data/lib/jerbil/config.md +49 -0
  19. data/lib/jerbil/config.rb +67 -0
  20. data/lib/jerbil/errors.rb +74 -0
  21. data/lib/jerbil/jerbil_service/base.rb +191 -0
  22. data/lib/jerbil/jerbil_service/client.rb +325 -0
  23. data/lib/jerbil/jerbil_service/config.md +119 -0
  24. data/lib/jerbil/jerbil_service/config.rb +72 -0
  25. data/lib/jerbil/jerbil_service/sclient.rb +343 -0
  26. data/lib/jerbil/jerbil_service/support.rb +58 -0
  27. data/lib/jerbil/jerbil_service/utils.rb +35 -0
  28. data/lib/jerbil/servers.rb +230 -0
  29. data/lib/jerbil/service.rb +216 -0
  30. data/lib/jerbil/support.rb +160 -0
  31. data/lib/jerbil/thor/server.rb +76 -0
  32. data/lib/jerbil/thor/service.rb +74 -0
  33. data/lib/jerbil/version.rb +13 -0
  34. data/sbin/jerbil-status +120 -0
  35. data/sbin/jerbil-stop +139 -0
  36. data/sbin/jerbild +186 -0
  37. data/sbin/jservice-status +107 -0
  38. data/sbin/jservice-stop +94 -0
  39. data/sbin/jserviced +111 -0
  40. data/spec/jerbil_2_jerbil_spec.rb +87 -0
  41. data/spec/jerbil_client1_spec.rb +80 -0
  42. data/spec/jerbil_client_spec.rb +114 -0
  43. data/spec/jerbil_client_stop_spec.rb +24 -0
  44. data/spec/jerbil_daemonised/jerbil_local_spec.rb +81 -0
  45. data/spec/jerbil_daemonised/jerbil_remote_spec.rb +116 -0
  46. data/spec/jerbil_load.rb +48 -0
  47. data/spec/jerbil_local_spec.rb +91 -0
  48. data/spec/jerbil_missing_spec.rb +98 -0
  49. data/spec/jerbil_remote_spec.rb +117 -0
  50. data/spec/jerbil_remote_spec_bup.rb +168 -0
  51. data/spec/jerbil_service_error_spec.rb +56 -0
  52. data/spec/jerbil_service_spec.rb +41 -0
  53. data/spec/jerbil_support_spec.rb +69 -0
  54. data/spec/jservice_utils_spec.rb +38 -0
  55. data/spec/server_spec.rb +69 -0
  56. data/spec/server_update_spec.rb +28 -0
  57. data/spec/service_spec.rb +72 -0
  58. data/spec/spec_helper.rb +12 -0
  59. data/spec/test_env_spec.rb +53 -0
  60. data/test/bad_test_service.rb +31 -0
  61. data/test/conf.d/jerbil +36 -0
  62. data/test/conf.d/jerbil.conf +39 -0
  63. data/test/conf.d/jerbil.rb +55 -0
  64. data/test/conf.d/jerbil_local.rb +33 -0
  65. data/test/conf.d/jerbil_no_local.conf +39 -0
  66. data/test/conf.d/jerbil_old.rb +47 -0
  67. data/test/conf.d/jerbil_test.rb +35 -0
  68. data/test/conf.d/malformed +1 -0
  69. data/test/conf.d/missing_services +39 -0
  70. data/test/conf.d/ruby_test.rb +8 -0
  71. data/test/init.d/jerbild +14 -0
  72. data/test/jerbil.rb +51 -0
  73. data/test/jerbil_config.rb +8 -0
  74. data/test/jstop.rb +36 -0
  75. data/test/key.asc +1 -0
  76. data/test/lib/ruby_test.rb +37 -0
  77. data/test/lib/ruby_test/config.rb +56 -0
  78. data/test/lib/ruby_test/version.rb +13 -0
  79. data/test/pids/jerbil-prod.asc +1 -0
  80. data/test/pids/jerbil-prod.pid +1 -0
  81. data/test/pids/jerbil.pid +1 -0
  82. data/test/private_key_file.asc +3 -0
  83. data/test/service-stop.rb +86 -0
  84. data/test/service_mock.rb +94 -0
  85. data/test/test_service_client.rb +25 -0
  86. metadata +265 -0
@@ -0,0 +1,56 @@
1
+ #
2
+ # Description
3
+ #
4
+ # Author:: Robert Sharp
5
+ # Copyright:: Copyright (c) 2010 Robert Sharp
6
+ # License:: Open Software Licence v3.0
7
+ #
8
+ # This software is licensed for use under the Open Software Licence v. 3.0
9
+ # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
10
+ # and in the file copyright.txt. Under the terms of this licence, all derivative works
11
+ # must themselves be licensed under the Open Software Licence v. 3.0
12
+ #
13
+ #
14
+
15
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
16
+ require 'jerbil/errors'
17
+ require 'jerbil/jerbil_service/base'
18
+ require 'jerbil'
19
+ require File.expand_path(File.dirname(__FILE__) + '/../test/test_service')
20
+ require 'socket'
21
+
22
+ config_dir = File.expand_path(File.dirname(__FILE__) + '/../test/conf.d/')
23
+ tconfig = File.expand_path(File.dirname(__FILE__) + '/../test/conf.d/test')
24
+
25
+ describe "Test Service Class for Errors (No Jerbil)" do
26
+
27
+ before(:each) do
28
+ @pkey = "ABCDEF"
29
+ jerbil_test = get_test_jerbil
30
+ Jerbil.stub(:get_local_server).and_return(jerbil_test)
31
+
32
+ end
33
+
34
+
35
+ it "should raise error on bad service name" do
36
+ require File.expand_path(File.dirname(__FILE__) + '/../test/bad_test_service')
37
+ jconfig = config_dir + '/jerbil'
38
+ options = {:log_dir => "/home/robert/dev/projects/jerbil/log", :log_level => :debug, :jerbil_config=>jconfig, :exit_on_stop=>false}
39
+ lambda{BadTestService.new(@pkey, options)}.should raise_error(Jerbil::InvalidService)
40
+ end
41
+
42
+ it "should raise error for no Jerbil Server" do
43
+ jconfig = config_dir + '/jerbil'
44
+ options = {:log_dir => "/home/robert/dev/projects/jerbil/log", :log_level => :debug, :jerbil_config=>jconfig, :exit_on_stop=>false}
45
+ Jerbil.unstub(:get_local_server)
46
+ lambda{TestService.new(@pkey, options)}.should raise_error(Jerbil::ServerConnectError)
47
+ end
48
+
49
+
50
+ end
51
+
52
+ def get_test_jerbil
53
+ config_file = File.expand_path(File.dirname(__FILE__) + '/../test/conf.d/jerbil.conf')
54
+ config = Jerbil.get_config(config_file)
55
+ return Jerbil.get_local_server(config)
56
+ end
@@ -0,0 +1,41 @@
1
+ #
2
+ # Description
3
+ #
4
+ # Author:: Robert Sharp
5
+ # Copyright:: Copyright (c) 2010 Robert Sharp
6
+ # License:: Open Software Licence v3.0
7
+ #
8
+ # This software is licensed for use under the Open Software Licence v. 3.0
9
+ # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
10
+ # and in the file copyright.txt. Under the terms of this licence, all derivative works
11
+ # must themselves be licensed under the Open Software Licence v. 3.0
12
+ #
13
+ #
14
+
15
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
16
+ require 'jerbil/jerbil_service/base'
17
+ require 'jerbil'
18
+ require File.expand_path(File.dirname(__FILE__) + '/../test/test_service')
19
+
20
+
21
+ describe "Test Service Class" do
22
+
23
+
24
+
25
+ it "should start and stop OK" do
26
+ pkey = "ABCDEF"
27
+ jerbil_test = get_test_jerbil
28
+ Jerbil.stub(:get_local_server).and_return(jerbil_test)
29
+ tservice = TestService.new(pkey, :log_dir => "/home/robert/dev/projects/jerbil/log", :log_level => :debug, :exit_on_stop=>false)
30
+ tservice.action.should == "Hello"
31
+ tservice.stop_callback(pkey) # make sure you do not kill anything
32
+ end
33
+
34
+
35
+ end
36
+
37
+ def get_test_jerbil
38
+ config_file = File.expand_path(File.dirname(__FILE__) + '/../test/conf.d/jerbil.conf')
39
+ config = Jerbil.get_config(config_file)
40
+ return Jerbil.get_local_server(config)
41
+ end
@@ -0,0 +1,69 @@
1
+ #
2
+ # Description
3
+ #
4
+ # Author:: Robert Sharp
5
+ # Copyright:: Copyright (c) 2010 Robert Sharp
6
+ # License:: Open Software Licence v3.0
7
+ #
8
+ # This software is licensed for use under the Open Software Licence v. 3.0
9
+ # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
10
+ # and in the file copyright.txt. Under the terms of this licence, all derivative works
11
+ # must themselves be licensed under the Open Software Licence v. 3.0
12
+ #
13
+ #
14
+
15
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
16
+ require 'jerbil/server'
17
+ require 'jerbil'
18
+ require 'jellog'
19
+ require 'socket'
20
+
21
+ Jellog.disable_syslog
22
+ config_dir = File.expand_path(File.dirname(__FILE__) + '/../test/conf.d/')
23
+ config_file = config_dir + '/jerbil.conf'
24
+
25
+ describe "Jerbil Support" do
26
+
27
+ it "should return a server from the config file" do
28
+ germ_fqdn = 'germanicus.osburn-sharp.ath.cx'
29
+ config = Jerbil.get_config(config_file)
30
+ germ = Jerbil.get_server(germ_fqdn, config)
31
+ germ.fqdn.should == germ_fqdn
32
+ end
33
+
34
+ it "should return this server from the config file" do
35
+ me = Socket.gethostname
36
+ config = Jerbil.get_config(config_file)
37
+ lucius = Jerbil.get_local_server(config)
38
+ lucius.fqdn.should == me
39
+ end
40
+
41
+ it "should not find a server with the wrong env" do
42
+ config = Jerbil.get_config(config_file)
43
+ config[:environment] = :prod
44
+ lambda{Jerbil.get_local_server(config)}.should raise_error(Jerbil::MissingServer)
45
+ end
46
+
47
+ it "should not find a server that is not there" do
48
+ config = Jerbil.get_config(config_file)
49
+ lambda{Jerbil.get_server('theimprobableone',config)}.should raise_error(Jerbil::MissingServer)
50
+ end
51
+
52
+ it "should not find a local server that is not there" do
53
+ no_local_config = config_dir + '/jerbil_no_local.conf'
54
+ config = Jerbil.get_config(no_local_config)
55
+ lambda{Jerbil.get_server('theimprobableone',config)}.should raise_error(Jerbil::MissingServer)
56
+ end
57
+
58
+ it "should not like a missing config file" do
59
+ lambda{Jerbil.get_config('config_file_is_missing')}.should raise_error(Jerbil::JerbilConfigError)
60
+ end
61
+
62
+ it "should default to the current system config" do
63
+ me = Socket.gethostname
64
+ lucius = Jerbil.get_local_server()
65
+ lucius.fqdn.should == me
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,38 @@
1
+ #
2
+ # Description
3
+ #
4
+ # Author:: Robert Sharp
5
+ # Copyright:: Copyright (c) 2010 Robert Sharp
6
+ # License:: Open Software Licence v3.0
7
+ #
8
+ # This software is licensed for use under the Open Software Licence v. 3.0
9
+ # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
10
+ # and in the file copyright.txt. Under the terms of this licence, all derivative works
11
+ # must themselves be licensed under the Open Software Licence v. 3.0
12
+ #
13
+ #
14
+
15
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
16
+ require 'jerbil/jerbil_service/utils'
17
+ require 'jerbil/chuser'
18
+
19
+
20
+ describe "utils" do
21
+
22
+ it "should classify a string" do
23
+ JerbilService::Utils.classify('robert_sharp').should == "RobertSharp"
24
+ JerbilService::Utils.classify('robert/sharp').should == "Robert::Sharp"
25
+ end
26
+
27
+ it "should change a user id etc" do
28
+ Process.should_receive(:uid).and_return(0)
29
+ Process::Sys.should_receive(:setuid).once.and_return(true)
30
+ Process::Sys.should_receive(:setgid).once.and_return(true)
31
+ Jerbil::Chuser.change('jermine').should be_true
32
+ end
33
+
34
+ it "should change a user id for real if run as su" do
35
+ Jerbil::Chuser.change('jermine').should be_true
36
+ end
37
+
38
+ end
@@ -0,0 +1,69 @@
1
+ #
2
+ # Description
3
+ #
4
+ # Author:: Robert Sharp
5
+ # Copyright:: Copyright (c) 2010 Robert Sharp
6
+ # License:: Open Software Licence v3.0
7
+ #
8
+ # This software is licensed for use under the Open Software Licence v. 3.0
9
+ # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
10
+ # and in the file copyright.txt. Under the terms of this licence, all derivative works
11
+ # must themselves be licensed under the Open Software Licence v. 3.0
12
+ #
13
+ #
14
+
15
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
16
+ require 'jerbil/servers'
17
+ require 'jerbil/errors'
18
+ require 'socket'
19
+
20
+ key_file = File.expand_path(File.dirname(__FILE__) + '/../test/private_key_file.asc')
21
+ my_key = File.readlines(key_file).join('')
22
+ conf_file = File.expand_path(File.dirname(__FILE__) + '/../test/conf.d/jerbil_local.rb')
23
+
24
+ describe "Jerbil Server Record" do
25
+
26
+ before(:all) do
27
+ @hostname = Socket.gethostname
28
+ @jport = Socket.getservbyname('jerbil') + 2
29
+ @pkey = "ABCDEFG"
30
+ @my_conf = Jerbil::Config.new(conf_file)
31
+ #puts my_conf.inspect
32
+ @my_session = Jerbil::Broker.new(@my_conf, @pkey)
33
+
34
+ @my_server = Jerbil::Servers.get_local_server(@my_conf[:environment])
35
+ DRb.start_service(@my_server.drb_address, @my_session)
36
+ end
37
+
38
+ after(:all) do
39
+ #@my_session.stop(@pkey) should be stopped anyway
40
+ end
41
+
42
+ it "should create a server object" do
43
+ @my_server.fqdn.should == Socket.gethostname
44
+ @my_server.ident.should == "#{@hostname}[:#{@my_conf[:environment]}]"
45
+ end
46
+
47
+ it "should connect to its server (WHEN ACTIVE)" do
48
+ jserver = @my_server.connect
49
+ jserver.verify.should be_true
50
+ end
51
+
52
+ it "should fail to stop the server with the wrong key" do
53
+ jserver = @my_server.connect
54
+ lambda{jserver.stop('123456')}.should raise_error(Jerbil::InvalidPrivateKey)
55
+ end
56
+
57
+ it "should stop the server with the correct key" do
58
+ jserver = @my_server.connect
59
+ lambda{jserver.stop(@pkey)}.should_not raise_error
60
+ #lambda{jserver.verify}.should raise_error
61
+ end
62
+
63
+
64
+ it "should find all running servers on the system" do
65
+ servers = Jerbil::Servers.find_servers(@my_conf[:environment], @my_conf[:net_address], @my_conf[:net_mask])
66
+ servers.each {|s| puts s.fqdn}
67
+ end
68
+
69
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ #require 'rspec/mocks/standalone'
3
+ require 'jerbil/server'
4
+ require 'jerbil/errors'
5
+ require 'socket'
6
+
7
+ key_file = File.expand_path(File.dirname(__FILE__) + '/../test/private_key_file.asc')
8
+ my_key = File.readlines(key_file).join('')
9
+
10
+ describe "Jerbil Server Record" do
11
+
12
+ before(:all) do
13
+ end
14
+
15
+ it "should find all running servers on the system" do
16
+ myserv = double("Jerbil::ServerRecord")
17
+ Jerbil::ServerRecord.stub(:new).and_return(myserv)
18
+ myserv.should_receive(:get_key).exactly(5).times.and_return(true)
19
+ myserv.should_receive(:fqdn).and_return("germanicus.osburn-sharp.ath.cx",
20
+ "lucius.osburn-sharp.ath.cx",
21
+ "antonia.osburn-sharp.ath.cx",
22
+ "valeria.osburn-sharp.ath.cx",
23
+ "aurelius.osburn-sharp.ath.cx")
24
+ servers = Jerbil::ServerRecord.find_servers(:prod, 0.1)
25
+ servers.each {|s| puts s.fqdn}
26
+ end
27
+
28
+ end
@@ -0,0 +1,72 @@
1
+ #
2
+ # Description
3
+ #
4
+ # Author:: Robert Sharp
5
+ # Copyright:: Copyright (c) 2010 Robert Sharp
6
+ # License:: Open Software Licence v3.0
7
+ #
8
+ # This software is licensed for use under the Open Software Licence v. 3.0
9
+ # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
10
+ # and in the file copyright.txt. Under the terms of this licence, all derivative works
11
+ # must themselves be licensed under the Open Software Licence v. 3.0
12
+ #
13
+ #
14
+
15
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
16
+ require 'jerbil/service'
17
+ require 'socket'
18
+
19
+ describe "Service" do
20
+ it "should create a new service record" do
21
+ service = Jerbil::ServiceRecord.new(:rubytest, :dev)
22
+ service.name.should == :rubytest
23
+ my_address = Socket::gethostname + ':' + (Socket::getservbyname('rubytest') + 2).to_s
24
+ service.address.should == my_address
25
+ service.key.should_not be_nil
26
+ service.local?.should be_true
27
+ end
28
+
29
+ describe "Comparisons" do
30
+ it "should match the service with all parameters" do
31
+ a_service = Jerbil::ServiceRecord.new(:rubytest, :dev)
32
+ my_key = a_service.key
33
+ a_service.matches?(:name=>:rubytest, :env=>:dev, :key=>my_key).should be_true
34
+ end
35
+
36
+ it "should match the service with the same name" do
37
+ a_service = Jerbil::ServiceRecord.new(:rubytest, :dev)
38
+ a_service.matches?(:name=>:rubytest).should be_true
39
+ end
40
+
41
+ it "should match the service with the same env" do
42
+ a_service = Jerbil::ServiceRecord.new(:rubytest, :dev)
43
+ a_service.matches?(:env=>:dev).should be_true
44
+ end
45
+
46
+ it "should match if no arguments are given" do
47
+ a_service = Jerbil::ServiceRecord.new(:rubytest, :dev)
48
+ a_service.matches?.should be_true
49
+ end
50
+
51
+ it "should not not match arguments that are different" do
52
+ a_service = Jerbil::ServiceRecord.new(:rubytest, :dev)
53
+ a_service.matches?(:name=>:hoaxer, :env=>:dev).should be_false
54
+ end
55
+
56
+ end
57
+
58
+ describe "Connections" do
59
+
60
+ before do
61
+ #@service = Jerbil::Service.new(:rubytest, :dev, :verify, :stop)
62
+ #DRbObject.stub(:new).and_return {@service}
63
+ end
64
+
65
+ it "should fail to connect where there is no server" do
66
+ @service = Jerbil::ServiceRecord.new(:rubytest, :dev)
67
+ lambda{@service.connect}.should raise_error(Jerbil::ServiceConnectError)
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ $LOAD_PATH.delete('/usr/local/lib')
4
+ require 'jerbil'
5
+ require 'rspec'
6
+ require 'rspec/autorun'
7
+
8
+ RSpec.configure do |config|
9
+ config.color_enabled = true
10
+ config.formatter = :doc
11
+
12
+ end
@@ -0,0 +1,53 @@
1
+ #
2
+ # Description
3
+ #
4
+ # Author:: Robert Sharp
5
+ # Copyright:: Copyright (c) 2010 Robert Sharp
6
+ # License:: Open Software Licence v3.0
7
+ #
8
+ # This software is licensed for use under the Open Software Licence v. 3.0
9
+ # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
10
+ # and in the file copyright.txt. Under the terms of this licence, all derivative works
11
+ # must themselves be licensed under the Open Software Licence v. 3.0
12
+ #
13
+ #
14
+
15
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
16
+ require 'jerbil/server'
17
+ require 'jerbil/service'
18
+ require 'jerbil/config'
19
+ require 'jerbil'
20
+ require 'socket'
21
+ require 'syslog'
22
+ require 'drb'
23
+ require 'jellog'
24
+
25
+
26
+ config = File.expand_path(File.dirname(__FILE__) + '/../test/conf.d/missing_services')
27
+
28
+ logdir = File.expand_path(File.dirname(__FILE__) + '/../log')
29
+
30
+ describe "This Environment" do
31
+
32
+ it "should have a load path" do
33
+ #puts $LOAD_PATH
34
+ $LOAD_PATH.index('/usr/local/lib').should be_false
35
+ end
36
+
37
+ it "should have the most recent Jellog" do
38
+ require 'jellog/version'
39
+ Jellog::Version.should == "1.0.1"
40
+ Jellog::Logger.respond_to?(:get_options).should be_true
41
+ end
42
+
43
+ it "should produce coloured logs" do
44
+ logger = Jellog::Logger.new("tester", :logdir=>logdir)
45
+ logger.info "This should be here"
46
+ end
47
+
48
+ it "should select log options from a hash" do
49
+ opts = {:logdir=>'/tmp', :my_opts=>true}
50
+ Jellog::Logger.get_options(opts).should == {:logdir=>'/tmp'}
51
+ end
52
+
53
+ end