thin_service 0.0.4 → 0.0.5
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/CHANGELOG.md +4 -0
- data/bin/thin_service +14 -0
- data/lib/thin_service/command.rb +106 -25
- data/lib/thin_service/version.rb +1 -1
- metadata +6 -6
data/CHANGELOG.md
CHANGED
data/bin/thin_service
CHANGED
@@ -10,6 +10,18 @@ if ARGV.first == "start"
|
|
10
10
|
# use same ruby for bundle exec, in case global path is different
|
11
11
|
ENV["Path"] = RbConfig::CONFIG['bindir'] + ';' + ENV["Path"]
|
12
12
|
|
13
|
+
version = "> 0"
|
14
|
+
gem 'bundler', version
|
15
|
+
load Gem.bin_path('bundler', 'bundle', version)
|
16
|
+
elsif ARGV.first == "daemon"
|
17
|
+
ARGV.shift
|
18
|
+
ARGV.shift
|
19
|
+
Dir.chdir( ARGV.shift )
|
20
|
+
ARGV = ["exec"] + ARGV
|
21
|
+
|
22
|
+
# use same ruby for bundle exec, in case global path is different
|
23
|
+
ENV["Path"] = RbConfig::CONFIG['bindir'] + ';' + ENV["Path"]
|
24
|
+
|
13
25
|
version = "> 0"
|
14
26
|
gem 'bundler', version
|
15
27
|
load Gem.bin_path('bundler', 'bundle', version)
|
@@ -18,3 +30,5 @@ else
|
|
18
30
|
ThinService::Service.new(ARGV).run!
|
19
31
|
end
|
20
32
|
|
33
|
+
|
34
|
+
|
data/lib/thin_service/command.rb
CHANGED
@@ -16,7 +16,7 @@ module ThinService
|
|
16
16
|
module Command
|
17
17
|
|
18
18
|
BANNER = "Usage: thin_service <command> [options]"
|
19
|
-
COMMANDS = ['start', 'install', 'remove']
|
19
|
+
COMMANDS = ['start', 'install', "installdaemon", 'remove']
|
20
20
|
|
21
21
|
class Base
|
22
22
|
|
@@ -112,7 +112,45 @@ module ThinService
|
|
112
112
|
end
|
113
113
|
|
114
114
|
module Commands
|
115
|
+
|
116
|
+
module ServiceInstall
|
117
|
+
def validate_thin_service_exe
|
118
|
+
# check if thin_service.exe is in ruby bindir.
|
119
|
+
gem_root = File.join(File.dirname(__FILE__), "..", "..")
|
120
|
+
gem_executable = File.join(gem_root, "resource/thin_service_wrapper.exe")
|
121
|
+
bindir_executable = File.join(RbConfig::CONFIG['bindir'], '/thin_service_wrapper.exe')
|
122
|
+
|
123
|
+
unless File.exist?(bindir_executable)
|
124
|
+
STDERR.puts "** Copying native thin_service executable..."
|
125
|
+
FileUtils.cp gem_executable, bindir_executable rescue nil
|
126
|
+
end
|
127
|
+
|
128
|
+
unless FileUtils.compare_file(bindir_executable, gem_executable)
|
129
|
+
STDERR.puts "** Updating native thin_service executable..."
|
130
|
+
FileUtils.rm_f bindir_executable rescue nil
|
131
|
+
FileUtils.cp gem_executable, bindir_executable rescue nil
|
132
|
+
end
|
133
|
+
|
134
|
+
bindir_executable
|
135
|
+
end
|
136
|
+
|
137
|
+
def add_service( svc_name, svc_display, argv)
|
138
|
+
begin
|
139
|
+
ServiceManager.create(
|
140
|
+
svc_name,
|
141
|
+
svc_display,
|
142
|
+
argv.join(' ')
|
143
|
+
)
|
144
|
+
puts "#{svc_display} service created."
|
145
|
+
rescue ServiceManager::CreateError => e
|
146
|
+
puts "There was a problem installing the service:"
|
147
|
+
puts e
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
115
152
|
class Install < ThinService::Command::Base
|
153
|
+
include ServiceInstall
|
116
154
|
|
117
155
|
def configure
|
118
156
|
options [
|
@@ -167,20 +205,7 @@ module ThinService
|
|
167
205
|
|
168
206
|
def run
|
169
207
|
# check if thin_service.exe is in ruby bindir.
|
170
|
-
|
171
|
-
gem_executable = File.join(gem_root, "resource/thin_service_wrapper.exe")
|
172
|
-
bindir_executable = File.join(RbConfig::CONFIG['bindir'], '/thin_service_wrapper.exe')
|
173
|
-
|
174
|
-
unless File.exist?(bindir_executable)
|
175
|
-
STDERR.puts "** Copying native thin_service executable..."
|
176
|
-
FileUtils.cp gem_executable, bindir_executable rescue nil
|
177
|
-
end
|
178
|
-
|
179
|
-
unless FileUtils.compare_file(bindir_executable, gem_executable)
|
180
|
-
STDERR.puts "** Updating native thin_service executable..."
|
181
|
-
FileUtils.rm_f bindir_executable rescue nil
|
182
|
-
FileUtils.cp gem_executable, bindir_executable rescue nil
|
183
|
-
end
|
208
|
+
bindir_executable = validate_thin_service_exe
|
184
209
|
|
185
210
|
# build the command line
|
186
211
|
argv = []
|
@@ -208,20 +233,76 @@ module ThinService
|
|
208
233
|
# concat remaining non-parsed ARGV
|
209
234
|
argv.concat(ARGV)
|
210
235
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
236
|
+
add_service( @svc_name, @svc_display, argv)
|
237
|
+
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
class Installdaemon < ThinService::Command::Base
|
243
|
+
include ServiceInstall
|
244
|
+
|
245
|
+
def configure
|
246
|
+
options [
|
247
|
+
['-N', '--name SVC_NAME', "Required name for the service to be registered/installed.", :@svc_name, nil],
|
248
|
+
['-D', '--display SVC_DISPLAY', "Adjust the display name of the service.", :@svc_display, nil],
|
249
|
+
['-t', '--task TASK', "Which task to run", :@command, "rake tm:background:start"],
|
250
|
+
['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, Dir.pwd],
|
251
|
+
]
|
252
|
+
end
|
253
|
+
|
254
|
+
def validate
|
255
|
+
@cwd = File.expand_path(@cwd)
|
256
|
+
valid_dir? @cwd, "Invalid path to change to: #@cwd"
|
257
|
+
|
258
|
+
# change there to start, then we'll have to come back after daemonize
|
259
|
+
Dir.chdir(@cwd)
|
260
|
+
|
261
|
+
valid? @svc_name != nil, "A service name is mandatory."
|
262
|
+
valid? !ServiceManager.exist?(@svc_name), "The service already exist, please remove it first."
|
263
|
+
|
264
|
+
# default service display to service name
|
265
|
+
@svc_display = @svc_name if !@svc_display
|
266
|
+
|
267
|
+
# start with the premise of app really exist.
|
268
|
+
app_exist = true
|
269
|
+
%w{app config log}.each do |path|
|
270
|
+
if !File.directory?(File.join(@cwd, path))
|
271
|
+
app_exist = false
|
272
|
+
break
|
273
|
+
end
|
221
274
|
end
|
275
|
+
|
276
|
+
valid? app_exist == true, "The path you specified isn't a valid Rails application."
|
277
|
+
|
278
|
+
return @valid
|
279
|
+
end
|
280
|
+
|
281
|
+
def run
|
282
|
+
bindir_executable = validate_thin_service_exe
|
283
|
+
|
284
|
+
# build the command line
|
285
|
+
argv = []
|
286
|
+
|
287
|
+
# start using the native executable
|
288
|
+
argv << '"' + bindir_executable + '"'
|
289
|
+
|
290
|
+
# force indication of daemon mode
|
291
|
+
argv << "daemon"
|
292
|
+
|
293
|
+
# now the options
|
294
|
+
argv << "-c \"#{@cwd}\""
|
295
|
+
argv << "\"#{@command}\""
|
296
|
+
|
297
|
+
|
298
|
+
# concat remaining non-parsed ARGV
|
299
|
+
argv.concat(ARGV)
|
300
|
+
|
301
|
+
add_service( @svc_name, @svc_display, argv)
|
222
302
|
end
|
223
303
|
end
|
224
304
|
|
305
|
+
|
225
306
|
module ServiceValidation
|
226
307
|
def configure
|
227
308
|
options [
|
data/lib/thin_service/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thin_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05
|
12
|
+
date: 2012-09-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &25651368 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *25651368
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &25650372 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *25650372
|
36
36
|
description: Runs Thin as a Windows Service - based on mongrel_service
|
37
37
|
email:
|
38
38
|
- gsmedley@kanayo.com
|