Module: Magicmonkey
- Defined in:
- lib/magicmonkey/version.rb,
lib/magicmonkey/magicmonkey.rb
Constant Summary collapse
- VERSION =
'3.0.3'
- COMMANDS =
%w(configure deconfigure enable disable show vhost start stop restart)
Class Method Summary collapse
-
.configure(args) ⇒ Object
CONFIGURE COMMAND #.
-
.deconfigure(args) ⇒ Object
DECONFIGURE COMMAND #.
-
.disable(args) ⇒ Object
DISABLE COMMAND #.
-
.enable(args) ⇒ Object
ENABLE COMMAND #.
- .main ⇒ Object
-
.restart(args) ⇒ Object
RESTART COMMAND #.
-
.show(args) ⇒ Object
SHOW COMMAND #.
-
.start(args) ⇒ Object
START COMMAND #.
-
.stop(args) ⇒ Object
STOP COMMAND #.
Class Method Details
.configure(args) ⇒ Object
CONFIGURE COMMAND #
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/magicmonkey/magicmonkey.rb', line 47 def self.configure(args) app = self.help('configure', 'Configure the application', args) do |opts| opts.on('-c', '--configuration CONFIG_FILE', 'Use this file as configuration') do |c| @o[:configuration] = c end end app_conf = Conf[app.to_sym] unless app_conf app_conf = @o.select{|k,v| ![:editor].include?(k)} app_conf[:app_path].gsub!('$APP', app) app_conf[:port] = Conf.next_port end tmpfile = Tempfile.new("#{app}.yml") tmpfile.write(app_conf.to_yaml) tmpfile.close system("#{@o[:editor]} '#{tmpfile.path}'") conf = YAML.load_file(tmpfile.path) tmpfile.unlink self.check_port!(conf[:port]) if app_conf[:port] != conf[:port] self.check_ruby_version!(conf[:ruby]) self.check_app_server!(conf[:app_server]) Conf[app.to_sym] = conf Conf.save end |
.deconfigure(args) ⇒ Object
DECONFIGURE COMMAND #
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/magicmonkey/magicmonkey.rb', line 78 def self.deconfigure(args) app = help('deconfigure', 'The application will no longer be handled by magicmonkey.', args) app_conf = Conf[app.to_sym] unless app_conf rputs "Application '#{app}' does not configured." puts "Use 'magicmonkey configure #{app}' to configure it." exit else Conf.delete(app) Conf.save end end |
.disable(args) ⇒ Object
DISABLE COMMAND #
105 106 107 108 109 110 111 |
# File 'lib/magicmonkey/magicmonkey.rb', line 105 def self.disable(args) applications = help2('disable', 'Disable the selected applications', args) applications.each do |app| Conf[app][:enabled] = false end Conf.save end |
.enable(args) ⇒ Object
ENABLE COMMAND #
94 95 96 97 98 99 100 |
# File 'lib/magicmonkey/magicmonkey.rb', line 94 def self.enable(args) applications = help2('enable', 'Enable the selected applications', args) applications.each do |app| Conf[app][:enabled] = true end Conf.save end |
.main ⇒ Object
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 |
# File 'lib/magicmonkey/magicmonkey.rb', line 16 def self.main #Process::UID.change_privilege(Conf[:uid] || Process.uid) raise 'You cannot do this as root' if Process.uid == 0 @o = Marshal.load(Marshal.dump(Conf[:default])) parser = OptionParser.new do |opts| opts. = 'Usage: magicmonkey <command> [<args>]' opts.separator '' opts.separator "Commands: #{COMMANDS.join(' ')}" opts.separator 'For more information about a specific command, please type' opts.separator "'magicmonkey <command> --help', e.g. 'magicmonkey configure --help'." opts.separator '' opts.separator 'Options:' opts.on_tail('-v', '--version', 'Print version') { puts Magicmonkey::VERSION; exit } opts.on_tail('-h', '--help', 'Show this help message') { puts opts; exit } end begin parser.order! command = (ARGV & COMMANDS).first raise 'Invalid command.' unless command ARGV.delete(command) rescue => e puts parser.help; exit end app = ARGV.first self.send(command, ARGV) end |
.restart(args) ⇒ Object
RESTART COMMAND #
148 149 150 |
# File 'lib/magicmonkey/magicmonkey.rb', line 148 def self.restart(args) self.run('restart', args) end |
.show(args) ⇒ Object
SHOW COMMAND #
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/magicmonkey/magicmonkey.rb', line 116 def self.show(args) applications = help2('show', 'Shows the configurations of selected applications', args) do |opts| @o[:enabled] = false opts.on('-e', '--enabled', 'Show enabled applications.') do |s| @o[:enabled] = s end end applications.select!{|k| Conf[k.to_sym][:enabled]} if @o[:enabled] applications.each do |app| puts app.upcase pp Conf[app] puts '-' * 80 end end |
.start(args) ⇒ Object
START COMMAND #
134 135 136 |
# File 'lib/magicmonkey/magicmonkey.rb', line 134 def self.start(args) self.run('start', args) end |
.stop(args) ⇒ Object
STOP COMMAND #
141 142 143 |
# File 'lib/magicmonkey/magicmonkey.rb', line 141 def self.stop(args) self.run('stop', args) end |