asmodai 0.1.3 → 0.1.4

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/lib/asmodai.rb CHANGED
@@ -27,4 +27,5 @@ module Asmodai
27
27
  require 'asmodai/info'
28
28
  require 'asmodai/logging'
29
29
  require 'asmodai/daemon'
30
+ require 'asmodai/version'
30
31
  end
data/lib/asmodai/cli.rb CHANGED
@@ -22,25 +22,32 @@ class Asmodai::CLI < Thor
22
22
  end
23
23
 
24
24
  desc "install", "Installs startup scripts to /etc/init.d"
25
- method_option :rvm, :type => :boolean,
26
- :desc => "Create an rvm-wrapper for asmodai"
25
+ method_option :force, :type => :boolean,
26
+ :desc => "Overwrite a given init.d-file"
27
27
  method_option :autostart,
28
28
  :type => :boolean,
29
29
  :desc => %{If you provide this, startup-links will be generated for the given runlevel. This is currently only supported on Debian/Ubuntu.}
30
+
30
31
  def install
31
32
  @info = Asmodai::Info.current
32
33
  @asmodai = "asmodai"
34
+ rvm_ruby_string = (ENV['rvm_ruby_string'] || "")
33
35
 
34
- if options[:rvm]
35
- wrapper_cmd="rvm wrapper #{ENV['rvm_ruby_string']} bootup asmodai"
36
- @asmodai=`which bootup_asmodai`.strip
36
+ if @info.rvm_environment?
37
+ @asmodai=Pathname.new(@info.rvm_wrapper_path)
38
+ if !@asmodai.exist?
39
+ @info.execute_sudo_checked("rvm wrapper #{@info.rvm_ruby_string} bootup asmodai")
40
+ end
37
41
  end
38
-
39
42
  path = "/etc/init.d/#{@info.daemon_name}"
43
+
44
+ if options[:force]
45
+ FileUtils.rm_f(path)
46
+ end
47
+
40
48
  template "templates/init_d.erb", path
41
49
  system "chmod a+x #{path}"
42
50
 
43
-
44
51
  if options[:autostart]
45
52
  if (update_bin=`which update-rc.d`.strip).blank?
46
53
  warn "update-rc.d was not found. Omitting autostart installation."
@@ -49,13 +56,13 @@ class Asmodai::CLI < Thor
49
56
  end
50
57
  end
51
58
  end
52
-
59
+
53
60
  desc "foreground", "Runs the daemon in foreground logging to stdout"
54
61
  def foreground
55
62
  instance=Asmodai::Info.current.daemon_class.new
56
63
  instance.foreground
57
64
  end
58
-
65
+
59
66
  desc "start", "Runs the daemon in the background"
60
67
  def start
61
68
  klass = Asmodai::Info.current.daemon_class
@@ -94,4 +101,10 @@ class Asmodai::CLI < Thor
94
101
  klass = Asmodai::Info.current.daemon_class
95
102
  exec "irb -r rubygems -r asmodai -r ./#{klass.daemon_name}"
96
103
  end
104
+
105
+ desc "version", "Prints Asmodai's version and exists"
106
+ def version
107
+ puts "Asmodai version #{Asmodai::VERSION}"
108
+ end
109
+ map %w(-v --version) => :version
97
110
  end
data/lib/asmodai/info.rb CHANGED
@@ -25,6 +25,23 @@ class Asmodai::Info
25
25
  daemon_name.camelize
26
26
  end
27
27
 
28
+ def rvm_environment?
29
+ !rvm_ruby_string.empty?
30
+ end
31
+
32
+ def rvm_ruby_string
33
+ execute_sudo_checked("env | grep rvm_ruby_string | grep -v SUDO").strip
34
+ end
35
+
36
+ def rvm_path
37
+ execute_sudo_checked(
38
+ "env | grep rvm_path | grep -v SUDO").strip.split("=").last
39
+ end
40
+
41
+ def rvm_wrapper_path
42
+ File.join(rvm_path, "bin/bootup_asmodai")
43
+ end
44
+
28
45
  # Returns the class of the Daemon
29
46
  def daemon_class
30
47
  require "./#{daemon_name}"
@@ -40,4 +57,23 @@ class Asmodai::Info
40
57
  def base_file_owner
41
58
  Etc.getpwuid(Pathname.new(base_file).stat.uid)
42
59
  end
60
+
61
+ # Return the sudoer if present, false otherwise
62
+ def run_as_sudo?
63
+ if ENV['USER']=='root' and (su=ENV['SUDO_USER'])
64
+ su
65
+ else
66
+ false
67
+ end
68
+ end
69
+
70
+ # Executes cmd in the context of the user, even if asmodai
71
+ # is called sudoed
72
+ def execute_sudo_checked(cmd)
73
+ if (su=run_as_sudo?)
74
+ `sudo -u #{su} bash -l -c '#{cmd}'`.strip
75
+ else
76
+ `#{cmd}`.strip
77
+ end
78
+ end
43
79
  end
@@ -1,3 +1,3 @@
1
1
  module Asmodai
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sebastian Morawietz
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-24 00:00:00 +01:00
17
+ date: 2011-01-25 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency