iyyov 1.0.0-java → 1.0.1-java
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.rdoc +8 -0
- data/Manifest.txt +8 -0
- data/README.rdoc +69 -5
- data/Rakefile +22 -10
- data/bin/iyyov-fg +0 -0
- data/config/async.rb +11 -0
- data/config/crontab +2 -0
- data/config/init.d/iyyov +97 -0
- data/config/jobs.rb +29 -0
- data/config/load-all.rb +10 -0
- data/init/iyyov-daemon +1 -1
- data/lib/iyyov/base.rb +1 -1
- data/lib/iyyov/daemon.rb +1 -9
- data/lib/iyyov/log_rotator.rb +0 -1
- data/lib/iyyov/task.rb +11 -4
- data/lib/iyyov.rb +4 -0
- data/test/jobs-bad.rb +1 -0
- data/test/jobs-dupe.rb +11 -0
- data/test/test_context.rb +59 -0
- metadata +14 -12
data/History.rdoc
CHANGED
@@ -1,2 +1,10 @@
|
|
1
|
+
=== 1.0.1 (2010-3-13)
|
2
|
+
* Fix dependencies
|
3
|
+
* Cleanup and add config examples to gem, including init.d and crontab
|
4
|
+
examples.
|
5
|
+
* Proper README.rdoc
|
6
|
+
* Add context file load error handling and example config tests.
|
7
|
+
* Improve error handling with tasks (log, :stop on StandardError)
|
8
|
+
|
1
9
|
=== 1.0.0 (2010-3-7)
|
2
10
|
* Initial release.
|
data/Manifest.txt
CHANGED
@@ -13,6 +13,14 @@ lib/iyyov/log_rotator.rb
|
|
13
13
|
lib/iyyov/scheduler.rb
|
14
14
|
lib/iyyov/shutdown_handler.rb
|
15
15
|
lib/iyyov/task.rb
|
16
|
+
config/async.rb
|
17
|
+
config/crontab
|
18
|
+
config/jobs.rb
|
19
|
+
config/load-all.rb
|
20
|
+
config/init.d/iyyov
|
21
|
+
test/jobs-bad.rb
|
22
|
+
test/jobs-dupe.rb
|
16
23
|
test/setup.rb
|
24
|
+
test/test_context.rb
|
17
25
|
test/test_daemon.rb
|
18
26
|
test/test_scheduler.rb
|
data/README.rdoc
CHANGED
@@ -6,13 +6,77 @@
|
|
6
6
|
|
7
7
|
== Description
|
8
8
|
|
9
|
-
Down-to-earth job control and monitoring.
|
9
|
+
Down-to-earth job control and monitoring.
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
*
|
11
|
+
=== Features
|
12
|
+
|
13
|
+
* Runs on JRuby (no fork or native code extensions)
|
14
|
+
* Powerful ruby-based configuration inspired by {God}[http://god.rubyforge.org]
|
15
|
+
* Simplified gem packaged daemon launching and monitoring (via Hashdot, others)
|
14
16
|
* Log rotation with daemon SIGHUP support
|
15
|
-
* Fixed and periodic time job scheduling (basic cron replacement)
|
17
|
+
* Fixed and periodic time job scheduling (basic cron replacement)
|
18
|
+
* Threaded asynchronous support with mutual exclusion for long
|
19
|
+
running scheduled jobs
|
20
|
+
* Configuration file monitoring and reload support
|
21
|
+
* Automatic daemon restart on upgrade or other changes
|
22
|
+
|
23
|
+
== Synopsis
|
24
|
+
|
25
|
+
Iyyov can be tested in the foreground with (-d)ebug logging:
|
26
|
+
|
27
|
+
% iyyov-fg -d jobs.rb
|
28
|
+
|
29
|
+
See gem or source config/ directory for sample/runnable
|
30
|
+
configurations. Sample jobs.rb configuration:
|
31
|
+
|
32
|
+
Iyyov.context do |c|
|
33
|
+
|
34
|
+
c.define_daemon do |d|
|
35
|
+
d.name = "hashdot-test-daemon"
|
36
|
+
d.version = "~> 1.0.0"
|
37
|
+
d.log_rotate do |l|
|
38
|
+
l.max_size_mb = 256
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
c.schedule_at( :name => "hello", :period => 3.0 ) do
|
43
|
+
puts "hello every 3.0 seconds"
|
44
|
+
end
|
45
|
+
|
46
|
+
c.schedule_at( :name => "fixed",
|
47
|
+
:fixed_times => %w[ 00:01 12:02 ] ) do
|
48
|
+
puts "Fixed time task"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
== Daemon support
|
54
|
+
|
55
|
+
The simple form of the define_daemon creates an Iyyov::Daemon
|
56
|
+
based on the following conventions:
|
57
|
+
|
58
|
+
* The required name by default is used as a gem name as well as init
|
59
|
+
script name.
|
60
|
+
* Most all set attributes may be lambda's.
|
61
|
+
* If a version is specified, the default Daemon.exe_path will be an
|
62
|
+
init script with the same name and provided by the same named gem
|
63
|
+
and highest matching version.
|
64
|
+
* In any case, the Daemon.exe_path should itself demonize and create
|
65
|
+
a pid in order to be monitored.
|
66
|
+
{Hashdot}[http://hashdot.sourceforge.net/] provides one reliable
|
67
|
+
means of achieving this. Its could also be achieved via a bash
|
68
|
+
script.
|
69
|
+
|
70
|
+
== Setup
|
71
|
+
|
72
|
+
Besides creating one or many jobs.rb scripts, you will want to arrange
|
73
|
+
for iyyov to be started on system boot. There are several ways to
|
74
|
+
achieve this:
|
75
|
+
|
76
|
+
* UNIX init.d script (a CentOS/Fedora version is provided in gem or source
|
77
|
+
config/init.d directory)
|
78
|
+
* inittab or upstart (which also supports monitoring iyyov/restarting itself)
|
79
|
+
* Crontab (an example is provided at gem or source config/crontab)
|
16
80
|
|
17
81
|
== License
|
18
82
|
|
data/Rakefile
CHANGED
@@ -28,26 +28,38 @@ t = RJack::TarPit.new( 'iyyov', Iyyov::VERSION, :java_platform )
|
|
28
28
|
t.specify do |h|
|
29
29
|
h.developer( 'David Kellum', 'dek-oss@gravitext.com' )
|
30
30
|
h.testlib = :minitest
|
31
|
-
h.extra_deps += [ [ 'rjack-
|
31
|
+
h.extra_deps += [ [ 'rjack-slf4j', '~> 1.5.11' ],
|
32
32
|
[ 'rjack-logback', '~> 0.9.18' ],
|
33
|
-
[ 'logrotate', '= 1.2.1'
|
34
|
-
h.extra_dev_deps += [ [ 'minitest', '~> 1.5.0'
|
35
|
-
[ 'hashdot-test-daemon', '>= 1.0.0'
|
33
|
+
[ 'logrotate', '= 1.2.1' ] ]
|
34
|
+
h.extra_dev_deps += [ [ 'minitest', '~> 1.5.0' ],
|
35
|
+
[ 'hashdot-test-daemon', '>= 1.0.0' ] ]
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
# Version/date consistency checks:
|
39
|
+
|
40
|
+
task :chk_init_v do
|
39
41
|
t.test_line_match( 'init/iyyov-daemon',
|
40
42
|
/^gem.+#{t.name}/, /= #{t.version}/ )
|
41
43
|
end
|
42
|
-
task :
|
44
|
+
task :chk_rcd_v do
|
45
|
+
t.test_line_match( 'config/init.d/iyyov', /^version=".+"/, /"#{t.version}"/ )
|
46
|
+
end
|
47
|
+
task :chk_cron_v do
|
48
|
+
t.test_line_match( 'config/crontab', /gems\/iyyov/,
|
49
|
+
/iyyov-#{t.version}-java/ )
|
50
|
+
end
|
51
|
+
task :chk_hist_v do
|
43
52
|
t.test_line_match( 'History.rdoc', /^==/, / #{t.version} / )
|
44
53
|
end
|
45
|
-
|
54
|
+
|
55
|
+
gem_tests = [ :chk_init_v, :chk_rcd_v, :chk_cron_v, :chk_hist_v ]
|
56
|
+
|
57
|
+
task :chk_hist_date do
|
46
58
|
t.test_line_match( 'History.rdoc', /^==/, /\([0-9\-]+\)$/ )
|
47
59
|
end
|
48
60
|
|
49
|
-
task :gem =>
|
50
|
-
task :tag =>
|
51
|
-
task :push => [
|
61
|
+
task :gem => gem_tests
|
62
|
+
task :tag => gem_tests + [ :chk_hist_date ]
|
63
|
+
task :push => [ :chk_hist_date ]
|
52
64
|
|
53
65
|
t.define_tasks
|
data/bin/iyyov-fg
CHANGED
File without changes
|
data/config/async.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
|
2
|
+
Iyyov.context do |c|
|
3
|
+
count = 0
|
4
|
+
log = SLF4J["hello"]
|
5
|
+
c.schedule_at( :name => "hello", :mode => :async, :period => 1.5 ) do
|
6
|
+
count += 1
|
7
|
+
sleep count
|
8
|
+
log.info "Hello after #{count}s"
|
9
|
+
:stop unless count <= 10 # Avoid killing ourselves.
|
10
|
+
end
|
11
|
+
end
|
data/config/crontab
ADDED
data/config/init.d/iyyov
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# iyyov Startup script for Iyyov monitoring daemon
|
4
|
+
#
|
5
|
+
# chkconfig: 2345 88 12
|
6
|
+
# description: Iyyov daemon
|
7
|
+
# processname: iyyov-daemon
|
8
|
+
# config: /opt/var/iyyov/jobs.rb
|
9
|
+
|
10
|
+
. /etc/rc.d/init.d/functions
|
11
|
+
|
12
|
+
# Gem home directory
|
13
|
+
# Set to match system "jgem environment path"
|
14
|
+
gem_home="/opt/jruby/gems"
|
15
|
+
|
16
|
+
# (Exact) Gem version of iyyov to run
|
17
|
+
version="1.0.1"
|
18
|
+
|
19
|
+
# User to run the daemon as (should own rundir)
|
20
|
+
user="iyyov"
|
21
|
+
|
22
|
+
# Running directory (for jobs.rb config, log, and pid file)
|
23
|
+
rundir="/opt/var/iyyov"
|
24
|
+
|
25
|
+
# Add PATH to jruby if non-standard
|
26
|
+
export PATH=/opt/bin:$PATH
|
27
|
+
|
28
|
+
prog="iyyov-daemon"
|
29
|
+
daemon="${gem_home}/gems/iyyov-${version}-java/init/${prog}"
|
30
|
+
config="${rundir}/jobs.rb"
|
31
|
+
pidfile="${rundir}/${prog}.pid"
|
32
|
+
|
33
|
+
RETVAL=0
|
34
|
+
|
35
|
+
start() {
|
36
|
+
[ -x "$daemon" ] || exit 5
|
37
|
+
[ -f "$config" ] || exit 6
|
38
|
+
[ -d "$rundir" ] || exit 7
|
39
|
+
|
40
|
+
echo -n $"Starting $prog: "
|
41
|
+
runuser -c "cd $rundir && $daemon $config" $user
|
42
|
+
RETVAL=$?
|
43
|
+
[ $RETVAL -eq 0 ] && success $"$prog startup" || failure $"$prog startup"
|
44
|
+
echo
|
45
|
+
}
|
46
|
+
|
47
|
+
status() {
|
48
|
+
if [ -f "$pidfile" ]; then
|
49
|
+
echo "Status $prog: running pid $(<$pidfile)"
|
50
|
+
else
|
51
|
+
echo "Status $prog: not running"
|
52
|
+
fi
|
53
|
+
}
|
54
|
+
|
55
|
+
reload() {
|
56
|
+
if [ -e "$pidfile" ]; then
|
57
|
+
touch $config
|
58
|
+
fi
|
59
|
+
}
|
60
|
+
|
61
|
+
stop() {
|
62
|
+
echo -n $"Shutting down $prog: "
|
63
|
+
killproc -p $pidfile $prog
|
64
|
+
RETVAL=$?
|
65
|
+
[ $RETVAL -eq 0 ] && success || failure
|
66
|
+
echo
|
67
|
+
return $RETVAL
|
68
|
+
}
|
69
|
+
|
70
|
+
case "$1" in
|
71
|
+
start)
|
72
|
+
start
|
73
|
+
;;
|
74
|
+
stop)
|
75
|
+
stop
|
76
|
+
;;
|
77
|
+
status)
|
78
|
+
status
|
79
|
+
;;
|
80
|
+
reload)
|
81
|
+
reload
|
82
|
+
;;
|
83
|
+
restart)
|
84
|
+
stop
|
85
|
+
start
|
86
|
+
RETVAL=$?
|
87
|
+
;;
|
88
|
+
condrestart)
|
89
|
+
[ -e $pidfile ] && restart
|
90
|
+
RETVAL=$?
|
91
|
+
;;
|
92
|
+
*)
|
93
|
+
echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"
|
94
|
+
RETVAL=1
|
95
|
+
esac
|
96
|
+
|
97
|
+
exit $RETVAL
|
data/config/jobs.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Iyyov.context do |c|
|
2
|
+
|
3
|
+
c.define_daemon do |d|
|
4
|
+
d.name = "hashdot-test-daemon"
|
5
|
+
d.version = "~> 1.0.0"
|
6
|
+
d.stop_on_exit = true
|
7
|
+
d.stop_delay = 2.0
|
8
|
+
d.log_rotate
|
9
|
+
d.log_rotate do |l|
|
10
|
+
l.max_size = 500
|
11
|
+
l.check_period = 21.0
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
c.schedule_at( :name => "hello", :period => 3.0 ) do
|
16
|
+
puts "hello every 3.0 seconds"
|
17
|
+
end
|
18
|
+
|
19
|
+
c.schedule_at( :name => "fixed",
|
20
|
+
:fixed_times => %w[ 00:03 1:00 2:00 3:00 4:00 12:00 ] ) do
|
21
|
+
puts "Fixed time task"
|
22
|
+
end
|
23
|
+
|
24
|
+
c.iyyov_log_rotate do |l|
|
25
|
+
l.max_size = 50_000
|
26
|
+
l.check_period = 17.0
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/config/load-all.rb
ADDED
data/init/iyyov-daemon
CHANGED
data/lib/iyyov/base.rb
CHANGED
data/lib/iyyov/daemon.rb
CHANGED
@@ -22,7 +22,7 @@ require 'iyyov/log_rotator'
|
|
22
22
|
module Iyyov
|
23
23
|
include RJack
|
24
24
|
|
25
|
-
# A daemon
|
25
|
+
# A daemon instance to start and monitor
|
26
26
|
class Daemon
|
27
27
|
|
28
28
|
# Name of this daemon. Must be unique in combination with any
|
@@ -101,13 +101,6 @@ module Iyyov
|
|
101
101
|
# Symbol (in STATES)
|
102
102
|
attr_reader :state
|
103
103
|
|
104
|
-
# Once do_first is called and provided a gem is found (gem version
|
105
|
-
# specified).
|
106
|
-
#
|
107
|
-
# Gem::Specification
|
108
|
-
# FIXME: May not want to expose this.
|
109
|
-
attr_reader :gem_spec
|
110
|
-
|
111
104
|
# States tracked
|
112
105
|
STATES = [ :begin, :up, :failed, :stopped ]
|
113
106
|
|
@@ -231,7 +224,6 @@ module Iyyov
|
|
231
224
|
end
|
232
225
|
|
233
226
|
def find_gem_spec
|
234
|
-
#FIXME: Use Gem.clear_paths to rescan.
|
235
227
|
@gem_spec ||= Gem.source_index.find_name( gem_name, version ).last
|
236
228
|
unless @gem_spec
|
237
229
|
raise( Gem::GemNotFoundException, "Missing gem #{gem_name} (#{version})" )
|
data/lib/iyyov/log_rotator.rb
CHANGED
data/lib/iyyov/task.rb
CHANGED
@@ -67,7 +67,10 @@ module Iyyov
|
|
67
67
|
|
68
68
|
@block = block
|
69
69
|
|
70
|
-
|
70
|
+
unless period || fixed_times
|
71
|
+
raise( SetupError,
|
72
|
+
"Task #{ opts.inspect } needs one of period or fixed_times" )
|
73
|
+
end
|
71
74
|
|
72
75
|
@log = SLF4J[ [ SLF4J[ self.class ].name, name ].compact.join( '.' ) ]
|
73
76
|
|
@@ -125,9 +128,13 @@ module Iyyov
|
|
125
128
|
|
126
129
|
def run_direct
|
127
130
|
@log.debug "Running."
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
+
begin
|
132
|
+
rc = ( @block.call if @block )
|
133
|
+
filter( rc )
|
134
|
+
rescue StandardError => e
|
135
|
+
@log.error( "Handled and stopped with: ", e )
|
136
|
+
:stop
|
137
|
+
end
|
131
138
|
end
|
132
139
|
|
133
140
|
def filter( rc )
|
data/lib/iyyov.rb
CHANGED
data/test/jobs-bad.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
no_method_by_this_name
|
data/test/jobs-dupe.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
#.hashdot.profile += jruby-shortlived
|
3
|
+
#--
|
4
|
+
# Copyright (C) 2010 David Kellum
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
7
|
+
# may not use this file except in compliance with the License. You
|
8
|
+
# may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
15
|
+
# implied. See the License for the specific language governing
|
16
|
+
# permissions and limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
TESTDIR = File.dirname( __FILE__ )
|
20
|
+
|
21
|
+
require File.join( TESTDIR, "setup" )
|
22
|
+
|
23
|
+
require 'iyyov'
|
24
|
+
|
25
|
+
class TestContext < MiniTest::Unit::TestCase
|
26
|
+
def setup
|
27
|
+
Iyyov.set_test_context
|
28
|
+
end
|
29
|
+
|
30
|
+
def teardown
|
31
|
+
Iyyov.context.shutdown
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_load_ruby_error
|
35
|
+
Iyyov.context do |c|
|
36
|
+
c.load_file( File.join( TESTDIR, "jobs-bad.rb" ) )
|
37
|
+
pass
|
38
|
+
end
|
39
|
+
pass
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_load_dupe_error
|
43
|
+
Iyyov.context do |c|
|
44
|
+
c.load_file( File.join( TESTDIR, "jobs-dupe.rb" ) )
|
45
|
+
pass
|
46
|
+
end
|
47
|
+
pass
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_load_samples
|
51
|
+
Dir[ File.join( TESTDIR, '..', 'config', '*.rb' ) ].each do |conf|
|
52
|
+
Iyyov.context { |c| c.load_file( conf ) }
|
53
|
+
Iyyov.context.shutdown
|
54
|
+
Iyyov.set_test_context
|
55
|
+
pass
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iyyov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- David Kellum
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-03-
|
12
|
+
date: 2010-03-12 23:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name: rjack-
|
16
|
+
name: rjack-slf4j
|
17
17
|
type: :runtime
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,7 @@ dependencies:
|
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: 1.2.0
|
74
74
|
version:
|
75
|
-
description:
|
76
|
-
Down-to-earth job control and monitoring. Features include:
|
77
|
-
|
78
|
-
* Runs on JRuby (no fork)
|
79
|
-
* Ruby-based configuration
|
80
|
-
* Gem packaged/Hashdot daemon based launching
|
81
|
-
* Log rotation with daemon SIGHUP support
|
82
|
-
* Fixed and periodic time job scheduling (basic cron replacement).
|
75
|
+
description: Down-to-earth job control and monitoring.
|
83
76
|
email:
|
84
77
|
- dek-oss@gravitext.com
|
85
78
|
executables:
|
@@ -106,7 +99,15 @@ files:
|
|
106
99
|
- lib/iyyov/scheduler.rb
|
107
100
|
- lib/iyyov/shutdown_handler.rb
|
108
101
|
- lib/iyyov/task.rb
|
102
|
+
- config/async.rb
|
103
|
+
- config/crontab
|
104
|
+
- config/jobs.rb
|
105
|
+
- config/load-all.rb
|
106
|
+
- config/init.d/iyyov
|
107
|
+
- test/jobs-bad.rb
|
108
|
+
- test/jobs-dupe.rb
|
109
109
|
- test/setup.rb
|
110
|
+
- test/test_context.rb
|
110
111
|
- test/test_daemon.rb
|
111
112
|
- test/test_scheduler.rb
|
112
113
|
has_rdoc: true
|
@@ -137,7 +138,8 @@ rubyforge_project: iyyov
|
|
137
138
|
rubygems_version: 1.3.5
|
138
139
|
signing_key:
|
139
140
|
specification_version: 3
|
140
|
-
summary: Down-to-earth job control and monitoring
|
141
|
+
summary: Down-to-earth job control and monitoring.
|
141
142
|
test_files:
|
143
|
+
- test/test_context.rb
|
142
144
|
- test/test_scheduler.rb
|
143
145
|
- test/test_daemon.rb
|