trinidad_init_services 1.1.0.pre3 → 1.1.0

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.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.1.0 (2012-01-04)
2
+
3
+ * Fix bug that didn't allow to create several services with different ids.
4
+ * Allow to provide a configuration file to load the options from.
5
+
1
6
  == 1.1.0.pre (2011-09-30)
2
7
 
3
8
  * Load prunsrv on Windows according with the architecture
data/README CHANGED
@@ -16,6 +16,27 @@ This installer guides you through the configuration process and generates a
16
16
  init.d script if you are on a unix system or creates the service if you are
17
17
  on a windows box.
18
18
 
19
+ You can optionally provide a configuration file to the trinidad_init_service
20
+ command. An example configuration file might look like this:
21
+
22
+ app_path: "/home/myuser/app"
23
+ trinidad_options: "-e production"
24
+ jruby_home: "/opt/jruby"
25
+ ruby_compat_version: RUBY1_8
26
+ trinidad_name: Trinidad
27
+ jsvc_path: "/usr/bin/jsvc"
28
+ java_home: "/opt/java"
29
+ output_path: "/etc/init.d"
30
+ pid_file: "/tmp/trinidad.pid"
31
+ log_file: "/tmp/trinidad.log"
32
+
33
+ You can then run the installer like so:
34
+
35
+ $ jruby -S trinidad_init_service trinidad_init_config.yml
36
+
37
+ If any of the required options are not provided in the configuration file, then the installer will prompt you
38
+ for them.
39
+
19
40
  Unix
20
41
  ====
21
42
 
@@ -1,3 +1,12 @@
1
+ #!/usr/bin/env jruby
2
+
1
3
  require 'trinidad_init_services/configuration'
4
+ require 'yaml'
2
5
 
3
- Trinidad::InitServices::Configuration.new.configure
6
+ if ARGV.size > 0
7
+ config_file = File.read(ARGV[0])
8
+ config = YAML.load(config_file)
9
+ Trinidad::InitServices::Configuration.new.configure(config)
10
+ else
11
+ Trinidad::InitServices::Configuration.new.configure
12
+ end
@@ -19,11 +19,11 @@ module Trinidad
19
19
  @classpath << File.join(@jruby_home, 'lib', 'jruby.jar')
20
20
  end
21
21
 
22
- def collect_windows_opts(options_ask)
22
+ def collect_windows_opts(options_ask, defaults)
23
23
  options_ask << '(separated by `;`)'
24
24
  name_ask = 'Service name? {Alphanumeric and spaces only}'
25
25
  name_default = 'Trinidad'
26
- @trinidad_name = ask(name_ask, name_default)
26
+ @trinidad_name = defaults["trinidad_name"] || ask(name_ask, name_default)
27
27
  end
28
28
 
29
29
  def configure_jruby_opts
@@ -36,29 +36,29 @@ module Trinidad
36
36
  opts
37
37
  end
38
38
 
39
- def configure
40
- @app_path = ask_path('Application path?')
39
+ def configure(defaults={})
40
+ @app_path = defaults["app_path"] || ask_path('Application path?')
41
41
  @trinidad_options = ["-d #{@app_path}"]
42
42
  options_ask = 'Trinidad options?'
43
43
  options_default = '-e production'
44
- collect_windows_opts(options_ask) if windows?
44
+ collect_windows_opts(options_ask, defaults) if windows?
45
45
 
46
- @trinidad_options << ask(options_ask, options_default)
47
- @jruby_home = ask_path('JRuby home?', default_jruby_home)
48
- @ruby_compat_version = ask('Ruby 1.8.x or 1.9.x compatibility?', default_ruby_compat_version)
46
+ @trinidad_options << (defaults["trinidad_options"] || ask(options_ask, options_default))
47
+ @jruby_home = defaults["jruby_home"] || ask_path('JRuby home?', default_jruby_home)
48
+ @ruby_compat_version = defaults["ruby_compat_version"] || ask('Ruby 1.8.x or 1.9.x compatibility?', default_ruby_compat_version)
49
49
  @jruby_opts = configure_jruby_opts
50
50
  initialize_paths
51
51
 
52
- windows? ? configure_windows_service : configure_unix_daemon
52
+ windows? ? configure_windows_service : configure_unix_daemon(defaults)
53
53
  puts 'Done.'
54
54
  end
55
55
 
56
- def configure_unix_daemon
57
- @jsvc = jsvc_path
58
- @java_home = ask_path('Java home?', default_java_home)
59
- @output_path = ask_path('init.d output path?', '/etc/init.d')
60
- @pid_file = ask_path('pid file?', '/var/run/trinidad/trinidad.pid')
61
- @log_file = ask_path('log file?', '/var/log/trinidad/trinidad.log')
56
+ def configure_unix_daemon(defaults)
57
+ @jsvc = defaults["jsvc_path"] || jsvc_path
58
+ @java_home = defaults["java_home"] || ask_path('Java home?', default_java_home)
59
+ @output_path = defaults["output_path"] || ask_path('init.d output path?', '/etc/init.d')
60
+ @pid_file = defaults["pid_file"] || ask_path('pid file?', '/var/run/trinidad/trinidad.pid')
61
+ @log_file = defaults["log_file"] || ask_path('log file?', '/var/log/trinidad/trinidad.log')
62
62
 
63
63
  daemon = ERB.new(
64
64
  File.read(
@@ -77,20 +77,30 @@ module Trinidad
77
77
 
78
78
  def configure_windows_service
79
79
  srv_path = prunsrv_path
80
- command = %Q{//IS//Trinidad --DisplayName="#{@trinidad_name}" \
81
- --Install="#{srv_path}" --Jvm=auto --StartMode=jvm --StopMode=jvm \
80
+ trinidad_service_id = @trinidad_name.gsub(/\W/, '')
81
+
82
+ command = %Q{//IS//#{trinidad_service_id} --DisplayName="#{@trinidad_name}" \
83
+ --Install=#{srv_path} --Jvm=auto --StartMode=jvm --StopMode=jvm \
82
84
  --StartClass=com.msp.procrun.JRubyService --StartMethod=start \
83
- --StartParams="#{@trinidad_daemon_path};#{@trinidad_options.join(";")}" \
84
- --StopClass=com.msp.procrun.JRubyService --StopMethod=stop --Classpath="#{@classpath.join(";")}" \
85
+ --StartParams="#{escape(@trinidad_daemon_path)};#{format_path(@trinidad_options)}" \
86
+ --StopClass=com.msp.procrun.JRubyService --StopMethod=stop --Classpath="#{format_path(@classpath)}" \
85
87
  --StdOutput=auto --StdError=auto \
86
- --LogPrefix="#{@trinidad_name.downcase.gsub(/\W/,'')}" \
87
- ++JvmOptions="#{@jruby_opts.join(";")}"
88
+ --LogPrefix="#{trinidad_service_id.downcase}" \
89
+ ++JvmOptions="#{format_path(@jruby_opts)}"
88
90
  }
89
91
  system "#{srv_path} #{command}"
90
92
  end
91
93
 
92
94
  private
93
95
 
96
+ def escape(path)
97
+ path.gsub(%r{/}, '\\')
98
+ end
99
+
100
+ def format_path(option)
101
+ option.map {|o| escape(o)}.join(';')
102
+ end
103
+
94
104
  def default_jruby_home
95
105
  Java::JavaLang::System.get_property("jruby.home")
96
106
  end
@@ -3,7 +3,7 @@ require 'trinidad'
3
3
 
4
4
  module Trinidad
5
5
  module Daemon
6
- VERSION = '1.1.0.pre3'
6
+ VERSION = '1.1.0'
7
7
 
8
8
  def init
9
9
  end
@@ -0,0 +1,19 @@
1
+ begin
2
+ require 'rspec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'rspec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+
11
+ require 'trinidad_init_services/configuration'
12
+
13
+ require 'java'
14
+ require 'mocha'
15
+ require 'fileutils'
16
+
17
+ RSpec.configure do |config|
18
+ config.mock_with :mocha
19
+ end
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'yaml'
3
+
4
+ describe Trinidad::InitServices::Configuration do
5
+
6
+ before do
7
+ Dir.mkdir(tmp_dir) unless File.exist?(tmp_dir)
8
+ Dir.mkdir(init_dir)
9
+
10
+ config = <<YAML
11
+ app_path: "tmp/app"
12
+ trinidad_options: "-e production"
13
+ jruby_home: "tmp/jruby"
14
+ ruby_compat_version: RUBY1_8
15
+ trinidad_name: Trinidad
16
+ jsvc_path: "tmp/jsvc"
17
+ java_home: "tmp/java"
18
+ output_path: "tmp/etc_init.d"
19
+ pid_file: "tmp/trinidad.pid"
20
+ log_file: "tmp/trinidad.log"
21
+ YAML
22
+
23
+ defaults = YAML::load(config)
24
+
25
+ subject.configure(defaults)
26
+ end
27
+
28
+ after do
29
+ File.delete(init_file)
30
+ Dir.rmdir(init_dir)
31
+ Dir.rmdir(tmp_dir)
32
+ end
33
+
34
+ it "is creates the init.d file" do
35
+ File.exist?(init_file).should be_true
36
+
37
+ init_file_content = File.read(init_file)
38
+
39
+ init_file_content.match(/JSVC=tmp\/jsvc/).should be_true
40
+ init_file_content.match(/JAVA_HOME=tmp\/java/).should be_true
41
+ init_file_content.match(/JRUBY_HOME=tmp\/jruby/).should be_true
42
+ init_file_content.match(/APP_PATH=tmp\/app/).should be_true
43
+ init_file_content.match(/TRINIDAD_OPTS="-d tmp\/app -e production"/).should be_true
44
+ end
45
+
46
+ def init_file
47
+ "#{init_dir}/trinidad"
48
+ end
49
+
50
+ def init_dir
51
+ "#{tmp_dir}/etc_init.d/"
52
+ end
53
+
54
+ def tmp_dir
55
+ "#{root_dir}/tmp"
56
+ end
57
+
58
+ def root_dir
59
+ File.dirname(__FILE__) + "/../../"
60
+ end
61
+ end
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'trinidad_init_services'
16
- s.version = '1.1.0.pre3'
17
- s.date = '2011-11-03'
16
+ s.version = '1.1.0'
17
+ s.date = '2012-01-04'
18
18
  s.rubyforge_project = 'trinidad_init_services'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -59,6 +59,8 @@ Gem::Specification.new do |s|
59
59
  init.d/trinidad.erb
60
60
  lib/trinidad_init_services.rb
61
61
  lib/trinidad_init_services/configuration.rb
62
+ spec/spec_helper.rb
63
+ spec/trinidad_init_services/configuration_spec.rb
62
64
  trinidad-libs/commons-daemon.jar
63
65
  trinidad-libs/jruby-jsvc.jar
64
66
  trinidad-libs/jsvc_darwin
metadata CHANGED
@@ -1,90 +1,79 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: trinidad_init_services
3
- version: !ruby/object:Gem::Version
4
- prerelease: 6
5
- version: 1.1.0.pre3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ prerelease:
6
6
  platform: ruby
7
- authors:
8
- - David Calavera
7
+ authors:
8
+ - David Calavera
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-11-03 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: trinidad
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.2.2
24
- type: :runtime
25
- version_requirements: *id001
26
- description: Trinidad init service scripts on Apache Commons Daemon and JRuby-jsvc, compatible with Unix and Windows services
12
+ date: 2012-01-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: trinidad
16
+ requirement: &2154417140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.2.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2154417140
25
+ description: Trinidad init service scripts on Apache Commons Daemon and JRuby-jsvc,
26
+ compatible with Unix and Windows services
27
27
  email: calavera@apache.org
28
- executables:
29
- - trinidad_init_service
28
+ executables:
29
+ - trinidad_init_service
30
30
  extensions: []
31
-
32
- extra_rdoc_files:
33
- - README
34
- - LICENSE
35
- files:
36
- - History.txt
37
- - LICENSE
38
- - README
39
- - Rakefile
40
- - bin/trinidad_init_service
41
- - init.d/trinidad.erb
42
- - lib/trinidad_init_services.rb
43
- - lib/trinidad_init_services/configuration.rb
44
- - trinidad-libs/commons-daemon.jar
45
- - trinidad-libs/jruby-jsvc.jar
46
- - trinidad-libs/jsvc_darwin
47
- - trinidad-libs/jsvc_linux
48
- - trinidad-libs/prunsrv_amd64.exe
49
- - trinidad-libs/prunsrv_ia64.exe
50
- - trinidad_init_services.gemspec
31
+ extra_rdoc_files:
32
+ - README
33
+ - LICENSE
34
+ files:
35
+ - History.txt
36
+ - LICENSE
37
+ - README
38
+ - Rakefile
39
+ - bin/trinidad_init_service
40
+ - init.d/trinidad.erb
41
+ - lib/trinidad_init_services.rb
42
+ - lib/trinidad_init_services/configuration.rb
43
+ - spec/spec_helper.rb
44
+ - spec/trinidad_init_services/configuration_spec.rb
45
+ - trinidad-libs/commons-daemon.jar
46
+ - trinidad-libs/jruby-jsvc.jar
47
+ - trinidad-libs/jsvc_darwin
48
+ - trinidad-libs/jsvc_linux
49
+ - trinidad-libs/prunsrv_amd64.exe
50
+ - trinidad-libs/prunsrv_ia64.exe
51
+ - trinidad_init_services.gemspec
51
52
  homepage: http://github.com/calavera/trinidad_daemon
52
53
  licenses: []
53
-
54
- post_install_message: |+
55
-
56
- ------------------------------------------------------------------------------------
57
-
58
- Please now run:
59
-
60
- $ jruby -S trinidad_init_service
61
-
62
- to complete the installation.
63
-
64
- ------------------------------------------------------------------------------------
65
-
66
- rdoc_options:
67
- - --charset=UTF-8
68
- require_paths:
69
- - lib
70
- required_ruby_version: !ruby/object:Gem::Requirement
54
+ post_install_message: ! "\n------------------------------------------------------------------------------------\n\nPlease
55
+ now run:\n\n $ jruby -S trinidad_init_service\n\nto complete the installation.\n\n------------------------------------------------------------------------------------\n\n"
56
+ rdoc_options:
57
+ - --charset=UTF-8
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
71
61
  none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: "0"
76
- required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
67
  none: false
78
- requirements:
79
- - - ">"
80
- - !ruby/object:Gem::Version
81
- version: 1.3.1
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
82
72
  requirements: []
83
-
84
73
  rubyforge_project: trinidad_init_services
85
- rubygems_version: 1.8.9
74
+ rubygems_version: 1.8.10
86
75
  signing_key:
87
76
  specification_version: 2
88
77
  summary: Trinidad init service scripts based on Apache Commons Daemon
89
78
  test_files: []
90
-
79
+ has_rdoc: