#!/usr/bin/env ruby # # Author:: Christian Reiniger # License:: GNU GPL v2 or later, as described in the accompanying LICENSE file # Homepage: http://dsadmin.dotsrc.org/ # # ---- # Last change: # # CVS User:: $Author: creinig $ # Date:: $Date: 2006-10-24 10:29:33 +0200 (Tue, 24 Oct 2006) $ # Revision:: $Revision: 110 $ # require 'pathname' unless defined?(RAILS_ROOT) root_path = File.join(File.dirname(__FILE__), '..') unless RUBY_PLATFORM =~ /mswin32/ require 'pathname' root_path = Pathname.new(root_path).cleanpath(true).to_s end RAILS_ROOT = root_path end INSTALL_PATH = Pathname.new(RAILS_ROOT).realpath.to_s $: << File.join(INSTALL_PATH, 'lib') require 'dsadmin/shellfe/shell_client' class AdmindCtl < Dsadmin::Shellfe::ShellClient def parse_opts @options.command = nil opts = base_optionparser opts.separator "" opts.separator "Actions (last one wins):" opts.on("-d", "--down", "--shutdown", "Shut down the entire system") { @options.command = [:meta, :shutdown] } opts.on("-r", "--restart", "Restart down the entire system") { @options.command = [:meta, :restart] } opts.on("-s", "--sync", "--sync-instances", "Sync all instances from the central repository") { @options.command = [:meta, :sync_instances] } opts.parse!(ARGV.clone) unless(@options.username and @options.command) puts opts exit end end def run parse_opts setup res = send_to_backend(@options.command[0], @options.command[1]) if(res.status == :success) puts "Success" else puts "Failure: Got response '#{res.status.to_s}'" if(res.data and res.data['message']) puts " (#{res.data['message']})" end end end end main = AdmindCtl.new main.run