aboutsummaryrefslogtreecommitdiff
path: root/bin/mauveserver
blob: 2d810b9b18448dbc79d6f6066bd3faa0444c8600 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /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'

configuration_file = ARGV.shift
configuration_file = [".", "/etc/mauvealert/"].find{|d| File.file?(File.join(d,"mauveserver.conf")) } 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
end

Mauve::Configuration.current = Mauve::ConfigurationBuilder.load(configuration_file)

%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.
    Mauve::Server.instance.logger.warn "#{sig} signal received.  Stopping."
    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."
    end
    Mauve::Server.instance.logger.warn "Restarting."
    Mauve::Server.instance.start
  end
end

%w(QUIT TERM INT).each do |sig|
  trap(sig) do
    Mauve::Server.instance.logger.warn "#{sig} signal received.  Stopping."
    Mauve::Server.instance.stop
    exit 0
  end
end

Mauve::Server.instance.run