trinidad_init_services 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,31 +1,10 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'date'
4
-
5
- #############################################################################
6
- #
7
- # Helper functions
8
- #
9
- #############################################################################
10
-
11
- def name
12
- @name ||= Dir['*.gemspec'].first.split('.').first
13
- end
14
-
15
- $:.push File.expand_path("../lib", __FILE__)
16
-
17
- def version
18
- require 'trinidad_init_services/version'
19
- Trinidad::InitServices::VERSION
20
- end
21
-
22
- def gemspec_file
23
- "#{name}.gemspec"
24
- end
25
-
26
- def gem_file
27
- "#{name}-#{version}.gem"
1
+ begin
2
+ require 'bundler/gem_helper'
3
+ rescue LoadError => e
4
+ require('rubygems') && retry
5
+ raise e
28
6
  end
7
+ Bundler::GemHelper.install_tasks
29
8
 
30
9
  #############################################################################
31
10
  #
@@ -39,66 +18,3 @@ require 'rspec/core/rake_task'
39
18
  RSpec::Core::RakeTask.new(:spec) do |spec|
40
19
  spec.rspec_opts = ['--color', "--format documentation"]
41
20
  end
42
-
43
- require 'rake/rdoctask'
44
- Rake::RDocTask.new do |rdoc|
45
- rdoc.rdoc_dir = 'rdoc'
46
- rdoc.title = "#{name} #{version}"
47
- rdoc.rdoc_files.include('README*')
48
- rdoc.rdoc_files.include('lib/**/*.rb')
49
- end
50
-
51
- desc "Open an irb session preloaded with this library"
52
- task :console do
53
- sh "irb -rubygems -r ./lib/#{name}.rb"
54
- end
55
-
56
- #############################################################################
57
- #
58
- # Custom tasks (add your own tasks here)
59
- #
60
- #############################################################################
61
-
62
-
63
-
64
- #############################################################################
65
- #
66
- # Packaging tasks
67
- #
68
- #############################################################################
69
-
70
- desc 'Release gem'
71
- task :release => :build do
72
- unless `git branch` =~ /^\* master$/
73
- puts "You must be on the master branch to release!"
74
- exit!
75
- end
76
- sh "git commit --allow-empty -a -m 'Release #{version}'"
77
- sh "git tag v#{version}"
78
- sh "git push origin master --tags"
79
- sh "gem push pkg/#{gem_file}"
80
- end
81
-
82
- desc 'Build gem'
83
- task :build do
84
- sh "mkdir -p pkg"
85
- sh "gem build #{gemspec_file}"
86
- sh "mv #{gem_file} pkg"
87
- end
88
-
89
- desc 'Install gem'
90
- task :install => :build do
91
- sh "gem install pkg/#{gem_file}"
92
- end
93
-
94
- task :validate do
95
- libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
96
- unless libfiles.empty?
97
- puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
98
- exit!
99
- end
100
- unless Dir['VERSION*'].empty?
101
- puts "A `VERSION` file at root level violates Gem best practices."
102
- exit!
103
- end
104
- end
data/init.d/trinidad.erb CHANGED
@@ -1,14 +1,9 @@
1
1
  #!/usr/bin/env bash
2
- # Generic script for running ruby scripts as daemons using
3
- # jsvc and a java class to control the daemon.
2
+ # Trinidad init.d script using `jsvc` customized from the jsvc-wrapper.sh
3
+ # http://github.com/nicobrevin/jruby-jsvc/blob/master/bin/jsvc-wrapper.sh
4
4
  #
5
- # Contains common parameters and start/stop
6
-
7
- # Things you'll need to set on a per script/daemon basis:
5
+ # set on a per script/daemon basis (optional) :
8
6
  # APP_NAME - name of your application (defaults to "trinidad")
9
- #
10
- # Things you can set:
11
- # PROG_OPTS - Arguments to send to the program. A few defaults are appended to this.
12
7
 
13
8
  # https://github.com/trinidad/trinidad_init_services/wiki/Installing-JSVC
14
9
  JSVC=<%= @jsvc %>
@@ -48,10 +43,6 @@ MAIN_CLASS=com.msp.jsvc.JRubyDaemon
48
43
 
