Class: Asmodai::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/asmodai/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



5
6
7
# File 'lib/asmodai/cli.rb', line 5

def app_name
  @app_name
end

Class Method Details

.source_rootObject



7
8
9
# File 'lib/asmodai/cli.rb', line 7

def self.source_root
  File.join(File.dirname(__FILE__), "generator")
end

Instance Method Details

#consoleObject



90
91
92
93
# File 'lib/asmodai/cli.rb', line 90

def console
  klass = Asmodai::Info.current.daemon_class
  exec "irb -Ilib -r rubygems -r asmodai -r ./#{klass.daemon_name}"
end

#foregroundObject



51
52
53
54
# File 'lib/asmodai/cli.rb', line 51

def foreground
  instance=Asmodai::Info.current.daemon_class.new
  instance.foreground
end

#installObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/asmodai/cli.rb', line 29

def install
  @info = Asmodai::Info.current
  @asmodai = "asmodai"
  path = "/etc/init.d/#{@info.daemon_name}"
  IO.popen "sudo bash -c \"cat > #{path}; chmod a+x #{path}\"", "r+" do |io|
    template_path = File.join(
      File.dirname(__FILE__), "generator/templates/init_d.erb")

    io.puts ERB.new(File.read(template_path)).result(binding)
    io.close
  end

  if options[:autostart]
    if (update_bin=`which update-rc.d`.strip).blank?
      warn "update-rc.d was not found. Omitting autostart installation."
    else
      `#{update_bin} #{@info.daemon_name} defaults`
    end
  end
end

#new(name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/asmodai/cli.rb', line 12

def new(name)
  @app_name=name
  empty_directory "#{name}/log"
  empty_directory "#{name}/lib"
  empty_directory "#{name}/script"
  template 'templates/daemon.rb.erb', "#{name}/#{name}.rb"
  copy_file 'templates/Gemfile', "#{name}/Gemfile"
  template 'templates/asmodai.erb', "#{name}/script/asmodai"
  template 'templates/launcher.erb', "#{name}/script/launcher"
  FileUtils.chmod 0755, "#{name}/script/asmodai"
end

#startObject



57
58
59
60
61
62
63
64
65
# File 'lib/asmodai/cli.rb', line 57

def start
  klass = Asmodai::Info.current.daemon_class
  puts "Starting #{klass.daemon_name}"
  if klass.start
    puts "Ok."
  else
    puts "#{klass.daemon_name} seems to be already running"
  end
end

#statusObject



80
81
82
83
84
85
86
87
# File 'lib/asmodai/cli.rb', line 80

def status
  klass = Asmodai::Info.current.daemon_class
  if !klass.is_running?
    puts "#{klass.daemon_name} doesn't seem to be running"
  else
    puts "#{klass.daemon_name} runs with pid #{klass.pid}"
  end      
end

#stopObject



68
69
70
71
72
73
74
75
76
77
# File 'lib/asmodai/cli.rb', line 68

def stop
  Asmodai::Info.current.daemon_class.tap do |klass|
    puts "Stopping #{klass.daemon_name}"
    if klass.terminate
      puts "Ok."
    else
      puts "#{klass.daemon_name} doesn't seem to be running."
    end
  end
end

#versionObject



96
97
98
# File 'lib/asmodai/cli.rb', line 96

def version
  puts "Asmodai version #{Asmodai::VERSION}"
end