Class: Asmodai::Info
- Inherits:
-
Object
- Object
- Asmodai::Info
- Defined in:
- lib/asmodai/info.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#base_file ⇒ Object
Returns the generated base file where the daemon class is declared in.
- #base_file_owner ⇒ Object
- #call_wrapper(argument) ⇒ Object
-
#daemon_class ⇒ Object
Returns the class of the Daemon.
-
#daemon_class_name ⇒ Object
Returns the camelized daemon name.
-
#daemon_name ⇒ Object
Returns the name of the daemon which is equal to the name of the directory, the daemon lives in.
-
#execute_sudo_checked(cmd) ⇒ Object
Executes cmd in the context of the user, even if asmodai is called sudoed.
- #gem_home ⇒ Object
-
#initialize(path = Asmodai.root) ⇒ Info
constructor
A new instance of Info.
- #ruby_exe_path ⇒ Object
-
#run_as_sudo? ⇒ Boolean
Return the sudoer if present, false otherwise.
- #wrapped_commands ⇒ Object
Constructor Details
#initialize(path = Asmodai.root) ⇒ Info
Returns a new instance of Info.
13 14 15 |
# File 'lib/asmodai/info.rb', line 13 def initialize(path=Asmodai.root) self.path = path end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/asmodai/info.rb', line 5 def path @path end |
Class Method Details
.current ⇒ Object
8 9 10 |
# File 'lib/asmodai/info.rb', line 8 def current @current||=self.new end |
Instance Method Details
#base_file ⇒ Object
Returns the generated base file where the daemon class is declared in.
50 51 52 |
# File 'lib/asmodai/info.rb', line 50 def base_file path.join("#{daemon_name}.rb") end |
#base_file_owner ⇒ Object
54 55 56 |
# File 'lib/asmodai/info.rb', line 54 def base_file_owner Etc.getpwuid(Pathname.new(base_file).stat.uid) end |
#call_wrapper(argument) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/asmodai/info.rb', line 28 def call_wrapper(argument) command="#{ruby_exe_path} ./script/asmodai #{argument}" function_body=<<-FUNCTION_END do_#{argument}() { cd #{path} sudo -u #{base_file_owner.name} bash -c "GEM_HOME=#{gem_home} #{command}" } FUNCTION_END end |
#daemon_class ⇒ Object
Returns the class of the Daemon
43 44 45 46 |
# File 'lib/asmodai/info.rb', line 43 def daemon_class require "./#{daemon_name}" eval(daemon_class_name) end |
#daemon_class_name ⇒ Object
Returns the camelized daemon name
24 25 26 |
# File 'lib/asmodai/info.rb', line 24 def daemon_class_name daemon_name.camelize end |
#daemon_name ⇒ Object
Returns the name of the daemon which is equal to the name of the directory, the daemon lives in
19 20 21 |
# File 'lib/asmodai/info.rb', line 19 def daemon_name File.basename(self.path) end |
#execute_sudo_checked(cmd) ⇒ Object
Executes cmd in the context of the user, even if asmodai is called sudoed
81 82 83 84 85 86 87 |
# File 'lib/asmodai/info.rb', line 81 def execute_sudo_checked(cmd) if (su=run_as_sudo?) `sudo -u #{su} bash -l -c '#{cmd}'`.strip else `#{cmd}`.strip end end |
#gem_home ⇒ Object
63 64 65 66 67 68 |
# File 'lib/asmodai/info.rb', line 63 def gem_home if (path=ENV['GEM_HOME']).blank? path=Gem.dir end path end |
#ruby_exe_path ⇒ Object
58 59 60 61 |
# File 'lib/asmodai/info.rb', line 58 def ruby_exe_path File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']). sub(/.*\s.*/m, '"\&"') end |
#run_as_sudo? ⇒ Boolean
Return the sudoer if present, false otherwise
71 72 73 74 75 76 77 |
# File 'lib/asmodai/info.rb', line 71 def run_as_sudo? if ENV['USER']=='root' and (su=ENV['SUDO_USER']) su else false end end |
#wrapped_commands ⇒ Object
38 39 40 |
# File 'lib/asmodai/info.rb', line 38 def wrapped_commands %w(start stop reopen foreground) end |