49
44
  CLASSPATH=<%= @classpath.join(":") %>
50
45
 
51
- if [ -z "$JRUBY_OPTS" ] ; then
52
- JRUBY_OPTS=""
53
- fi
54
-
55
46
  JRUBY_SHELL=/bin/sh
56
47
 
57
48
  JRUBY_NATIVE_PATH=""
@@ -65,28 +56,46 @@ if [ -d "$JRUBY_HOME/lib/native/" ]; then
65
56
  done
66
57
  fi
67
58
 
59
+ # JAVA_MEM, JAVA_MEM_MIN & JAVA_STACK are compatible with jruby's binary
60
+
68
61
  if [ -z "$JAVA_MEM" ] ; then
69
- JAVA_MEM=500m
62
+ JAVA_MEM=-Xmx500m
63
+ fi
64
+ # backwards compatibility we accept the non-full option (e.g. JAVA_MEM=500m)
65
+ if [[ "$JAVA_MEM" != "-Xmx"* ]] ; then
66
+ JAVA_MEM="-Xmx$JAVA_MEM"
67
+ fi
68
+
69
+ # we accept the non-full option (e.g. JAVA_MEM_MIN=500m)
70
+ if [[ -n "$JAVA_MEM_MIN" && "$JAVA_MEM_MIN" != "-Xms"* ]] ; then
71
+ JAVA_MEM_MIN="-Xms$JAVA_MEM_MIN"
72
+ fi
73
+ if [ -z "$JAVA_MEM_MIN" ] ; then
74
+ JAVA_MEM_MIN=""
70
75
  fi
71
76
 
72
77
  if [ -z "$JAVA_STACK" ] ; then
73
- JAVA_STACK=2048k
78
+ JAVA_STACK=-Xss2048k
74
79
  fi
80
+ # backwards compatibility we accept the non-full option (e.g. JAVA_STACK=2048k)
81
+ if [[ "$JAVA_STACK" != "-Xss"* ]] ; then
82
+ JAVA_STACK="-Xss$JAVA_STACK"
83
+ fi
84
+
85
+ # A custom (daemon) script will be started (not jruby -S) thus JRUBY_OPTS
86
+ # won't be used here, feel free to hand tune JAVA_OPTS here instead ...
75
87
 
76
- JAVA_OPTS="-Xmx${JAVA_MEM} -Xss${JAVA_STACK} -Xbootclasspath/a:$JRUBY_HOME/lib/jruby.jar"
88
+ JAVA_OPTS="$JAVA_MEM $JAVA_MEM_MIN $JAVA_STACK -Xbootclasspath/a:$JRUBY_HOME/lib/jruby.jar"
77
89
 
78
90
  # force file.encoding to UTF-8 :
79
91
  if [[ -z "$JAVA_ENCODING" ]]; then
80
- JAVA_OPTS="${JAVA_OPTS} -Dfile.encoding=UTF-8"
92
+ JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8"
81
93
  fi
82
94
 
83
95
  JAVA_PROPS="$JAVA_PROPS \
84
- -Djruby.memory.max=$JAVA_MEM \
85
- -Djruby.stack.max=$JAVA_STACK \
86
96
  -Djruby.shell=$JRUBY_SHELL \
87
97
  -Djffi.boot.library.path=$JRUBY_NATIVE_PATH \
88
- <%= @jruby_opts.join(' ') %> \
89
- $JRUBY_OPTS"
98
+ <%= @jruby_opts.join(' ') %> "
90
99
 
91
100
  PROC_NAME=${SCRIPT_NAME:-${APP_NAME:-"trinidad"}}
92
101
 
@@ -123,7 +132,7 @@ case "$1" in
123
132
  $START_COMMAND
124
133
  EXIT_CODE=$?
125
134
  if [ "$EXIT_CODE" != 0 ]; then
126
- echo "Daemon exited with status: $EXIT_CODE. Check pidfile and log"
135
+ echo "Daemon exited with status: $EXIT_CODE. Check pidfile and log"
127
136
  fi
128
137
  fi
129
138
  ;;
@@ -151,7 +160,7 @@ case "$1" in
151
160
  $START_COMMAND
152
161
  EXIT_CODE=$?
153
162
  if [ "$EXIT_CODE" != 0 ]; then
154
- echo "Daemon exited with status: $EXIT_CODE. Check pidfile and log"
163
+ echo "Daemon exited with status: $EXIT_CODE. Check pidfile and log"
155
164
  fi
156
165
  fi
157
166
  ;;
@@ -160,9 +169,9 @@ case "$1" in
160
169
  PID=`cat $PIDFILE`
161
170
  OUTPUT=`ps $PID | egrep "^$PID "`
162
171
  if [ ${#OUTPUT} -gt 0 ]; then
163
- echo "Service running with pid: $PID"
172
+ echo "Service running with pid: $PID"
164
173
  else
165
- echo "Pidfile present, but process not running"
174
+ echo "Pidfile present, but process not running"
166
175
  fi
167
176
  else
168
177
  echo "No pidfile present"
@@ -1,5 +1,9 @@
1
- require 'rubygems'
2
- require 'trinidad'
1
+ begin
2
+ require 'trinidad'
3
+ rescue LoadError => e
4
+ require('rubygems') && retry
5
+ raise e
6
+ end
3
7
 
4
8
  module Trinidad
5
9
  module Daemon
@@ -7,10 +11,15 @@ module Trinidad
7
11
  def init
8
12
  end
9
13
 
14
+ # checked from com.msp.jsvc.JRubyDaemon.init
15
+ # as Trinidad::Daemon#setup? to check whether
16
+ # daemon's init setup has been succesful ...
10
17
  def setup?
11
18
  true
12
19
  end
13
20
 
21
+ # called from com.msp.jsvc.JRubyDaemon.start
22
+ # as Trinidad::Daemon#start
14
23
  def start(args = ARGV)
15
24
  Trinidad::CommandLineParser.parse(args)
16
25
  Trinidad.configuration.trap = false
@@ -18,6 +27,8 @@ module Trinidad
18
27
  @server.start
19
28
  end
20
29
 
30
+ # called from com.msp.jsvc.JRubyDaemon.stop
31
+ # as Trinidad::Daemon#stop
21
32
  def stop
22
33
  @server.stop
23
34
  end
@@ -30,7 +30,7 @@ module Trinidad
30
30
  end
31
31
 
32
32
  def configure(defaults = {})
33
- @app_path = defaults["app_path"] || ask_path('Application path?')
33
+ @app_path = defaults["app_path"] || ask_path('Application path', false)
34
34
  @trinidad_options = ["-d #{@app_path}"]
35
35
  options_ask = 'Trinidad options?'
36
36
  options_default = '-e production'
@@ -38,8 +38,8 @@ module Trinidad
38
38
 
39
39
  @trinidad_options << (defaults["trinidad_options"] || ask(options_ask, options_default))
40
40
  @trinidad_options.map! { |opt| Shellwords.shellsplit(opt) }.flatten!
41
- @jruby_home = defaults["jruby_home"] || ask_path('JRuby home?', default_jruby_home)
42
- @ruby_compat_version = defaults["ruby_compat_version"] || ask('Ruby 1.8.x or 1.9.x compatibility?', default_ruby_compat_version)
41
+ @jruby_home = defaults["jruby_home"] || ask_path('JRuby home', default_jruby_home)
42
+ @ruby_compat_version = defaults["ruby_compat_version"] || ask('Ruby 1.8.x or 1.9.x compatibility', default_ruby_compat_version)
43
43
  @jruby_opts = configure_jruby_opts
44
44
  initialize_paths(@jruby_home)
45
45
 
@@ -58,20 +58,20 @@ module Trinidad
58
58
  end
59
59
 
60
60
  def configure_unix_daemon(defaults)
61
- @java_home = defaults["java_home"] || ask_path('Java home?', default_java_home)
61
+ @java_home = defaults["java_home"] || ask_path('Java home', default_java_home)
62
62
  unless @jsvc = defaults["jsvc_path"] || detect_jsvc_path
63
- @jsvc = ask_path("path to jsvc binary (leave blank and we'll try to compile)?", '')
63
+ @jsvc = ask_path("path to jsvc binary (leave blank and we'll try to compile)", '')
64
64
  if @jsvc.empty? # unpack and compile :
65
- jsvc_unpack_dir = defaults["jsvc_unpack_dir"] || ask_path("dir where jsvc dist should be unpacked?", '/usr/local/src')
65
+ jsvc_unpack_dir = defaults["jsvc_unpack_dir"] || ask_path("dir where jsvc dist should be unpacked", '/usr/local/src')
66
66
  @jsvc = compile_jsvc(jsvc_unpack_dir, @java_home)
67
67
  say "jsvc binary available at: #{@jsvc} " +
68
68
  "(consider adding it to $PATH if you plan to re-run trinidad_init_service)"
69
69
  end
70
70
  end
71
- @output_path = defaults["output_path"] || ask_path('init.d output path?', '/etc/init.d')
72
- @pid_file = defaults["pid_file"] || ask_path('pid file?', '/var/run/trinidad/trinidad.pid')
73
- @log_file = defaults["log_file"] || ask_path('log file?', '/var/log/trinidad/trinidad.log')
74
- @run_user = defaults["run_user"] || ask('run daemon as user (enter a non-root username or leave blank)?', '')
71
+ @output_path = defaults["output_path"] || ask_path('init.d output path', '/etc/init.d')
72
+ @pid_file = defaults["pid_file"] || ask_path('pid file', '/var/run/trinidad/trinidad.pid')
73
+ @log_file = defaults["log_file"] || ask_path('log file', '/var/log/trinidad/trinidad.log')
74
+ @run_user = defaults["run_user"] || ask('run daemon as user (enter a non-root username or leave blank)', '')
75
75
 
76
76
  if @run_user != '' && `id -u #{@run_user}` == ''
77
77
  raise ArgumentError, "user '#{@run_user}' does not exist (leave blank if you're planning to `useradd' later)"
@@ -107,7 +107,7 @@ module Trinidad
107
107
  @trinidad_service_id = defaults["trinidad_service_id"] || ask(id_ask, id_default)
108
108
 
109
109
  desc_ask = 'Service description? {Alphanumeric and spaces only}'
110
- desc_default = 'Embedded Apache Tomcat running rack and rails applications'
110
+ desc_default = 'Embedded Apache Tomcat running Rack and Rails applications'
111
111
  @trinidad_service_desc = defaults["trinidad_service_desc"] || ask(desc_ask, desc_default)
112
112
  end
113
113
 
@@ -200,7 +200,11 @@ module Trinidad
200
200
 
201
201
  def compile_jsvc(jsvc_unpack_dir, java_home = default_java_home)
202
202
  unless File.exist?(jsvc_unpack_dir)
203
- raise "specified path does not exist: #{jsvc_unpack_dir.inspect}"
203
+ begin
204
+ FileUtils.mkdir(jsvc_unpack_dir)
205
+ rescue
206
+ raise "specified path does not exist: #{jsvc_unpack_dir.inspect}"
207
+ end
204
208
  end
205
209
  unless File.directory?(jsvc_unpack_dir)
206
210
  raise "specified path: #{jsvc_unpack_dir.inspect} is not a directory"
@@ -284,13 +288,18 @@ module Trinidad
284
288
 
285
289
  def ask_path(question, default = nil)
286
290
  path = ask(question, default)
291
+ unless path # nil, false
292
+ raise "#{question.inspect} not provided!" if path == false
293
+ return path # nil
294
+ end
287
295
  path.empty? ? path : File.expand_path(path)
288
296
  end
289
297
 
290
298
  def ask(question, default = nil)
291
299
  return default if ! @stdin.tty? || @ask == false
292
-
293
- question << " [#{default}]" if default && ! default.empty?
300
+
301
+ question = "#{question}?" unless question.index('?')
302
+ question += " [#{default}]" if default && ! default.empty?
294
303
 
295
304
  result = nil
296
305
  while result.nil?
@@ -1,5 +1,5 @@
1
1
  module Trinidad
2
2
  module InitServices
3
- VERSION = '1.2.1'
3
+ VERSION = '1.2.2'
4
4
  end
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  begin
2
2
  require 'rspec'
3
- rescue LoadError
4
- require 'rubygems'
5
- gem 'rspec'
6
- require 'rspec'
3
+ rescue LoadError => e
4
+ require('rubygems') && retry
5
+ raise e
7
6
  end
8
7
 
9
8
  require 'mocha'
@@ -12,7 +11,7 @@ RSpec.configure do |config|
12
11
  config.mock_with :mocha
13
12
  end
14
13
 
15
- $:.unshift(File.dirname(__FILE__) + '/../lib')
14
+ $:.unshift File.expand_path('../lib', File.dirname(__FILE__))
16
15
 
17
16
  require 'trinidad_init_services'
18
17
  require 'trinidad/daemon'
@@ -156,6 +156,24 @@ describe Trinidad::InitServices::Configuration do
156
156
  }x
157
157
  end
158
158
 
159
+ it "ask_path works when non tty and default nil" do
160
+ subject.ask = false
161
+ stdin = mock('stdin')
162
+ stdin.stubs(:tty?).returns false
163
+ subject.instance_variable_set(:@stdin, stdin)
164
+ subject.send(:ask_path, 'Home', nil).should be nil
165
+ end
166
+
167
+ it "ask_path raises when non tty and default false" do
168
+ subject.ask = false
169
+ stdin = mock('stdin')
170
+ stdin.stubs(:tty?).returns false
171
+ subject.instance_variable_set(:@stdin, stdin)
172
+ expect( lambda {
173
+ subject.send(:ask_path, 'Home', false)
174
+ } ).to raise_error RuntimeError
175
+ end
176
+
159
177
  it "ask= forces trinidad to not ask on tty" do
160
178
  subject.ask = false
161
179
  outcome = subject.send :ask, 'hello?', :there
@@ -164,7 +182,7 @@ describe Trinidad::InitServices::Configuration do
164
182
  outcome = subject.send :ask, 'de-ja-vu?', nil
165
183
  outcome.should be nil
166
184
  end
167
-
185
+
168
186
  it "say= silences standard output" do
169
187
  def subject.puts(msg)
170
188
  raise msg
@@ -3,10 +3,6 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require 'trinidad_init_services/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.specification_version = 2 if s.respond_to? :specification_version=
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.rubygems_version = '1.3.5'
9
-
10
6
  s.name = 'trinidad_init_services'
11
7
  s.version = Trinidad::InitServices::VERSION
12
8
  s.rubyforge_project = 'trinidad_init_services'
@@ -29,13 +25,13 @@ Gem::Specification.new do |s|
29
25
  ## Specify any RDoc options here. You'll want to add your README and
30
26
  ## LICENSE files to the extra_rdoc_files list.
31
27
  s.rdoc_options = ["--charset=UTF-8"]
32
- s.extra_rdoc_files = %w[README.md LICENSE]
28
+ s.extra_rdoc_files = %w[ README.md LICENSE ]
33
29
 
34
30
  ## List your runtime dependencies here. Runtime dependencies are those
35
31
  ## that are needed for an end user to actually USE your code.
36
- s.add_dependency('trinidad', '>= 1.3.2')
32
+ s.add_dependency('trinidad', '>= 1.3.5')
37
33
 
38
- s.add_development_dependency('rspec', '>= 2.7.1')
34
+ s.add_development_dependency('rspec', '>= 2.10')
39
35
  s.add_development_dependency('mocha', '>= 0.10')
40
36
 
41
37
  s.files = `git ls-files`.split("\n")
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: trinidad_init_services
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.1
5
+ version: 1.2.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Calavera
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-09-06 00:00:00 Z
13
+ date: 2012-10-23 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: trinidad
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.3.2
23
+ version: 1.3.5
24
24
  type: :runtime
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
@@ -31,7 +31,7 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 2.7.1
34
+ version: "2.10"
35
35
  type: :development
36
36
  version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
@@ -156,9 +156,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  requirements: []
157
157
 
158
158
  rubyforge_project: trinidad_init_services
159
- rubygems_version: 1.8.15
159
+ rubygems_version: 1.8.24
160
160
  signing_key:
161
- specification_version: 2
161
+ specification_version: 3
162
162
  summary: Trinidad init service scripts based on Apache Commons Daemon
163
163
  test_files: []
164
164