From e140af144e987ff7f6d767f2dc48b9cf685803fd Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 13 Jul 2011 16:02:50 +0100 Subject: Big commit * Added manpages for all binaries * Added log-reopening for mauvealert-server, and logrotate snippet * mauveserver now adds a user on install, and runs as that user * Big logging tidy-up * Alert subjects are only overwritten by the source, when the subject in the databse is empty * Removed various attr_writer methods that were being redifined * Added a notes box to the acknowledge form, but this doesn't work yet --- bin/mauveclient | 4 +++ bin/mauveconsole | 65 ++++++++++++++++++++++++++++++++------ bin/mauveserver | 96 +++++++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 141 insertions(+), 24 deletions(-) (limited to 'bin') diff --git a/bin/mauveclient b/bin/mauveclient index 0068435..251b45b 100755 --- a/bin/mauveclient +++ b/bin/mauveclient @@ -142,6 +142,10 @@ # # mauveclient -i heartbeat -d "No heartbeat received for 1.2.3.4. Could be down!" -s "heartbeat failed" -c -r +10m # +# SEE ALSO +# +# mauveconsole(1), mauveserver(1) +# # AUTHOR # # Patrick J Cherry diff --git a/bin/mauveconsole b/bin/mauveconsole index debe5af..5a16a7e 100755 --- a/bin/mauveconsole +++ b/bin/mauveconsole @@ -1,23 +1,70 @@ #!/usr/bin/ruby1.8 +# NAME +# +# mauveconsole -- Ruby console to query the mauvealert server directly +# +# SYNOPSIS +# +# mauveconsole [-h | --help] [] +# +# OPTIONS +# +# -h, --help Show a help message +# File to load the configuration from. If none is +# specified, then mauvealert.conf in the current +# directory is used, and failing that +# /etc/mauvealert/mauvealert.conf is used. +# +# SEE ALSO +# +# irb(1), mauveserver(1), mauveclient(1) +# +# AUTHOR +# +# Patrick J Cherry +# -require 'pp' -require 'irb' -require 'thread' -require 'mauve/configuration' +def error(msg) + STDERR.print "*** Error: #{msg}\n" + STDERR.print "*** For help, type: #{$0} -h\n" + exit 1 +end -Thread.abort_on_exception = true +# CAUTION! Kwality kode. +# +if ARGV.any?{|a| a =~ /--?h(elp)?/} + # Open the file, stripping the shebang line + lines = File.open(__FILE__){|fh| fh.readlines}[1..-1] + + lines.each do |line| + line.chomp! + break if line.empty? + puts line[2..-1].to_s + end + + exit 0 +end configuration_file = ARGV.shift -configuration_file = [".", "/etc/mauvealert/"].find{|d| File.file?(File.join(d,"mauveserver.conf")) } if configuration_file.nil? +configuration_file = [".", "/etc/mauvealert/"].collect{|x| File.join("mauveserver.conf") }.find{|d| File.file?(d)} if configuration_file.nil? configuration_file = File.expand_path(configuration_file) unless File.file?(configuration_file) - STDERR.print "Configuration file #{configuration_file} not found" - Kernel.exit 1 + error "Configuration file #{configuration_file} not found\n" end -Mauve::Configuration.current = Mauve::ConfigurationBuilder.load(configuration_file) +require 'irb' +require 'thread' +require 'mauve/configuration' + +Thread.abort_on_exception = true include Mauve +begin + Configuration.current = ConfigurationBuilder.load(configuration_file) +rescue StandardError => ex + error ex.message +end + IRB.start diff --git a/bin/mauveserver b/bin/mauveserver index 2d810b9..a5cf7b5 100755 --- a/bin/mauveserver +++ b/bin/mauveserver @@ -1,49 +1,111 @@ #! /usr/bin/ruby1.8 +# NAME +# +# mauveserver -- receive alerts from station(s) around the network +# +# SYNOPSIS +# +# mauveserver [ -h | --help ] [] +# +# OPTIONS +# +# -h, --help Show a help message +# +# File to load the configuration from +# +# SEE ALSO +# +# mauveclient(1), mauveconsole(1) +# +# AUTHOR +# +# Patrick J Cherry +# + +def error(msg) + STDERR.print "*** Error: #{msg}\n" + STDERR.print "*** For help, type: #{$0} -h\n" + exit 1 +end begin eval "Proc.new { |a,&b| }" rescue SyntaxError => no_blocks_with_procs - STDERR.print "mauveserver must have Ruby 1.8.7 or later, sorry (if you "+ - "try, you'll get a SyntaxError trying to load one of its libraries)\n" - exit 1 + error "mauveserver must have Ruby 1.8.7 or later" end - -require 'mauve/configuration' + +# CAUTION! Kwality kode. +# +if ARGV.any?{|a| a =~ /--?h(elp)?/} + # Open the file, stripping the shebang line + lines = File.open(__FILE__){|fh| fh.readlines}[1..-1] + + lines.each do |line| + line.chomp! + break if line.empty? + puts line[2..-1].to_s + end + + exit 0 +end + configuration_file = ARGV.shift -configuration_file = [".", "/etc/mauvealert/"].find{|d| File.file?(File.join(d,"mauveserver.conf")) } if configuration_file.nil? +configuration_file = [".", "/etc/mauvealert/"].collect{|x| File.join("mauveserver.conf") }.find{|d| File.file?(d)} if configuration_file.nil? configuration_file = File.expand_path(configuration_file) unless File.file?(configuration_file) - STDERR.print "Configuration file #{configuration_file} not found\n" - Kernel.exit 1 + error "Configuration file #{configuration_file} not found\n" end -Mauve::Configuration.current = Mauve::ConfigurationBuilder.load(configuration_file) +require 'mauve/configuration' + +begin + Mauve::Configuration.current = Mauve::ConfigurationBuilder.load(configuration_file) +rescue StandardError => ex + error ex.message +end %w(HUP).each do |sig| - trap("HUP") do + trap(sig) do # this blows up if you do it twice in quick succession, but don't really # care about that case as it's only for log rotation. - Mauve::Server.instance.logger.warn "#{sig} signal received. Stopping." + Mauve::Server.instance.logger.warn "#{sig} signal received. Restarting." Mauve::Server.instance.stop # # Reload configuration # - Mauve::Server.instance.logger.warn "Restarting." - begin new_config = Mauve::ConfigurationBuilder.load(configuration_file) Mauve::Configuration.current = new_config rescue BuildException => ex - Mauve::Server.instance.logger.warn "Reconfiguration failed: #{ex}. Sticking with old one." + Mauve::Server.instance.logger.error "Reconfiguration failed: #{ex}. Sticking with old one." end Mauve::Server.instance.logger.warn "Restarting." Mauve::Server.instance.start end end +%w(USR1).each do |sig| + trap(sig) do + Mauve::Server.instance.logger.warn "#{sig} signal received. Re-opening logs." + Log4r::Outputter.each_outputter do |old| + next unless old.is_a?(Log4r::FileOutputter) + + new = Log4r::FileOutputter.new(old.name, {:filename => old.filename, :trunc => false}) + new.formatter = old.formatter + new.level = old.level + + Mauve::Server.instance.logger.outputters << new + Mauve::Server.instance.logger.outputters.delete(old) + old.close + + Mauve::Server.instance.logger.debug "Opened #{new.filename}." + end + end +end + %w(QUIT TERM INT).each do |sig| trap(sig) do Mauve::Server.instance.logger.warn "#{sig} signal received. Stopping." @@ -52,5 +114,9 @@ end end end -Mauve::Server.instance.run +begin + Mauve::Server.instance.run +rescue StandardError => ex + error ex.message +end -- cgit v1.2.1