Class: SwissAdmin::Commands::Web

Inherits:
Thor
  • Object
show all
Defined in:
lib/swiss_admin/cli/web_cli.rb

Instance Method Summary collapse

Instance Method Details

#startObject



30
31
32
33
34
35
36
# File 'lib/swiss_admin/cli/web_cli.rb', line 30

def start
  $stdout.puts "Starting..."
  Rack::Server.start(app: SwissAdmin::HostInfo, 
                     daemonize: true, 
                     pid: options[:pid_file] || "/tmp/swissadmin.pid",
                     Port: options[:port])
end

#statusObject



56
57
58
59
60
61
62
63
64
# File 'lib/swiss_admin/cli/web_cli.rb', line 56

def status
  running = false
  if File.exist?("/tmp/swissadmin.pid")
    pid = IO.read("/tmp/swissadmin.pid")
    res = Commands.app_running? pid
    running = true if res == :running
  end
  $stdout.puts (running ? "Running" : "Not Running")
end

#stopObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/swiss_admin/cli/web_cli.rb', line 40

def stop
  begin
    pid = IO.read("/tmp/swissadmin.pid")
    res = Commands.app_running? pid
    if res == :running
      Process.kill("HUP",pid.to_i)
    end
    File.delete("/tmp/swissadmin.pid")
    $stdout.puts "Stopped" || res != :running
  rescue Errno::ENOENT => e
    $stdout.puts e.message
    return 0
  end
end