From 8db484ce414c285a9755922d47872f974a2206e5 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 27 Feb 2012 17:34:49 +0100 Subject: [PATCH 01/14] feature #924: Add CloudLogger module --- src/cloud/common/CloudAuth.rb | 5 ++-- src/cloud/common/CloudServer.rb | 53 +++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/cloud/common/CloudAuth.rb b/src/cloud/common/CloudAuth.rb index 23331f79f8..b6203a11ea 100644 --- a/src/cloud/common/CloudAuth.rb +++ b/src/cloud/common/CloudAuth.rb @@ -39,11 +39,12 @@ class CloudAuth # Tokens will be generated if time > EXPIRE_TIME - EXPIRE_MARGIN EXPIRE_MARGIN = 300 - attr_reader :client, :token + attr_reader :client, :token, :logger # conf a hash with the configuration attributes as symbols - def initialize(conf) + def initialize(conf, logger=nil) @conf = conf + @logger = logger @token_expiration_time = Time.now.to_i + EXPIRE_DELTA diff --git a/src/cloud/common/CloudServer.rb b/src/cloud/common/CloudServer.rb index ec3b86134d..feb698a04d 100755 --- a/src/cloud/common/CloudServer.rb +++ b/src/cloud/common/CloudServer.rb @@ -37,7 +37,7 @@ class CloudServer ########################################################################## # Public attributes ########################################################################## - attr_reader :config + attr_reader :config, :logger # Initializes the Cloud server based on a config file # config_file:: _String_ for the server. MUST include the following @@ -45,9 +45,10 @@ class CloudServer # AUTH # VM_TYPE # XMLRPC - def initialize(config) + def initialize(config, logger=nil) # --- Load the Cloud Server configuration file --- @config = config + @logger = logger end # # Prints the configuration of the server @@ -82,3 +83,51 @@ class CloudServer return false end end + +module CloudLogger + require 'logger' + + DEBUG_LEVEL = [ + Logger::ERROR, # 0 + Logger::WARN, # 1 + Logger::INFO, # 2 + Logger::DEBUG # 3 + ] + + # Mon Feb 27 06:02:30 2012 [Clo] [E]: Error message example + MSG_FORMAT = %{%s [Clo] [%s]: %s\n} + + # Mon Feb 27 06:02:30 2012 + DATE_FORMAT = "%a %b %d %H:%M:%S %Y" + + # Patch logger class to be compatible with Rack::CommonLogger + class ::Logger + def write(msg) + info msg.chop + end + end + + def enable_logging(path=nil, debug_level=3) + path ||= $stdout + logger = ::Logger.new(path) + logger.level = DEBUG_LEVEL[debug_level] + logger.formatter = proc do |severity, datetime, progname, msg| + MSG_FORMAT % [ + datetime.strftime(DATE_FORMAT), + severity[0..0], + msg ] + end + + # Add the logger instance to the Sinatra settings + set :logger, logger + + # Use the logger instance in the Rack methods + use Rack::CommonLogger, logger + + helpers do + def logger + settings.logger + end + end + end +end From 3ed87c071ae6bf889ea83b24c080ac010a7c86fc Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 27 Feb 2012 17:36:34 +0100 Subject: [PATCH 02/14] feature #924: Add logger to OCCI --- src/cloud/occi/etc/occi-server.conf | 3 ++ src/cloud/occi/lib/OCCIServer.rb | 4 +-- src/cloud/occi/lib/occi-server.rb | 51 ++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/cloud/occi/etc/occi-server.conf b/src/cloud/occi/etc/occi-server.conf index 7d42afbf3d..71402a6457 100644 --- a/src/cloud/occi/etc/occi-server.conf +++ b/src/cloud/occi/etc/occi-server.conf @@ -37,6 +37,9 @@ # Life-time in seconds for token renewal (that used to handle OpenNebula auths) :token_expiration_delta: 1800 +# 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG +:debug_level: 3 + # VM types allowed and its template file (inside templates directory) :instance_types: :small: diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index b05bf6ab43..8d831ee86a 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -52,8 +52,8 @@ class OCCIServer < CloudServer # Server initializer # config_file:: _String_ path of the config file # template:: _String_ path to the location of the templates - def initialize(client, config) - super(config) + def initialize(client, config, logger) + super(config, logger) if config[:ssl_server] @base_url=config[:ssl_server] diff --git a/src/cloud/occi/lib/occi-server.rb b/src/cloud/occi/lib/occi-server.rb index 10b814e5f2..5d2655179f 100755 --- a/src/cloud/occi/lib/occi-server.rb +++ b/src/cloud/occi/lib/occi-server.rb @@ -37,6 +37,7 @@ else end OCCI_AUTH = VAR_LOCATION + "/.one/occi_auth" +OCCI_LOG = VAR_LOCATION + "/occi-server.log" $: << RUBY_LIB_LOCATION $: << RUBY_LIB_LOCATION+"/cloud/occi" @@ -59,42 +60,55 @@ require 'CloudAuth' include OpenNebula ############################################################################## -# Parse Configuration file +# Configuration ############################################################################## +# Set Configuration settings begin conf = YAML.load_file(CONFIGURATION_FILE) rescue Exception => e - puts "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}" + STDERR.puts "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}" exit 1 end conf[:template_location] = TEMPLATE_LOCATION +conf[:debug_level] ||= 3 CloudServer.print_configuration(conf) -############################################################################## -# Sinatra Configuration -############################################################################## +set :config, conf + + +# Enable Logger +include CloudLogger +enable_logging OCCI_LOG, settings.config[:debug_level].to_i + + +# Set Sinatra configuration use Rack::Session::Pool, :key => 'occi' + set :public, Proc.new { File.join(root, "ui/public") } set :views, settings.root + '/ui/views' -set :config, conf if CloudServer.is_port_open?(settings.config[:server], settings.config[:port]) - puts "Port busy, please shutdown the service or move occi server port." - exit + settings.logger.error { + "Port #{settings.config[:port]} busy, please shutdown " << + "the service or move occi server port." + } + exit -1 end set :bind, settings.config[:server] set :port, settings.config[:port] + +# Create CloudAuth begin ENV["ONE_CIPHER_AUTH"] = OCCI_AUTH - cloud_auth = CloudAuth.new(settings.config) + cloud_auth = CloudAuth.new(settings.config, settings.logger) rescue => e - puts "Error initializing authentication system" - puts e.message + settings.logger.error {"Error initializing authentication system"} + settings.logger.error {e.message} exit -1 end @@ -110,17 +124,19 @@ before do begin username = settings.cloud_auth.auth(request.env, params) rescue Exception => e - error 500, e.message + logger.error {e.message} + error 500, "" end else username = session[:user] end if username.nil? #unable to authenticate + logger.error {"User not authorized"} error 401, "" else client = settings.cloud_auth.client(username) - @occi_server = OCCIServer.new(client, settings.config) + @occi_server = OCCIServer.new(client, settings.config, settings.logger) end end end @@ -147,20 +163,22 @@ helpers do begin username = settings.cloud_auth.auth(request.env, params) rescue Exception => e - error 500, e.message + logger.error {e.message} + error 500, "" end if username.nil? + logger.error {"User not authorized"} error 401, "" else client = settings.cloud_auth.client(username) - @occi_server = OCCIServer.new(client, settings.config) + @occi_server = OCCIServer.new(client, settings.config, settings.logger) user_id = OpenNebula::User::SELF user = OpenNebula::User.new_with_id(user_id, client) rc = user.info if OpenNebula.is_error?(rc) - # Add a log message + logger.error {rc.message} return [500, ""] end @@ -190,6 +208,7 @@ helpers do def treat_response(result,rc) if OpenNebula::is_error?(result) + logger.error {result.message} halt rc, result.message end From 52ab2afea6e55fe56bbf36c4e5d2ff100fd1d93f Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 29 Feb 2012 13:27:01 +0100 Subject: [PATCH 03/14] feature #924: Change MSG_FORMAT in Logger class --- src/cloud/common/CloudServer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cloud/common/CloudServer.rb b/src/cloud/common/CloudServer.rb index feb698a04d..84a9bd460b 100755 --- a/src/cloud/common/CloudServer.rb +++ b/src/cloud/common/CloudServer.rb @@ -95,7 +95,7 @@ module CloudLogger ] # Mon Feb 27 06:02:30 2012 [Clo] [E]: Error message example - MSG_FORMAT = %{%s [Clo] [%s]: %s\n} + MSG_FORMAT = %{%s [%s]: %s\n} # Mon Feb 27 06:02:30 2012 DATE_FORMAT = "%a %b %d %H:%M:%S %Y" From 4fd1a87e6680c058aec879fe5a7ed6a9696a310a Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 29 Feb 2012 15:58:37 +0100 Subject: [PATCH 04/14] feature #924: Add Logger to EC2 --- src/cloud/ec2/etc/econe.conf | 3 +++ src/cloud/ec2/lib/EC2QueryServer.rb | 4 ++-- src/cloud/ec2/lib/econe-server.rb | 29 ++++++++++++++++++++--------- src/cloud/occi/etc/occi-server.conf | 3 --- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/cloud/ec2/etc/econe.conf b/src/cloud/ec2/etc/econe.conf index 679d5fb6e9..f9ba61e670 100644 --- a/src/cloud/ec2/etc/econe.conf +++ b/src/cloud/ec2/etc/econe.conf @@ -34,6 +34,9 @@ # x509, for x509 certificate encryption of tokens :core_auth: cipher +# 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG +:debug_level: 3 + # VM types allowed and its template file (inside templates directory) :instance_types: :m1.small: diff --git a/src/cloud/ec2/lib/EC2QueryServer.rb b/src/cloud/ec2/lib/EC2QueryServer.rb index 4e2abd1072..66c14ad2a0 100644 --- a/src/cloud/ec2/lib/EC2QueryServer.rb +++ b/src/cloud/ec2/lib/EC2QueryServer.rb @@ -61,8 +61,8 @@ class EC2QueryServer < CloudServer ########################################################################### - def initialize(client, config) - super(config) + def initialize(client, config, logger) + super(config, logger) @client = client end diff --git a/src/cloud/ec2/lib/econe-server.rb b/src/cloud/ec2/lib/econe-server.rb index 0a8ccc1d98..e583c4ca38 100644 --- a/src/cloud/ec2/lib/econe-server.rb +++ b/src/cloud/ec2/lib/econe-server.rb @@ -33,6 +33,7 @@ end VIEWS_LOCATION = RUBY_LIB_LOCATION + "/cloud/econe/views" EC2_AUTH = VAR_LOCATION + "/.one/ec2_auth" +EC2_LOG = VAR_LOCATION + "/econe.log" $: << RUBY_LIB_LOCATION $: << RUBY_LIB_LOCATION+"/cloud" @@ -57,12 +58,13 @@ include OpenNebula begin conf = YAML.load_file(CONFIGURATION_FILE) rescue Exception => e - puts "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}" + STDERR.puts "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}" exit 1 end conf[:template_location] = TEMPLATE_LOCATION conf[:views] = VIEWS_LOCATION +conf[:debug_level] ||= 3 CloudServer.print_configuration(conf) @@ -70,21 +72,28 @@ CloudServer.print_configuration(conf) # Sinatra Configuration ############################################################################## set :config, conf -set :bind, settings.config[:server] -set :port, settings.config[:port] + +include CloudLogger +enable_logging EC2_LOG, settings.config[:debug_level].to_i if CloudServer.is_port_open?(settings.config[:server], settings.config[:port]) - puts "Port busy, please shutdown the service or move econe server port." - exit 1 + settings.logger.error { + "Port #{settings.config[:port]} busy, please shutdown " << + "the service or move occi server port." + } + exit -1 end +set :bind, settings.config[:server] +set :port, settings.config[:port] + begin ENV["ONE_CIPHER_AUTH"] = EC2_AUTH - cloud_auth = CloudAuth.new(settings.config) + cloud_auth = CloudAuth.new(settings.config, settings.logger) rescue => e - puts "Error initializing authentication system" - puts e.message + settings.logger.error {"Error initializing authentication system"} + settings.logger.error {e.message} exit -1 end @@ -116,6 +125,7 @@ before do params['econe_path'] = settings.econe_path username = settings.cloud_auth.auth(request.env, params) rescue Exception => e + logger.error {e.message} error 500, error_xml("AuthFailure", 0) end @@ -123,7 +133,7 @@ before do error 401, error_xml("AuthFailure", 0) else client = settings.cloud_auth.client(username) - @econe_server = EC2QueryServer.new(client, settings.config) + @econe_server = EC2QueryServer.new(client, settings.config, settings.logger) end end @@ -179,6 +189,7 @@ def do_http_request(params) end if OpenNebula::is_error?(result) + logger.error(result.message) error rc, error_xml(result.message, 0) end diff --git a/src/cloud/occi/etc/occi-server.conf b/src/cloud/occi/etc/occi-server.conf index 71402a6457..5ab9849e09 100644 --- a/src/cloud/occi/etc/occi-server.conf +++ b/src/cloud/occi/etc/occi-server.conf @@ -34,9 +34,6 @@ # x509, for x509 certificate encryption of tokens :core_auth: cipher -# Life-time in seconds for token renewal (that used to handle OpenNebula auths) -:token_expiration_delta: 1800 - # 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG :debug_level: 3 From 26c7333de69480b5954020f3d11c93e83a07e18d Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 1 Mar 2012 12:55:33 +0100 Subject: [PATCH 05/14] Feature #924: Complete occi server UI-related upgrade to use new logger (cherry picked from commit 407f19f86d234d0fd233b34c385ae96689aeb44d) --- src/cloud/occi/lib/OCCIServer.rb | 5 +++-- src/cloud/occi/lib/occi-server.rb | 8 ++++++-- src/sunstone/OpenNebulaVNC.rb | 5 +++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/cloud/occi/lib/OCCIServer.rb b/src/cloud/occi/lib/OCCIServer.rb index 8d831ee86a..a3102da56c 100755 --- a/src/cloud/occi/lib/OCCIServer.rb +++ b/src/cloud/occi/lib/OCCIServer.rb @@ -568,7 +568,7 @@ class OCCIServer < CloudServer return [404, error] end - vnc_proxy = OpenNebulaVNC.new(config,{:json_errors => false}) + vnc_proxy = OpenNebulaVNC.new(config, logger, {:json_errors => false}) return vnc_proxy.start(vm) end @@ -576,7 +576,8 @@ class OCCIServer < CloudServer begin OpenNebulaVNC.stop(pipe) rescue Exception => e - return [500, e.message] + logger.error {e.message} + return [500, "Error stopping VNC. Please check server logs."] end return [200,nil] diff --git a/src/cloud/occi/lib/occi-server.rb b/src/cloud/occi/lib/occi-server.rb index 5d2655179f..baf2ed8ad1 100755 --- a/src/cloud/occi/lib/occi-server.rb +++ b/src/cloud/occi/lib/occi-server.rb @@ -136,7 +136,9 @@ before do error 401, "" else client = settings.cloud_auth.client(username) - @occi_server = OCCIServer.new(client, settings.config, settings.logger) + @occi_server = OCCIServer.new(client, + settings.config, + settings.logger) end end end @@ -172,7 +174,9 @@ helpers do error 401, "" else client = settings.cloud_auth.client(username) - @occi_server = OCCIServer.new(client, settings.config, settings.logger) + @occi_server = OCCIServer.new(client, + settings.config, + settings.logger) user_id = OpenNebula::User::SELF user = OpenNebula::User.new_with_id(user_id, client) diff --git a/src/sunstone/OpenNebulaVNC.rb b/src/sunstone/OpenNebulaVNC.rb index 71c92b6fe2..8d0285c079 100644 --- a/src/sunstone/OpenNebulaVNC.rb +++ b/src/sunstone/OpenNebulaVNC.rb @@ -21,7 +21,7 @@ require 'OpenNebula' # This class provides support for launching and stopping a websockify proxy # class OpenNebulaVNC - def initialize(config, opt={:json_errors => true}) + def initialize(config, logger, opt={:json_errors => true}) @proxy_path = config[:vnc_proxy_path] @proxy_base_port = config[:vnc_proxy_base_port].to_i @@ -36,6 +36,7 @@ class OpenNebulaVNC end @options = opt + @logger = logger end # Start a VNC proxy @@ -71,7 +72,7 @@ class OpenNebulaVNC cmd ="#{@proxy_path} #{proxy_options} #{proxy_port} #{host}:#{vnc_port}" begin - $stderr.puts("Starting vnc proxy: #{cmd}") + @logger.info { "Starting vnc proxy: #{cmd}" } pipe = IO.popen(cmd) rescue Exception => e return [500, OpenNebula::Error.new(e.message).to_json] From e0f95f9a4b24f99716a59772a79f02cbda57e7b2 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 1 Mar 2012 15:28:02 +0100 Subject: [PATCH 06/14] Feature #924: Update Sunstone server to use the new logging system (cherry picked from commit 7b05c9af6a99bb6414a9cd780f559940c0222205) --- src/sunstone/models/SunstoneServer.rb | 15 ++++++--- src/sunstone/sunstone-server.rb | 45 ++++++++++++++++++++------- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/sunstone/models/SunstoneServer.rb b/src/sunstone/models/SunstoneServer.rb index 165f758669..6696d7f436 100644 --- a/src/sunstone/models/SunstoneServer.rb +++ b/src/sunstone/models/SunstoneServer.rb @@ -14,6 +14,8 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +require 'CloudServer' + require 'OpenNebulaJSON' include OpenNebulaJSON @@ -22,14 +24,15 @@ require 'OpenNebulaVNC' require 'OpenNebulaJSON/JSONUtils' include JSONUtils -class SunstoneServer +class SunstoneServer < CloudServer # FLAG that will filter the elements retrieved from the Pools POOL_FILTER = Pool::INFO_ALL # Secs to sleep between checks to see if image upload to repo is finished IMAGE_POLL_SLEEP_TIME = 5 - def initialize(client) + def initialize(client, config, logger) + super(config, logger) @client = client end @@ -194,7 +197,8 @@ class SunstoneServer begin log = File.read(vm_log_file) rescue Exception => e - return [200, "Log for VM #{id} not available"] + msg = "Log for VM #{id} not available" + return [200, {:vm_log => msg}.to_json] end return [200, {:vm_log => log}.to_json] @@ -210,7 +214,7 @@ class SunstoneServer return [404, resource.to_json] end - vnc_proxy = OpenNebulaVNC.new(config) + vnc_proxy = OpenNebulaVNC.new(config, logger) return vnc_proxy.start(resource) end @@ -221,7 +225,8 @@ class SunstoneServer begin OpenNebulaVNC.stop(pipe) rescue Exception => e - error = Error.new(e.message) + logger.error {e.message} + error = Error.new("Error stopping VNC. Please check server logs.") return [500, error.to_json] end diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index 2e09422136..0421a2ee99 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -32,6 +32,7 @@ else end SUNSTONE_AUTH = VAR_LOCATION + "/.one/sunstone_auth" +SUNSTONE_LOG = VAR_LOCATION + "/sunstone.log" CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-server.conf" PLUGIN_CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-plugins.yaml" @@ -54,27 +55,42 @@ require 'CloudAuth' require 'SunstoneServer' require 'SunstonePlugins' + +############################################################################## +# Configuration +############################################################################## + begin conf = YAML.load_file(CONFIGURATION_FILE) rescue Exception => e - puts "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}" + STDERR.puts "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}" exit 1 end -############################################################################## -# Sinatra Configuration -############################################################################## -use Rack::Session::Pool, :key => 'sunstone' +conf[:debug_level] ||= 3 + +CloudServer.print_configuration(conf) + +#Sinatra configuration + set :config, conf set :bind, settings.config[:host] set :port, settings.config[:port] +use Rack::Session::Pool, :key => 'sunstone' + +# Enable logger + +include CloudLogger +enable_logging SUNSTONE_LOG, settings.config[:debug_level].to_i + begin ENV["ONE_CIPHER_AUTH"] = SUNSTONE_AUTH cloud_auth = CloudAuth.new(settings.config) rescue => e - puts "Error initializing authentication system" - puts e.message + settings.logger.error { + "Error initializing authentication system" } + settings.logger.error { e.message } exit -1 end @@ -93,10 +109,12 @@ helpers do settings.cloud_auth.update_userpool_cache result = settings.cloud_auth.auth(request.env, params) rescue Exception => e - error 500, e.message + error 500, "" + logger.error { e.message } end if result.nil? + logger.info { "Unauthorized login attempt" } return [401, ""] else client = settings.cloud_auth.client(result) @@ -105,7 +123,7 @@ helpers do user = OpenNebula::User.new_with_id(user_id, client) rc = user.info if OpenNebula.is_error?(rc) - # Add a log message + logger.error { rc.message } return [500, ""] end @@ -157,7 +175,9 @@ before do halt 401 unless authorized? @SunstoneServer = SunstoneServer.new( - settings.cloud_auth.client(session[:user])) + settings.cloud_auth.client(session[:user]), + settings.config, + settings.logger) end end @@ -244,7 +264,10 @@ end post '/config' do begin body = JSON.parse(request.body.read) - rescue + rescue Exception => e + msg = "Error parsing configuration JSON" + logger.error { msg } + logger.error { e.message } [500, OpenNebula::Error.new(msg).to_json] end From 42ee95d0c83ef499d316efce5c27bf83210b5143 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 1 Mar 2012 16:47:02 +0100 Subject: [PATCH 07/14] Feature #924: Update ozones to use the new logger (cherry picked from commit 74b54f658ac794809be8f3e7e9754667ddb9fd43) Conflicts: src/ozones/Server/ozones-server.rb --- src/ozones/Server/models/OzonesServer.rb | 7 +++- src/ozones/Server/ozones-server.rb | 52 +++++++++++++++++------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/ozones/Server/models/OzonesServer.rb b/src/ozones/Server/models/OzonesServer.rb index 835d78b8f9..1b43ba887b 100644 --- a/src/ozones/Server/models/OzonesServer.rb +++ b/src/ozones/Server/models/OzonesServer.rb @@ -14,13 +14,16 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +require 'CloudServer' + require 'JSONUtils' -class OzonesServer +class OzonesServer < CloudServer include OpenNebulaJSON::JSONUtils - def initialize(cipher) + def initialize(cipher, config, logger) + super(config, logger) #Set cipher for Zone classes OZones::Zones.cipher = cipher end diff --git a/src/ozones/Server/ozones-server.rb b/src/ozones/Server/ozones-server.rb index a3fb9d8b85..9249cf6e48 100755 --- a/src/ozones/Server/ozones-server.rb +++ b/src/ozones/Server/ozones-server.rb @@ -23,15 +23,20 @@ if !ONE_LOCATION LIB_LOCATION="/usr/lib/one" RUBY_LIB_LOCATION="/usr/lib/one/ruby" VAR_LOCATION="/var/lib/one" + CONFIGURATION_FILE="/etc/one/ozones-server.conf" else ETC_LOCATION=ONE_LOCATION+"/etc" LIB_LOCATION=ONE_LOCATION+"/lib" RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" VAR_LOCATION=ONE_LOCATION+"/var" + CONFIGURATION_FILE=ONE_LOCATION+"/etc/ozones-server.conf" end +OZONES_LOG = VAR_LOCATION + "/ozones-server.log" + $: << LIB_LOCATION + "/sunstone/models" $: << RUBY_LIB_LOCATION +$: << RUBY_LIB_LOCATION+'/cloud' $: << LIB_LOCATION+'/ozones/models' $: << LIB_LOCATION+'/ozones/lib' $: << RUBY_LIB_LOCATION+"/cli" @@ -52,8 +57,16 @@ require 'OzonesServer' ############################################################################## # Read configuration ############################################################################## -config_data=File.read(ETC_LOCATION+'/ozones-server.conf') -config=YAML::load(config_data) +begin + config=YAML::load_file(CONFIGURATION_FILE) +rescue Exception => e + warn "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}" + exit 1 +end + +config[:debug_level] ||= 3 + +CloudServer.print_configuration(config) db_type = config[:databasetype] @@ -72,6 +85,20 @@ case db_type exit -1 end +############################################################################## +# Sinatra Configuration +############################################################################## +set :config, config +set :bind, config[:host] +set :port, config[:port] + +use Rack::Session::Pool, :key => 'ozones' + +#Enable logger +disable :logging +include CloudLogger +enable_logging OZONES_LOG, settings.config[:debug_level].to_i + ############################################################################## # DB bootstrapping ############################################################################## @@ -92,7 +119,7 @@ if Auth.all.size == 0 credentials = IO.read(ENV['OZONES_AUTH']).strip.split(':') if credentials.length < 2 - warn "Authorization data malformed" + settings.logger.error {"Authorization data malformed"} exit -1 end credentials[1] = Digest::SHA1.hexdigest(credentials[1]) @@ -100,7 +127,8 @@ if Auth.all.size == 0 :password => credentials[1]}) @auth.save else - warn "oZones admin credentials not set, missing OZONES_AUTH file." + error_m = "oZones admin credentials not set, missing OZONES_AUTH file." + settings.logger.error { error_m } exit -1 end else @@ -117,15 +145,6 @@ rescue Exception => e exit -1 end - -############################################################################## -# Sinatra Configuration -############################################################################## -use Rack::Session::Pool, :key => 'ozones' -set :bind, config[:host] -set :port, config[:port] -set :show_exceptions, false - ############################################################################## # Helpers ############################################################################## @@ -157,10 +176,11 @@ helpers do return [204, ""] else + logger.info {"User not authorized login attempt"} return [401, ""] end end - + logger.error {"Authentication settings wrong or not provided"} return [401, ""] end @@ -181,7 +201,9 @@ before do end end - @OzonesServer = OzonesServer.new(session[:key]) + @OzonesServer = OzonesServer.new(session[:key], + settings.config, + settings.logger) @pr = OZones::ProxyRules.new("apache",config[:htaccess]) end end From 95219a9adad747bc2668dd7875eb6a103fde7a6b Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 1 Mar 2012 16:53:16 +0100 Subject: [PATCH 08/14] Feature #924: Update ozones and sunstone logs with :debug_devel (cherry picked from commit fc30b2a2c58a9b2742b3cadbd4c2db4d8218c040) --- src/ozones/Server/etc/ozones-server.conf | 5 ++++- src/ozones/Server/ozones-server.rb | 1 - src/sunstone/etc/sunstone-server.conf | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ozones/Server/etc/ozones-server.conf b/src/ozones/Server/etc/ozones-server.conf index 8b09856d69..1fa3f0695b 100644 --- a/src/ozones/Server/etc/ozones-server.conf +++ b/src/ozones/Server/etc/ozones-server.conf @@ -19,7 +19,7 @@ ############################################## ###################### -# DB Options +# DB Options ###################### :databasetype: sqlite @@ -27,6 +27,9 @@ #:htaccess: /var/www/.htaccess :dbdebug: no +# 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG +:debug_level: 3 + ##################### # Server Configuration ##################### diff --git a/src/ozones/Server/ozones-server.rb b/src/ozones/Server/ozones-server.rb index 9249cf6e48..14ccc3fab7 100755 --- a/src/ozones/Server/ozones-server.rb +++ b/src/ozones/Server/ozones-server.rb @@ -95,7 +95,6 @@ set :port, config[:port] use Rack::Session::Pool, :key => 'ozones' #Enable logger -disable :logging include CloudLogger enable_logging OZONES_LOG, settings.config[:debug_level].to_i diff --git a/src/sunstone/etc/sunstone-server.conf b/src/sunstone/etc/sunstone-server.conf index bcc7e8225f..cddab640a1 100644 --- a/src/sunstone/etc/sunstone-server.conf +++ b/src/sunstone/etc/sunstone-server.conf @@ -1,6 +1,9 @@ # OpenNebula sever contact information :one_xmlrpc: http://localhost:2633/RPC2 +# 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG +:debug_level: 3 + # Server Configuration :host: 127.0.0.1 :port: 9869 From 2a34ba0a0ca1d6c09f97ac556c89327358cd8db6 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 2 Mar 2012 11:28:34 +0100 Subject: [PATCH 09/14] Feature #924 - add missing logger to ozones (cherry picked from commit d4d3eb692a3ea2566596c71ac2686c6c4758ad84) --- src/ozones/Server/ozones-server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ozones/Server/ozones-server.rb b/src/ozones/Server/ozones-server.rb index 14ccc3fab7..ca8830577c 100755 --- a/src/ozones/Server/ozones-server.rb +++ b/src/ozones/Server/ozones-server.rb @@ -140,7 +140,7 @@ ADMIN_PASS = @auth.password begin OZones::ProxyRules.new("apache",config[:htaccess]) rescue Exception => e - warn e.message + settings.logger {e.message} exit -1 end From f1349136c7d5f8388c739e1a45b6328e02ad815a Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 2 Mar 2012 11:44:03 +0100 Subject: [PATCH 10/14] Feature #924: launch ozones without using rackup (cherry picked from commit bf87b2bed5bf39910ce55f36509e4c693ed2d773) --- src/ozones/Server/bin/ozones-server | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/ozones/Server/bin/ozones-server b/src/ozones/Server/bin/ozones-server index 7d71a28d8f..9a637cafbb 100755 --- a/src/ozones/Server/bin/ozones-server +++ b/src/ozones/Server/bin/ozones-server @@ -19,14 +19,14 @@ if [ -z "$ONE_LOCATION" ]; then OZONES_PID=/var/run/one/ozones.pid OZONES_LOCATION=/usr/lib/one/ozones - OZONES_SERVER=$OZONES_LOCATION/config.ru + OZONES_SERVER=$OZONES_LOCATION/ozones-server.rb OZONES_LOCK_FILE=/var/lock/one/.ozones.lock OZONES_LOG=/var/log/one/ozones-server.log OZONES_CONF=/etc/one/ozones-server.conf else OZONES_PID=$ONE_LOCATION/var/ozones.pid OZONES_LOCATION=$ONE_LOCATION/lib/ozones - OZONES_SERVER=$OZONES_LOCATION/config.ru + OZONES_SERVER=$OZONES_LOCATION/ozones-server.rb OZONES_LOCK_FILE=$ONE_LOCATION/var/.ozones.lock OZONES_LOG=$ONE_LOCATION/var/ozones-server.log OZONES_CONF=$ONE_LOCATION/etc/ozones-server.conf @@ -58,29 +58,26 @@ start() exit 1 fi - HOST=`cat $OZONES_CONF|grep ^\:host\:|cut -d' ' -f 2` - PORT=`cat $OZONES_CONF|grep ^\:port\:|cut -d' ' -f 2` - - lsof -i:$PORT &> /dev/null - if [ $? -eq 0 ]; then - echo "The port $PORT is being used. Please specify a different one." - exit 1 - fi - # Start the ozones daemon touch $OZONES_LOCK_FILE - rackup $OZONES_SERVER -s thin -p $PORT -o $HOST \ - -P $OZONES_PID &> $OZONES_LOG & + ruby $OZONES_SERVER > $OZONES_LOG 2>&1 & + LASTPID=$! + if [ $? -ne 0 ]; then + echo "Error executing $OZONES_SERVER, please check the log $OZONES_LOG" + exit 1 + else + echo $LASTPID > $OZONES_PID + fi sleep 2 - ps -p $(cat $OZONES_PID 2>/dev/null) > /dev/null 2>&1 + ps $LASTPID &> /dev/null if [ $? -ne 0 ]; then echo "Error executing $OZONES_SERVER, please check the log $OZONES_LOG" exit 1 fi - echo "ozones-server listening on $HOST:$PORT" + echo "ozones-server started" } # From e1fc5f5dc3baedf7d3c0e676298b7a3999d5ecab Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 2 Mar 2012 16:29:20 +0100 Subject: [PATCH 11/14] feature #924: Remove unneeded rackup file --- src/ozones/Server/config.ru | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 src/ozones/Server/config.ru diff --git a/src/ozones/Server/config.ru b/src/ozones/Server/config.ru deleted file mode 100644 index b5e2604dee..0000000000 --- a/src/ozones/Server/config.ru +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/ruby - -# -------------------------------------------------------------------------- # -# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # -# # -# Licensed under the Apache License, Version 2.0 (the "License"); you may # -# not use this file except in compliance with the License. You may obtain # -# a copy of the License at # -# # -# http://www.apache.org/licenses/LICENSE-2.0 # -# # -# Unless required by applicable law or agreed to in writing, software # -# distributed under the License is distributed on an "AS IS" BASIS, # -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -# See the License for the specific language governing permissions and # -# limitations under the License. # -#--------------------------------------------------------------------------- # - -$: << File.dirname(__FILE__) - -require 'ozones-server.rb' - -run Sinatra::Application From 79facc884ea5c48cbc05921d81d355ca8514f8a3 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 2 Mar 2012 16:32:49 +0100 Subject: [PATCH 12/14] feature #924: Removed unneeded config.ru file --- src/sunstone/config.ru | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 src/sunstone/config.ru diff --git a/src/sunstone/config.ru b/src/sunstone/config.ru deleted file mode 100644 index aa4380a728..0000000000 --- a/src/sunstone/config.ru +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/ruby - -# -------------------------------------------------------------------------- # -# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # -# # -# Licensed under the Apache License, Version 2.0 (the "License"); you may # -# not use this file except in compliance with the License. You may obtain # -# a copy of the License at # -# # -# http://www.apache.org/licenses/LICENSE-2.0 # -# # -# Unless required by applicable law or agreed to in writing, software # -# distributed under the License is distributed on an "AS IS" BASIS, # -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -# See the License for the specific language governing permissions and # -# limitations under the License. # -#--------------------------------------------------------------------------- # - -$: << File.dirname(__FILE__) - -require 'sunstone-server.rb' - -run Sinatra::Application From 6389af93352f356b6bf8d84cb4209466fdb092e5 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 2 Mar 2012 17:36:31 +0100 Subject: [PATCH 13/14] feature #924: Fix system wide paths for logs --- src/cloud/common/CloudServer.rb | 3 +++ src/cloud/ec2/lib/econe-server.rb | 23 +++++++++++++---------- src/cloud/occi/lib/occi-server.rb | 21 ++++++++++++--------- src/ozones/Server/ozones-server.rb | 23 ++++++++++++----------- src/sunstone/sunstone-server.rb | 3 ++- 5 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/cloud/common/CloudServer.rb b/src/cloud/common/CloudServer.rb index 84a9bd460b..9e3883ad1a 100755 --- a/src/cloud/common/CloudServer.rb +++ b/src/cloud/common/CloudServer.rb @@ -121,6 +121,9 @@ module CloudLogger # Add the logger instance to the Sinatra settings set :logger, logger + # The logging will be configured in Rack, not in Sinatra + disable :logging + # Use the logger instance in the Rack methods use Rack::CommonLogger, logger diff --git a/src/cloud/ec2/lib/econe-server.rb b/src/cloud/ec2/lib/econe-server.rb index e583c4ca38..0d20b59cc4 100644 --- a/src/cloud/ec2/lib/econe-server.rb +++ b/src/cloud/ec2/lib/econe-server.rb @@ -20,20 +20,23 @@ ONE_LOCATION=ENV["ONE_LOCATION"] if !ONE_LOCATION - RUBY_LIB_LOCATION = "/usr/lib/one/ruby" + LOG_LOCATION = "/var/log/one" VAR_LOCATION = "/var/lib/one" - CONFIGURATION_FILE = "/etc/one/econe.conf" - TEMPLATE_LOCATION = "/etc/one/ec2query_templates" + ETC_LOCATION = "/etc/one" + RUBY_LIB_LOCATION = "/usr/lib/one/ruby" else - RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby" - VAR_LOCATION = ONE_LOCATION+"/var" - CONFIGURATION_FILE = ONE_LOCATION+"/etc/econe.conf" - TEMPLATE_LOCATION = ONE_LOCATION+"/etc/ec2query_templates" + VAR_LOCATION = ONE_LOCATION + "/var" + LOG_LOCATION = ONE_LOCATION + "/var" + ETC_LOCATION = ONE_LOCATION + "/etc" + RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby" end -VIEWS_LOCATION = RUBY_LIB_LOCATION + "/cloud/econe/views" -EC2_AUTH = VAR_LOCATION + "/.one/ec2_auth" -EC2_LOG = VAR_LOCATION + "/econe.log" +EC2_AUTH = VAR_LOCATION + "/.one/ec2_auth" +EC2_LOG = LOG_LOCATION + "/econe-server.log" +CONFIGURATION_FILE = ETC_LOCATION + "/occi-server.conf" + +TEMPLATE_LOCATION = ETC_LOCATION + "/occi_templates" +VIEWS_LOCATION = RUBY_LIB_LOCATION + "/cloud/econe/views" $: << RUBY_LIB_LOCATION $: << RUBY_LIB_LOCATION+"/cloud" diff --git a/src/cloud/occi/lib/occi-server.rb b/src/cloud/occi/lib/occi-server.rb index baf2ed8ad1..851d58dc5c 100755 --- a/src/cloud/occi/lib/occi-server.rb +++ b/src/cloud/occi/lib/occi-server.rb @@ -25,19 +25,22 @@ ONE_LOCATION=ENV["ONE_LOCATION"] if !ONE_LOCATION - RUBY_LIB_LOCATION="/usr/lib/one/ruby" + LOG_LOCATION = "/var/log/one" VAR_LOCATION = "/var/lib/one" - TEMPLATE_LOCATION="/etc/one/occi_templates" - CONFIGURATION_FILE = "/etc/one/occi-server.conf" + ETC_LOCATION = "/etc/one" + RUBY_LIB_LOCATION = "/usr/lib/one/ruby" else - RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" - VAR_LOCATION = ONE_LOCATION+"/var" - TEMPLATE_LOCATION=ONE_LOCATION+"/etc/occi_templates" - CONFIGURATION_FILE = ONE_LOCATION+"/etc/occi-server.conf" + VAR_LOCATION = ONE_LOCATION + "/var" + LOG_LOCATION = ONE_LOCATION + "/var" + ETC_LOCATION = ONE_LOCATION + "/etc" + RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby" end -OCCI_AUTH = VAR_LOCATION + "/.one/occi_auth" -OCCI_LOG = VAR_LOCATION + "/occi-server.log" +OCCI_AUTH = VAR_LOCATION + "/.one/occi_auth" +OCCI_LOG = LOG_LOCATION + "/occi-server.log" +CONFIGURATION_FILE = ETC_LOCATION + "/occi-server.conf" + +TEMPLATE_LOCATION = ETC_LOCATION + "/occi_templates" $: << RUBY_LIB_LOCATION $: << RUBY_LIB_LOCATION+"/cloud/occi" diff --git a/src/ozones/Server/ozones-server.rb b/src/ozones/Server/ozones-server.rb index ca8830577c..70eb42323a 100755 --- a/src/ozones/Server/ozones-server.rb +++ b/src/ozones/Server/ozones-server.rb @@ -19,20 +19,21 @@ ONE_LOCATION=ENV["ONE_LOCATION"] if !ONE_LOCATION - ETC_LOCATION="/etc/one" - LIB_LOCATION="/usr/lib/one" - RUBY_LIB_LOCATION="/usr/lib/one/ruby" - VAR_LOCATION="/var/lib/one" - CONFIGURATION_FILE="/etc/one/ozones-server.conf" + LOG_LOCATION = "/var/log/one" + VAR_LOCATION = "/var/lib/one" + ETC_LOCATION = "/etc/one" + LIB_LOCATION = "/usr/lib/one" + RUBY_LIB_LOCATION = "/usr/lib/one/ruby" else - ETC_LOCATION=ONE_LOCATION+"/etc" - LIB_LOCATION=ONE_LOCATION+"/lib" - RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" - VAR_LOCATION=ONE_LOCATION+"/var" - CONFIGURATION_FILE=ONE_LOCATION+"/etc/ozones-server.conf" + VAR_LOCATION = ONE_LOCATION + "/var" + LOG_LOCATION = ONE_LOCATION + "/var" + ETC_LOCATION = ONE_LOCATION + "/etc" + LIB_LOCATION = ONE_LOCATION+"/lib" + RUBY_LIB_LOCATION = ONE_LOCATION+"/lib/ruby" end -OZONES_LOG = VAR_LOCATION + "/ozones-server.log" +OZONES_LOG = LOG_LOCATION + "/ozones-server.log" +CONFIGURATION_FILE = ETC_LOCATION + "/ozones-server.conf" $: << LIB_LOCATION + "/sunstone/models" $: << RUBY_LIB_LOCATION diff --git a/src/sunstone/sunstone-server.rb b/src/sunstone/sunstone-server.rb index 0421a2ee99..21230aa0f5 100755 --- a/src/sunstone/sunstone-server.rb +++ b/src/sunstone/sunstone-server.rb @@ -32,8 +32,9 @@ else end SUNSTONE_AUTH = VAR_LOCATION + "/.one/sunstone_auth" -SUNSTONE_LOG = VAR_LOCATION + "/sunstone.log" +SUNSTONE_LOG = LOG_LOCATION + "/sunstone.log" CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-server.conf" + PLUGIN_CONFIGURATION_FILE = ETC_LOCATION + "/sunstone-plugins.yaml" SUNSTONE_ROOT_DIR = File.dirname(__FILE__) From 62b5427c248f13952b1545e4d27326e7b6863547 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 7 Mar 2012 13:10:14 +0100 Subject: [PATCH 14/14] feature #924: Remove removed config.ru files from installer --- install.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index fa2b593fe0..28e4e2b0a9 100755 --- a/install.sh +++ b/install.sh @@ -1079,8 +1079,7 @@ ETC_CLIENT_FILES="src/cli/etc/group.default" # Sunstone files #----------------------------------------------------------------------------- -SUNSTONE_FILES="src/sunstone/config.ru \ - src/sunstone/sunstone-server.rb \ +SUNSTONE_FILES="src/sunstone/sunstone-server.rb \ src/sunstone/OpenNebulaVNC.rb" SUNSTONE_BIN_FILES="src/sunstone/bin/sunstone-server" @@ -1225,8 +1224,7 @@ src/sunstone/public/locale/ru/ru_datatable.txt" # Ozones files #----------------------------------------------------------------------------- -OZONES_FILES="src/ozones/Server/config.ru \ - src/ozones/Server/ozones-server.rb" +OZONES_FILES="src/ozones/Server/ozones-server.rb" OZONES_BIN_FILES="src/ozones/Server/bin/ozones-server"