trinidad_daemon_extension 0.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 ADDED
@@ -0,0 +1,3 @@
1
+ 0.1.0 (2010-04-17)
2
+
3
+ * First release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 David Calavera
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,42 @@
1
+ Trinidad Daemon Extension
2
+ =======
3
+
4
+ # DESCRIPTION
5
+
6
+ Extension to run Trinidad server as a daemon.
7
+
8
+ [WARNING] This extension only works with Trinidad 0.8.3 or above.
9
+
10
+ # INSTALLATION
11
+
12
+ jruby -S gem install trinidad_daemon_extension
13
+
14
+ # USAGE
15
+
16
+ This extension can be enabled from the Trinidad's configuration file or from the command line.
17
+ It uses a temporal directory to write the pid file but its route can be overrided.
18
+
19
+ * To enable it from the configuration file you have to add a section "extensions" to the root of the file and the section "daemon" to this one. The pid file can be specified there:
20
+
21
+ --
22
+ extensions:
23
+ daemon:
24
+ pid_file: ./trinidad.pid # this is optional by default the extension writes the pid file into a temporal directory.
25
+
26
+ * To enable it from the command line you have to load the extension first and the add one of these options:
27
+
28
+ -d, --daemonize [PID_FILE]
29
+
30
+ for instance:
31
+
32
+ $ jruby -S trinidad --load daemon --daemonize ./trinidad.pid
33
+
34
+ # TODO
35
+
36
+ * enable logging. Right now the Tomcat's log is not written anywhere.
37
+
38
+ You can find further information on how to write your onw extension in the wiki: http://wiki.github.com/calavera/trinidad/extensions
39
+
40
+ # Copyright
41
+
42
+ Copyright (c) 2010 David Calavera. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,150 @@
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
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ task :default => :spec
47
+
48
+ require 'spec/rake/spectask'
49
+ Spec::Rake::SpecTask.new(:spec) do |spec|
50
+ spec.libs << 'lib' << 'spec'
51
+ spec.spec_opts = ['--options', 'spec/spec.opts']
52
+ spec.spec_files = FileList['spec/**/*_spec.rb']
53
+ end
54
+
55
+
56
+ desc "Generate RCov test coverage and open in your browser"
57
+ task :coverage do
58
+ require 'rcov'
59
+ sh "rm -fr coverage"
60
+ sh "rcov test/test_*.rb"
61
+ sh "open coverage/index.html"
62
+ end
63
+
64
+ require 'rake/rdoctask'
65
+ Rake::RDocTask.new do |rdoc|
66
+ rdoc.rdoc_dir = 'rdoc'
67
+ rdoc.title = "#{name} #{version}"
68
+ rdoc.rdoc_files.include('README*')
69
+ rdoc.rdoc_files.include('lib/**/*.rb')
70
+ end
71
+
72
+ desc "Open an irb session preloaded with this library"
73
+ task :console do
74
+ sh "irb -rubygems -r ./lib/#{name}.rb"
75
+ end
76
+
77
+ #############################################################################
78
+ #
79
+ # Custom tasks (add your own tasks here)
80
+ #
81
+ #############################################################################
82
+
83
+
84
+
85
+ #############################################################################
86
+ #
87
+ # Packaging tasks
88
+ #
89
+ #############################################################################
90
+
91
+ task :release => :build do
92
+ unless `git branch` =~ /^\* master$/
93
+ puts "You must be on the master branch to release!"
94
+ exit!
95
+ end
96
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
97
+ sh "git tag v#{version}"
98
+ sh "git push origin master"
99
+ sh "git push v#{version}"
100
+ sh "gem push pkg/#{name}-#{version}.gem"
101
+ end
102
+
103
+ task :build => ['ant:build', 'gemspec'] do
104
+ sh "mkdir -p pkg"
105
+ sh "gem build #{gemspec_file}"
106
+ sh "mv #{gem_file} pkg"
107
+ end
108
+
109
+ task :gemspec => :validate do
110
+ # read spec file and split out manifest section
111
+ spec = File.read(gemspec_file)
112
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
113
+
114
+ # replace name version and date
115
+ replace_header(head, :name)
116
+ replace_header(head, :version)
117
+ replace_header(head, :date)
118
+ #comment this out if your rubyforge_project has a different name
119
+ replace_header(head, :rubyforge_project)
120
+
121
+ # determine file list from git ls-files
122
+ files = `git ls-files`.
123
+ split("\n").
124
+ sort.
125
+ reject { |file| file =~ /^\./ }.
126
+ reject { |file| file =~ /^(rdoc|pkg|src)/ }.
127
+ reject { |file| file =~ /tomcat-core.jar/ }.
128
+ map { |file| " #{file}" }.
129
+ join("\n")
130
+
131
+ files << "\n trinidad-libs/trinidad-daemon-extension.jar"
132
+
133
+ # piece file back together and write
134
+ manifest = " s.files = %w[\n#{files}\n ]\n"
135
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
136
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
137
+ puts "Updated #{gemspec_file}"
138
+ end
139
+
140
+ task :validate do
141
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
142
+ unless libfiles.empty?
143
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
144
+ exit!
145
+ end
146
+ unless Dir['VERSION*'].empty?
147
+ puts "A `VERSION` file at root level violates Gem best practices."
148
+ exit!
149
+ end
150
+ end
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ gem 'trinidad_jars'
3
+ require 'trinidad/extensions'
4
+ require 'trinidad/jars'
5
+
6
+ require File.expand_path('../../trinidad-libs/akuma', __FILE__)
7
+ require File.expand_path('../../trinidad-libs/trinidad-daemon-extension', __FILE__)
8
+
9
+ module Trinidad
10
+ module Extensions
11
+ module Daemon
12
+ VERSION = '0.1.0'
13
+ end
14
+
15
+ class DaemonServerExtension < ServerExtension
16
+ def configure(tomcat)
17
+ org.jruby.trinidad.TrinidadDaemon.new(tomcat, @options[:pid_file])
18
+ end
19
+
20
+ def override_tomcat?; true; end
21
+ end
22
+
23
+ class DaemonOptionsExtension < OptionsExtension
24
+ def configure(parser, default_options)
25
+ parser.on('-d', '--daemonize [PID_FILE]', 'run Trinidad as a daemon, pid_file by default is ENV[$TMPDIR]/trinidad.pid') do |pid|
26
+ extensions = default_options[:extensions] || {}
27
+ extensions[:daemon] = {:pid_file => pid}
28
+ default_options[:extensions] = extensions
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ require 'ant'
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ TARGET_DIR = 'target'
6
+ LIBS_DIR = 'trinidad-libs'
7
+ JAR_NAME = 'trinidad-daemon-extension.jar'
8
+
9
+ namespace :ant do
10
+ desc 'Clean the java target directory'
11
+ task :clean do
12
+ rm_f TARGET_DIR
13
+ rm_f "#{LIBS_DIR}/#{JAR_NAME}"
14
+ end
15
+
16
+ desc 'Compile the java classes'
17
+ task :compile => :clean do
18
+ opts = {
19
+ :fork => 'true',
20
+ :failonerror => 'true',
21
+ :srcdir => 'src/main',
22
+ :destdir => TARGET_DIR,
23
+ :classpath => Dir.glob('trinidad-libs/*.jar').join(':')
24
+ }
25
+
26
+ mkdir_p TARGET_DIR
27
+ ant.javac(opts)
28
+ end
29
+
30
+ desc 'Create the jar file'
31
+ task :build => :compile do
32
+ opts = {
33
+ :destfile => "#{LIBS_DIR}/#{JAR_NAME}",
34
+ :basedir => TARGET_DIR
35
+ }
36
+ ant.jar(opts)
37
+ end
38
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format specdoc
@@ -0,0 +1,17 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+
11
+ require 'java'
12
+ require 'trinidad_daemon_extension'
13
+ require 'mocha'
14
+
15
+ Spec::Runner.configure do |config|
16
+ config.mock_with :mocha
17
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'optparse'
3
+
4
+ describe Trinidad::Extensions::DaemonServerExtension do
5
+ subject { Trinidad::Extensions::DaemonServerExtension.new({}) }
6
+
7
+ before(:each) do
8
+ @tomcat = Trinidad::Tomcat::Tomcat.new
9
+ end
10
+
11
+ it "bypass the control to the daemon" do
12
+ daemon = subject.configure(@tomcat)
13
+ daemon.should_not be_nil
14
+ daemon.should be_instance_of(org.jruby.trinidad.TrinidadDaemon)
15
+ end
16
+
17
+ it "uses a temporal directory to write the pid file by default" do
18
+ daemon = subject.configure(@tomcat)
19
+ daemon.pid_file.should =~ /trinidad.pid$/
20
+ end
21
+
22
+ it "can use a given pid file" do
23
+ extension = Trinidad::Extensions::DaemonServerExtension.new(:pid_file => 'trinidad_pid.txt')
24
+ daemon = extension.configure(@tomcat)
25
+ daemon.pid_file.should =~ /trinidad_pid.txt$/
26
+ end
27
+
28
+ it "allows to specify a command line option to run the daemon" do
29
+ extension = Trinidad::Extensions::DaemonOptionsExtension.new
30
+ parser = OptionParser.new
31
+ options = {}
32
+
33
+ extension.configure(parser, options)
34
+ parser.parse! '-d /tmp/trinidad.pid'.split
35
+
36
+ options[:extensions].keys.should include(:daemon)
37
+ options[:extensions][:daemon].should include(:pid_file)
38
+ options[:extensions][:daemon][:pid_file].should == '/tmp/trinidad.pid'
39
+ end
40
+ end
Binary file
@@ -0,0 +1,73 @@
1
+ ## This is the rakegem gemspec template. Make sure you read and understand
2
+ ## all of the comments. Some sections require modification, and others can
3
+ ## be deleted if you don't need them. Once you understand the contents of
4
+ ## this file, feel free to delete any comments that begin with two hash marks.
5
+ ## You can find comprehensive Gem::Specification documentation, at
6
+ ## http://docs.rubygems.org/read/chapter/20
7
+ Gem::Specification.new do |s|
8
+ s.specification_version = 2 if s.respond_to? :specification_version=
9
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.rubygems_version = '1.3.5'
11
+
12
+ ## Leave these as is they will be modified for you by the rake gemspec task.
13
+ ## If your rubyforge_project name is different, then edit it and comment out
14
+ ## the sub! line in the Rakefile
15
+ s.name = 'trinidad_daemon_extension'
16
+ s.version = '0.1.0'
17
+ s.date = '2010-04-17'
18
+ s.rubyforge_project = 'trinidad_daemon_extension'
19
+
20
+ ## Make sure your summary is short. The description may be as long
21
+ ## as you like.
22
+ s.summary = "Trinidad daemon extension"
23
+ s.description = "Trinidad extension to run the Apache Tomcat server as a daemon"
24
+
25
+ ## List the primary authors. If there are a bunch of authors, it's probably
26
+ ## better to set the email to an email list or something. If you don't have
27
+ ## a custom homepage, consider using your GitHub URL or the like.
28
+ s.authors = ["David Calavera"]
29
+ s.email = 'calavera@apache.org'
30
+ s.homepage = 'http://github.com/trinidad/trinidad_daemon_extension'
31
+
32
+ ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
33
+ ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
34
+ s.require_paths = %w[lib]
35
+
36
+ ## Specify any RDoc options here. You'll want to add your README and
37
+ ## LICENSE files to the extra_rdoc_files list.
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.extra_rdoc_files = %w[README LICENSE]
40
+
41
+ ## List your runtime dependencies here. Runtime dependencies are those
42
+ ## that are needed for an end user to actually USE your code.
43
+ s.add_dependency('trinidad_jars', [">= 0.1.1"])
44
+
45
+ ## List your development dependencies here. Development dependencies are
46
+ ## those that are only needed during development
47
+ s.add_development_dependency('rspec')
48
+ s.add_development_dependency('mocha')
49
+
50
+ ## Leave this section as-is. It will be automatically generated from the
51
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
52
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
53
+ # = MANIFEST =
54
+ s.files = %w[
55
+ History.txt
56
+ LICENSE
57
+ README
58
+ Rakefile
59
+ lib/trinidad_daemon_extension.rb
60
+ rakelib/build.rake
61
+ spec/spec.opts
62
+ spec/spec_helper.rb
63
+ spec/trinidad_daemon_extension_spec.rb
64
+ trinidad-libs/akuma.jar
65
+ trinidad_daemon_extension.gemspec
66
+ trinidad-libs/trinidad-daemon-extension.jar
67
+ ]
68
+ # = MANIFEST =
69
+
70
+ ## Test files will be grabbed from the file list. Make sure the path glob
71
+ ## matches what you actually use.
72
+ s.test_files = s.files.select { |path| path =~ /^spec\/.*_spec\.rb/ }
73
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trinidad_daemon_extension
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - David Calavera
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-17 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: trinidad_jars
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 1
30
+ - 1
31
+ version: 0.1.1
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: mocha
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ type: :development
57
+ version_requirements: *id003
58
+ description: Trinidad extension to run the Apache Tomcat server as a daemon
59
+ email: calavera@apache.org
60
+ executables: []
61
+
62
+ extensions: []
63
+
64
+ extra_rdoc_files:
65
+ - README
66
+ - LICENSE
67
+ files:
68
+ - History.txt
69
+ - LICENSE
70
+ - README
71
+ - Rakefile
72
+ - lib/trinidad_daemon_extension.rb
73
+ - rakelib/build.rake
74
+ - spec/spec.opts
75
+ - spec/spec_helper.rb
76
+ - spec/trinidad_daemon_extension_spec.rb
77
+ - trinidad-libs/akuma.jar
78
+ - trinidad_daemon_extension.gemspec
79
+ - trinidad-libs/trinidad-daemon-extension.jar
80
+ has_rdoc: true
81
+ homepage: http://github.com/trinidad/trinidad_daemon_extension
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options:
86
+ - --charset=UTF-8
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ requirements: []
104
+
105
+ rubyforge_project: trinidad_daemon_extension
106
+ rubygems_version: 1.3.6
107
+ signing_key:
108
+ specification_version: 2
109
+ summary: Trinidad daemon extension
110
+ test_files:
111
+ - spec/trinidad_daemon_extension_spec.rb