ar_mailer_service 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 +4 -0
- data/Manifest.txt +11 -0
- data/README.txt +82 -0
- data/Rakefile +20 -0
- data/bin/ar_sendmail_daemon +6 -0
- data/bin/ar_sendmail_service +5 -0
- data/lib/ar_mailer_service/ar_sendmail.rb +24 -0
- data/lib/ar_mailer_service/daemon.rb +30 -0
- data/lib/ar_mailer_service/service.rb +166 -0
- data/lib/ar_mailer_service.rb +3 -0
- data/test/test_ar_mailer_service.rb +60 -0
- metadata +86 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
bin/ar_sendmail_daemon
|
6
|
+
bin/ar_sendmail_service
|
7
|
+
lib/ar_mailer_service.rb
|
8
|
+
lib/ar_mailer_service/ar_sendmail.rb
|
9
|
+
lib/ar_mailer_service/service.rb
|
10
|
+
lib/ar_mailer_service/daemon.rb
|
11
|
+
test/test_ar_mailer_service.rb
|
data/README.txt
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
ar_mailer_service
|
2
|
+
by Adam Meehan
|
3
|
+
http://armailerservice.rubyforge.org/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A windows service for the ar_mailer gem by Eric Hodel (http://segment7.com/) from the Seattle.rb https://rubyforge.org/projects/seattlerb/.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
Creates a windows service to run the ar_sendmail script from the ar_mailer gem using a subset of settings which apply to a service.
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
To install as windows service:
|
16
|
+
|
17
|
+
ar_sendmail_service install -N rails_app_mailer -c c:/my/app/root -e production
|
18
|
+
|
19
|
+
For an explanation of options see the ar_mailer gem by running
|
20
|
+
|
21
|
+
ar_sendmail -h
|
22
|
+
|
23
|
+
only the -c, -e, -b, --delay and --max-age options apply to the service
|
24
|
+
|
25
|
+
|
26
|
+
To remove service:
|
27
|
+
|
28
|
+
ar_sendmail_service remove -N rails_app_mailer
|
29
|
+
|
30
|
+
OR
|
31
|
+
|
32
|
+
sc.exe delete rails_app_mailer (Windows service controller)
|
33
|
+
|
34
|
+
To start service:
|
35
|
+
|
36
|
+
ar_sendmail_service start -N rails_app_mailer
|
37
|
+
|
38
|
+
OR
|
39
|
+
|
40
|
+
net start rails_app_mailer
|
41
|
+
|
42
|
+
To stop service:
|
43
|
+
|
44
|
+
ar_sendmail_service stop -N rails_app_mailer
|
45
|
+
|
46
|
+
OR
|
47
|
+
|
48
|
+
net stop rails_app_mailer
|
49
|
+
|
50
|
+
== REQUIREMENTS:
|
51
|
+
|
52
|
+
ar_mailer gem
|
53
|
+
win32-service gem required to run as service
|
54
|
+
|
55
|
+
== INSTALL:
|
56
|
+
|
57
|
+
gem install ar_mailer_service
|
58
|
+
|
59
|
+
== LICENSE:
|
60
|
+
|
61
|
+
(The MIT License)
|
62
|
+
|
63
|
+
Copyright (c) 2007 Adam Meehan
|
64
|
+
|
65
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
66
|
+
a copy of this software and associated documentation files (the
|
67
|
+
'Software'), to deal in the Software without restriction, including
|
68
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
69
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
70
|
+
permit persons to whom the Software is furnished to do so, subject to
|
71
|
+
the following conditions:
|
72
|
+
|
73
|
+
The above copyright notice and this permission notice shall be
|
74
|
+
included in all copies or substantial portions of the Software.
|
75
|
+
|
76
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
77
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
78
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
79
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
80
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
81
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
82
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/ar_mailer_service.rb'
|
6
|
+
|
7
|
+
Hoe.new('ar_mailer_service', ARMailerService::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'armailersvc'
|
9
|
+
p.author = 'Adam Meehan'
|
10
|
+
p.email = 'adam.meehan@gmail.com'
|
11
|
+
p.summary = 'A windows service for the ar_mailer gem'
|
12
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
13
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
14
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
15
|
+
p.extra_deps << ['win32-service', '>= 0.5.2']
|
16
|
+
p.extra_deps << ['ar_mailer', '>= 1.3.1']
|
17
|
+
p.remote_rdoc_dir = ''
|
18
|
+
end
|
19
|
+
|
20
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'action_mailer/ar_sendmail'
|
2
|
+
|
3
|
+
module ActionMailer
|
4
|
+
|
5
|
+
# The ARMailer class which does all the work defined in the ar_mailer gem.
|
6
|
+
class ARSendmail
|
7
|
+
|
8
|
+
# This class method is required to allow the command args to be processed
|
9
|
+
# and return an instance of ARSendmail. The :Once option is set so that
|
10
|
+
# control is returned to the containing object after processing the mail,
|
11
|
+
# in this case the daemon object. Otherwise it is not possible to stop
|
12
|
+
# the service once started, as ar_sendmail is designed to run standalone
|
13
|
+
# and exit on the TERM or INT signal which the windows service controller
|
14
|
+
# does not send.
|
15
|
+
#
|
16
|
+
def self.setup(args = ARGV)
|
17
|
+
options = process_args(args)
|
18
|
+
options[:Once] = true
|
19
|
+
new(options)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'ar_mailer_service/ar_sendmail'
|
2
|
+
require 'win32/service'
|
3
|
+
|
4
|
+
module ARMailerService
|
5
|
+
|
6
|
+
class Daemon < Win32::Daemon
|
7
|
+
attr_accessor :args, :mailer
|
8
|
+
|
9
|
+
def initialize(args = ARGV)
|
10
|
+
@args = args
|
11
|
+
end
|
12
|
+
|
13
|
+
# Create an ARSendmail instance using the command line options, when service
|
14
|
+
# is started.
|
15
|
+
def service_init
|
16
|
+
@mailer = ActionMailer::ARSendmail.setup(args)
|
17
|
+
end
|
18
|
+
|
19
|
+
# while the service is running it executes the ARSendmail run method
|
20
|
+
# every delay seconds, which sends any waiting mail.
|
21
|
+
def service_main
|
22
|
+
while running?
|
23
|
+
@mailer.run
|
24
|
+
# sleep for 1 second by the number of seconds in delay. This prevents process blocking in win32-service
|
25
|
+
@mailer.delay.times {sleep 1}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'win32/service'
|
3
|
+
|
4
|
+
module ARMailerService
|
5
|
+
class ServiceCommand
|
6
|
+
attr_reader :command, :options
|
7
|
+
|
8
|
+
def run(args)
|
9
|
+
@command = args.shift
|
10
|
+
@command = @command.dup.downcase if @command
|
11
|
+
|
12
|
+
parse(args)
|
13
|
+
@options
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse(args)
|
17
|
+
begin
|
18
|
+
options = {}
|
19
|
+
|
20
|
+
# This is a subset of options replicated from the ar_mailer gem
|
21
|
+
opts = OptionParser.new do |opts|
|
22
|
+
opts.banner = "Usage: ar_mailer_service <command> [options]"
|
23
|
+
opts.separator ""
|
24
|
+
opts.separator "Specific options:"
|
25
|
+
|
26
|
+
opts.on("-N", "--name SERVICE_NAME", String, "Config file with projects session files to check") do |name|
|
27
|
+
options[:ServiceName] = name
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on("-b", "--batch-size BATCH_SIZE",
|
31
|
+
"Maximum number of emails to send per delay",
|
32
|
+
"Default: Deliver all available emails", Integer) do |batch_size|
|
33
|
+
options[:BatchSize] = batch_size
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on( "--delay DELAY",
|
37
|
+
"Delay between checks for new mail",
|
38
|
+
"in the database",
|
39
|
+
"Default: #{options[:Delay]}", Integer) do |delay|
|
40
|
+
options[:Delay] = delay
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on( "--max-age MAX_AGE",
|
44
|
+
"Maxmimum age for an email. After this",
|
45
|
+
"it will be removed from the queue.",
|
46
|
+
"Set to 0 to disable queue cleanup.",
|
47
|
+
"Default: #{options[:MaxAge]} seconds", Integer) do |max_age|
|
48
|
+
options[:MaxAge] = max_age
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on("-c", "--chdir PATH",
|
52
|
+
"Use PATH for the application path",
|
53
|
+
"Default: #{options[:Chdir]}") do |path|
|
54
|
+
options[:Chdir] = path
|
55
|
+
end
|
56
|
+
|
57
|
+
opts.on("-e", "--environment RAILS_ENV",
|
58
|
+
"Set the RAILS_ENV constant",
|
59
|
+
"Default: #{options[:RailsEnv]}") do |env|
|
60
|
+
options[:RailsEnv] = env
|
61
|
+
end
|
62
|
+
|
63
|
+
opts.on("-t", "--table-name TABLE_NAME",
|
64
|
+
"Name of table holding emails",
|
65
|
+
"Used for both sendmail and",
|
66
|
+
"migration creation",
|
67
|
+
"Default: #{options[:TableName]}") do |name|
|
68
|
+
options[:TableName] = name
|
69
|
+
end
|
70
|
+
|
71
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
72
|
+
puts opts
|
73
|
+
exit
|
74
|
+
end
|
75
|
+
end
|
76
|
+
opts.parse!(args)
|
77
|
+
@options = options
|
78
|
+
validate_options
|
79
|
+
@options
|
80
|
+
rescue OptionParser::ParseError => e
|
81
|
+
puts e
|
82
|
+
puts opts
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def validate_options
|
87
|
+
errors = []
|
88
|
+
errors << "Service name is required (switch -N)" unless @options[:ServiceName]
|
89
|
+
errors << "App diretory is required (switch -c)" if !@options[:Chdir] && @command == 'install'
|
90
|
+
errors << "Rails environment is required (switch -e)" if !@options[:RailsEnv] && @command == 'install'
|
91
|
+
if errors.size > 0
|
92
|
+
puts "Error found."
|
93
|
+
puts errors.join("\n")
|
94
|
+
exit
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
class Service
|
101
|
+
attr_accessor :name
|
102
|
+
|
103
|
+
def install
|
104
|
+
svc = Win32::Service.new
|
105
|
+
begin
|
106
|
+
if Win32::Service.exists?(name)
|
107
|
+
puts "Service name '#{name}' already exists."
|
108
|
+
return
|
109
|
+
end
|
110
|
+
|
111
|
+
svc.create_service do |s|
|
112
|
+
s.service_name = name
|
113
|
+
s.display_name = name
|
114
|
+
s.binary_path_name = binary_path_name
|
115
|
+
end
|
116
|
+
|
117
|
+
svc.close
|
118
|
+
puts "ARMailer service '#{name}' installed."
|
119
|
+
rescue => e
|
120
|
+
puts e.inspect
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def start
|
125
|
+
Win32::Service.start(name)
|
126
|
+
end
|
127
|
+
|
128
|
+
def stop
|
129
|
+
Win32::Service.stop(name)
|
130
|
+
end
|
131
|
+
|
132
|
+
def remove
|
133
|
+
begin
|
134
|
+
Win32::Service.stop(name)
|
135
|
+
rescue
|
136
|
+
end
|
137
|
+
|
138
|
+
begin
|
139
|
+
Win32::Service.delete(name)
|
140
|
+
puts "'#{name}' service removed."
|
141
|
+
rescue => e
|
142
|
+
puts e.inspect
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
# Sets up the command with options to execute when the service starts
|
148
|
+
def binary_path_name
|
149
|
+
path = "#{Config::CONFIG['bindir']}/rubyw #{Config::CONFIG['bindir']}/ar_sendmail_daemon"
|
150
|
+
path << " -c #{@options[:Chdir]}"
|
151
|
+
path << " -e #{@options[:RailsEnv]}"
|
152
|
+
path << " -t #{@options[:TableName]}" if @options[:TableName]
|
153
|
+
path << " --delay #{@options[:Delay]}" if @options[:Delay]
|
154
|
+
path << " -b #{@options[:BatchSize]}" if @options[:BatchSize]
|
155
|
+
path << " --max-age #{@options[:MaxAge]}" if @options[:MaxAge]
|
156
|
+
path
|
157
|
+
end
|
158
|
+
|
159
|
+
def run(args)
|
160
|
+
command = ARMailerService::ServiceCommand.new
|
161
|
+
@options = command.run(args)
|
162
|
+
self.name = @options[:ServiceName]
|
163
|
+
self.send(command.command.to_sym)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'ar_mailer_service/ar_sendmail'
|
3
|
+
require 'ar_mailer_service/service'
|
4
|
+
require 'win32/service'
|
5
|
+
|
6
|
+
class TestARMailerService < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@service_name = 'test_rails_mailer'
|
10
|
+
@install_args = %w{install -N test_rails_mailer -c c:/test_app -e production -t Emails --delay 60 -b 10 --max-age 300}
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_ar_sendmail_class_has_setup_method
|
14
|
+
assert ActionMailer::ARSendmail.respond_to?(:setup)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_service_command_created_with_correct_values
|
18
|
+
sc = ARMailerService::ServiceCommand.new
|
19
|
+
sc.run( @install_args )
|
20
|
+
assert_equal 'install', sc.command
|
21
|
+
assert_equal 'test_rails_mailer', sc.options[:ServiceName]
|
22
|
+
assert_equal 60, sc.options[:Delay]
|
23
|
+
assert_equal 10, sc.options[:BatchSize]
|
24
|
+
assert_equal 300, sc.options[:MaxAge]
|
25
|
+
assert_equal 'production', sc.options[:RailsEnv]
|
26
|
+
assert_equal 'c:/test_app', sc.options[:Chdir]
|
27
|
+
assert_equal 'Emails', sc.options[:TableName]
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_service_created_and_has_correct_binary_path
|
31
|
+
ARMailerService::Service.new.run( @install_args.dup )
|
32
|
+
|
33
|
+
assert Win32::Service.exists?( @service_name )
|
34
|
+
svc = get_service @service_name
|
35
|
+
assert_match( /^#{ruby_bin_path} #{daemon_bin_path}/, svc.binary_path_name )
|
36
|
+
args_str = @install_args[3..-1].join(' ')
|
37
|
+
|
38
|
+
assert_match( /#{args_str}/, svc.binary_path_name )
|
39
|
+
|
40
|
+
Win32::Service.delete( @service_name )
|
41
|
+
end
|
42
|
+
|
43
|
+
def ruby_bin_path
|
44
|
+
"#{Config::CONFIG['bindir']}/rubyw"
|
45
|
+
end
|
46
|
+
|
47
|
+
def daemon_bin_path
|
48
|
+
"#{Config::CONFIG['bindir']}/ar_sendmail_daemon"
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_service(name)
|
52
|
+
svc = nil
|
53
|
+
Win32::Service.services { |s| svc = s if s.service_name == name }
|
54
|
+
svc
|
55
|
+
end
|
56
|
+
|
57
|
+
def teardown
|
58
|
+
Win32::Service.delete( @service_name ) rescue nil
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: ar_mailer_service
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-10-26 00:00:00 +10:00
|
8
|
+
summary: A windows service for the ar_mailer gem
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: adam.meehan@gmail.com
|
12
|
+
homepage: " by Adam Meehan"
|
13
|
+
rubyforge_project: armailersvc
|
14
|
+
description: "== FEATURES/PROBLEMS: Creates a windows service to run the ar_sendmail script from the ar_mailer gem using a subset of settings which apply to a service. == SYNOPSIS: To install as windows service:"
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Adam Meehan
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- bin/ar_sendmail_daemon
|
37
|
+
- bin/ar_sendmail_service
|
38
|
+
- lib/ar_mailer_service.rb
|
39
|
+
- lib/ar_mailer_service/ar_sendmail.rb
|
40
|
+
- lib/ar_mailer_service/service.rb
|
41
|
+
- lib/ar_mailer_service/daemon.rb
|
42
|
+
- test/test_ar_mailer_service.rb
|
43
|
+
test_files:
|
44
|
+
- test/test_ar_mailer_service.rb
|
45
|
+
rdoc_options:
|
46
|
+
- --main
|
47
|
+
- README.txt
|
48
|
+
extra_rdoc_files:
|
49
|
+
- History.txt
|
50
|
+
- Manifest.txt
|
51
|
+
- README.txt
|
52
|
+
executables:
|
53
|
+
- ar_sendmail_daemon
|
54
|
+
- ar_sendmail_service
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
dependencies:
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: win32-service
|
62
|
+
version_requirement:
|
63
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.5.2
|
68
|
+
version:
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ar_mailer
|
71
|
+
version_requirement:
|
72
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.3.1
|
77
|
+
version:
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: hoe
|
80
|
+
version_requirement:
|
81
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.3.0
|
86
|
+
version:
|