Class: Appserver::Command

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, arguments, options = {}) ⇒ Command



11
12
13
# File 'lib/appserver/command.rb', line 11

def initialize (command, arguments, options = {})
  @command, @arguments, @options = command, arguments, options
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



9
10
11
# File 'lib/appserver/command.rb', line 9

def arguments
  @arguments
end

#commandObject (readonly)

Returns the value of attribute command.



9
10
11
# File 'lib/appserver/command.rb', line 9

def command
  @command
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/appserver/command.rb', line 9

def options
  @options
end

Class Method Details

.run!(*args) ⇒ Object



5
6
7
# File 'lib/appserver/command.rb', line 5

def self.run! (*args)
  new(*args).run!
end

Instance Method Details

#run!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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/appserver/command.rb', line 15

def run!
  Dir.chdir(options[:dir]) if options[:dir]

  if command == 'init'
    ServerDir.init(arguments[0], options)
    Dir.chdir(arguments[0])
  end

  server_dir = ServerDir.discover

  case command
    when 'init'
      server_dir.write_configs
      puts 'Initialized appserver directory.'
      puts 'Wrote configuration snippets. Make sure to include them into your'
      puts 'system\'s Monit/Nginx/Logrotate configuration to become active.'

    when 'update'
      server_dir.write_configs
      puts 'Wrote configuration snippets.'

    when 'deploy'
      repository = server_dir.repository(arguments[0])
      repository.install_hook
      # Second and third arguments are used by git update hooks and contain
      # the ref name and the new ref that just have been updated
      ref = repository.app.branch
      if arguments[1] && arguments[2]
        return unless arguments[1] =~ %r(refs/heads/#{ref})
        ref = arguments[2]
      end
      puts 'Deploying application...'
      repository.deploy(ref)
      puts 'Done.'

    when 'start'
      app = server_dir.app(arguments[0])
      app.start_server

    when 'stop'
      app = server_dir.app(arguments[0])
      app.stop_server

    when 'restart'
      app = server_dir.app(arguments[0])
      app.restart_server

    when 'reopen'
      app = server_dir.app(arguments[0])
      app.reopen_server_log

    else
      raise UnknownCommandError
  end
end