aboutsummaryrefslogtreecommitdiff
path: root/bin/mauveserver
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-04-13 17:03:16 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-04-13 17:03:16 +0100
commit89a67770e66d11740948e90a41db6cee0482cf8e (patch)
treebe858515fb789a89d68f94975690ab019813726c /bin/mauveserver
new version.
Diffstat (limited to 'bin/mauveserver')
-rwxr-xr-xbin/mauveserver71
1 files changed, 71 insertions, 0 deletions
diff --git a/bin/mauveserver b/bin/mauveserver
new file mode 100755
index 0000000..c576c85
--- /dev/null
+++ b/bin/mauveserver
@@ -0,0 +1,71 @@
+#! /usr/bin/ruby1.8
+
+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
+end
+
+require 'mauve/configuration'
+include Mauve
+
+configuration_file = ARGV[0]
+if configuration_file.nil?
+ %w(/etc/mauvealert/mauveserver.conf mauveserver.conf).each do |configuration_file|
+ break if File.exists?(configuration_file)
+ end
+end
+
+unless File.exists?(configuration_file)
+ if ARGV[0]
+ STDERR.print "Configuration file #{configuration_file} not found"
+ else
+ STDERR.print "Syntax: #{$0} <configuration filename>\n"
+ end
+ exit 1
+end
+
+Configuration.current = ConfigurationBuilder.load(configuration_file)
+
+class RestartSignalReceived < Exception; end
+class TerminateSignalReceived < Exception; end
+
+%w(HUP).each do |sig|
+ trap("HUP") 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.
+ Configuration.current.logger.warn "#{sig} signal received. Restarting."
+ Configuration.current.server.stop
+ #
+ # Reload configuration
+ #
+ Configuration.current = ConfigurationBuilder.load(configuration_file)
+ Configuration.current.server.start
+ end
+end
+
+%w(QUIT TERM INT).each do |sig|
+ trap(sig) do
+ Configuration.current.logger.warn "#{sig} signal received. Exiting."
+ Configuration.current.server.stop
+ exit 0
+ end
+end
+
+#begin
+ Mauve::Server.instance.run
+#rescue SystemExit
+ # Woo!
+# exit 0
+#rescue Exception => ex
+# [ex.class.to_s, ex.to_s, ex.backtrace.join("\n")].each do |s|
+# Configuration.current.logger.fatal s
+# warn s
+# end
+#
+# exit 1
+#end
+#
+