thin-service 0.0.1

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.
File without changes
Binary file
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thin-service'
4
+ ThinService::Runner.new(ARGV).run!
@@ -0,0 +1,97 @@
1
+ require 'optparse'
2
+
3
+ module ThinService
4
+
5
+ class Runner
6
+ # list of available commands
7
+ COMMANDS = %w(install delete)
8
+
9
+ # command to be runned
10
+ attr_accessor :command
11
+
12
+ # parsed options
13
+ attr_accessor :options
14
+
15
+ def initialize(argv)
16
+ @argv = argv
17
+
18
+ @options = {
19
+ :ruby_executables => %w(ruby.exe jruby.exe),
20
+ :port => 80,
21
+ :environment => 'production',
22
+ :service_path => "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\",
23
+ :service_key => 'Parameters',
24
+ :directory => Dir.pwd
25
+ }
26
+
27
+ parse!
28
+ end
29
+
30
+ def parser
31
+ @parser ||= OptionParser.new do |opts|
32
+ opts.banner = "Usage: thin-service #{COMMANDS.join('|')} [options]"
33
+
34
+ opts.separator ""
35
+ opts.separator "Options:"
36
+
37
+ opts.on("-p", "--port PORT", "use PORT (default: #{@options[:port]})") { |port| @options[:port] = port }
38
+ opts.on("-d", "--directory DIR", "Project directory (default: #{@options[:directory]})") { |directory| @options[:directory] = directory }
39
+ opts.on("-e", "--environment ENVIRONMENT", "use ENVIRONMENT (default: #{@options[:environment]})") { |environment| @options[:environment] = environment }
40
+ opts.on("-h", "--help", "Show this message") { puts opts; exit }
41
+ end
42
+ end
43
+
44
+ def parse!
45
+ parser.parse! @argv
46
+ @command = @argv.shift
47
+ @service = @argv.shift
48
+ end
49
+
50
+ def run!
51
+ if ThinService::Runner::COMMANDS.include?(@command) && respond_to?(@command)
52
+ send(@command)
53
+ else
54
+ raise ThinService::CommandNotSupported
55
+ end
56
+ end
57
+
58
+ protected
59
+
60
+ def install
61
+ # get paths
62
+ file_path = windows_path(@options[:directory] || Dir.pwd)
63
+ ruby_path = windows_path(find_ruby_path)
64
+ svranyexe = windows_path(File.join(File.expand_path('../..', __FILE__), 'bin', 'srvany.exe'))
65
+
66
+ # default display name
67
+ display_name = @options[:display_name] || File.basename(file_path)
68
+
69
+ # windows command
70
+ system("sc create \"#{@service}\" binPath= \"#{svranyexe}\" DisplayName= \"#{@service}\"")
71
+
72
+ system("reg add \"#{@options[:service_path]}#{@service}\\#{@options[:service_key]}\" ")
73
+ system("reg add \"#{@options[:service_path]}#{@service}\\#{@options[:service_key]}\" /v Application /t REG_SZ /d \"#{ruby_path}\"")
74
+ system("reg add \"#{@options[:service_path]}#{@service}\\#{@options[:service_key]}\" /v AppDirectory /t REG_SZ /d \"#{file_path}\"")
75
+ system("reg add \"#{@options[:service_path]}#{@service}\\#{@options[:service_key]}\" /v AppParameters /t REG_SZ /d \"#{File.dirname(ruby_path)}\\thin start -p #{@options[:port]} -e #{@options[:environment]}\"")
76
+ end
77
+
78
+ def delete
79
+ # windows command
80
+ system('sc delete ' + @service)
81
+ end
82
+
83
+ def find_ruby_path
84
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
85
+ @options[:ruby_executables].each do |exe|
86
+ file = "#{path}\\#{exe}"
87
+ return file if File.executable?(file)
88
+ end
89
+ end
90
+ end
91
+
92
+ def windows_path(path)
93
+ path.gsub('/', '\\')
94
+ end
95
+
96
+ end
97
+ end
@@ -0,0 +1,16 @@
1
+ module ThinService
2
+ class PlatformNotSupported < RuntimeError; end
3
+ class CommandNotSupported < RuntimeError; end
4
+
5
+ NAME = "thin-service"
6
+
7
+ MAJOR = 0
8
+ MINOR = 0
9
+ BUILD = 1
10
+
11
+ VERSION = [MAJOR, MINOR, BUILD].join('.')
12
+
13
+ def self.windows?
14
+ RUBY_PLATFORM =~ /mswin|mingw/
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thin-service
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christian Blais
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thin
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ description: An easy way to create thin services
31
+ email: christ.blais@gmail.com
32
+ executables:
33
+ - thin-service
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - README.md
38
+ - bin/srvany.exe
39
+ - bin/thin-service
40
+ - lib/thin-service.rb
41
+ - lib/version.rb
42
+ homepage: https://github.com/christianblais/thin-service
43
+ licenses:
44
+ - Ruby
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.7
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.23
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: An easy way to create thin services
67
+ test_files: []