Class: Jettr::Command

Inherits:
Thor
  • Object
show all
Defined in:
lib/jettr/command.rb

Instance Method Summary collapse

Instance Method Details

#start(path = ".") ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/jettr/command.rb', line 15

def start(path=".")
  config = nil
  config_file = File.join(path,"jettr.yaml")
  if File.exist?(config_file)
    config = Jettr::Config.new(:config_file => config_file)
  else
    config = Jettr::Config.new({
      :server => {
        :port => options[:port]
      },
      :apps => [
        {
          :type => options[:type],
          :app_path => path,
          :app_uri => options[:uri]
        }
      ]
    })
  end
  
  if(options[:daemon])
    d = Jettr::Akuma::Daemon.new
    pid_file = File.expand_path(options[:pid] || File.join(path,'tmp','run',"jettr.pid"))
    if(d.daemonized?)
      if File.exist?(pid_file)
        puts "Pid file alread exists at: #{pid_file}"
        puts "run `jettr stop #{pid_file}` to ensure the process has been stopped."
        exit 1
      end
      FileUtils.mkdir_p File.dirname(pid_file)
      puts "PID File: #{pid_file}"
      d.init(pid_file)
    else
      d.daemonize()
      exit 0
    end
  end
  server = config.create_server
  puts "Starting Server..."
  server.start
end

#stop(path = '.') ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/jettr/command.rb', line 58

def stop(path='.')
  pid_file = File.directory?(path) ? File.join(path, 'tmp','run','jettr.pid') : path
  unless File.exist?(pid_file)
    puts "Pid file not found: #{pid_file}"
    exit 1
  end
  File.open(pid_file) do |file|
    pid = file.read.strip.to_i
    res = Process.kill("SIGINT", pid)
    puts "Jettr process #{pid} was killed with response #{res}"
  end
  FileUtils.rm_rf pid_file
end