smartguard 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/smartguard CHANGED
@@ -1,23 +1,51 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'smartguard'
4
- require 'trollop'
4
+ require 'dante'
5
5
 
6
- opts = Trollop::options do
7
- opt :application, "Application to use", :type => :string
8
- opt :path, "Path to application", :type => :string
9
- opt :port, "Port to run DRB", :type => :integer, :default => 10000
6
+ runner = Dante::Runner.new('smartguard')
7
+ runner.description = "Smartkiosk services control daemon"
8
+
9
+ runner.with_options do |opts|
10
+ options[:port] = 10000
11
+
12
+ opts.on("-a", "--app APPLICATION", String, "Application to use") do |x|
13
+ options[:application] = x
14
+ end
15
+ opts.on("-x", "--path PATH", String, "Path to application") do |x|
16
+ options[:path] = x
17
+ end
18
+
19
+ opts.on("-p", "--port PORT", Integer, "Port to run DRB (default: #{options[:port]})") do |x|
20
+ options[:port] = x
21
+ end
22
+
23
+ opts.on("-s", "--start", "Start all services and exit") do |x|
24
+ options[:start] = x
25
+ end
26
+
27
+ opts.on("-S", "--stop", "Stop all services and exit") do |x|
28
+ options[:stop] = x
29
+ end
10
30
  end
11
31
 
12
- raise "You should specify application (--application)" if opts[:application].blank?
13
- raise "You should specify application path (--path)" if opts[:path].blank?
32
+ runner.execute do |opts|
33
+ abort "You should specify application (--app)" if opts[:application].blank?
34
+ abort "You should specify application path (--path)" if opts[:path].blank?
14
35
 
15
- application = Smartguard::Applications.const_get(opts[:application].camelize) rescue nil
36
+ application = Smartguard::Applications.const_get(opts[:application].camelize) rescue nil
16
37
 
17
- raise "Application `#{opts[:application]}` not supported" if application.nil?
38
+ abort "Application `#{opts[:application]}` not supported" if application.nil?
18
39
 
19
- application = application.new(opts[:path])
20
- application.warm_up
40
+ application = application.new(opts[:path])
21
41
 
22
- DRb.start_service("druby://localhost:#{opts[:port]}", application)
23
- DRb.thread.join
42
+ if opts[:stop]
43
+ application.stop_services
44
+ elsif opts[:start]
45
+ application.start_services
46
+ else
47
+ application.warm_up
48
+ DRb.start_service("druby://localhost:#{opts[:port]}", application)
49
+ DRb.thread.join
50
+ end
51
+ end
@@ -3,18 +3,18 @@ module Smartguard
3
3
  class Smartkiosk
4
4
  class Smartware < Smartguard::Process
5
5
  def initialize(path)
6
- @path = path
7
- @pids_path = path.join('tmp/pids')
8
- @logs_path = path.join('log')
6
+ @path = path
7
+ @pid_file = path.join('tmp/pids/smartware.pid')
8
+ @log_file = path.join('log/smartware.log')
9
9
  end
10
10
 
11
11
  def pid
12
- File.read("#{@pids_path}/smartware.pid").to_i rescue nil
12
+ File.read(@pid_file).to_i rescue nil
13
13
  end
14
14
 
15
15
  def start
16
16
  Logging.logger.info "Starting smartware"
17
- run @path, "bundle exec smartware piddir=#{@pids_path} logdir=#{@logs_path} &"
17
+ run @path, "bundle exec smartware -d --pid=#{@pid_file} --log=#{@log_file}"
18
18
  end
19
19
 
20
20
  def stop
@@ -45,7 +45,7 @@ module Smartguard
45
45
  start_services(path)
46
46
  end
47
47
 
48
- def restart_asyn(path=nil)
48
+ def restart_async(path=nil)
49
49
  Thread.new{ self.restart(path) }
50
50
  true
51
51
  end
@@ -1,3 +1,3 @@
1
1
  module Smartguard
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/smartguard.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'active_support/all'
2
+ require 'pathname'
2
3
  require 'fileutils'
3
4
  require 'drb'
4
5
 
data/smartguard.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_runtime_dependency "i18n"
21
21
  gem.add_runtime_dependency "active_support"
22
- gem.add_runtime_dependency "trollop"
22
+ gem.add_runtime_dependency "dante"
23
23
 
24
24
  gem.add_development_dependency "pry"
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartguard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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-12-14 00:00:00.000000000 Z
12
+ date: 2012-12-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
16
- requirement: &70236313873140 !ruby/object:Gem::Requirement
16
+ requirement: &70350512255040 !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: :runtime
23
23
  prerelease: false
24
- version_requirements: *70236313873140
24
+ version_requirements: *70350512255040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: active_support
27
- requirement: &70236313872100 !ruby/object:Gem::Requirement
27
+ requirement: &70350512253720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70236313872100
35
+ version_requirements: *70350512253720
36
36
  - !ruby/object:Gem::Dependency
37
- name: trollop
38
- requirement: &70236313871280 !ruby/object:Gem::Requirement
37
+ name: dante
38
+ requirement: &70350512252860 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70236313871280
46
+ version_requirements: *70350512252860
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &70236313870400 !ruby/object:Gem::Requirement
49
+ requirement: &70350512252360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70236313870400
57
+ version_requirements: *70350512252360
58
58
  description: Smartguard is the Smartkiosk services control daemon
59
59
  email:
60
60
  - boris@roundlake.ru