Fix a dep. That *is* worth a version bump.
[webvac] / bin / webvac-server
1 #!/usr/bin/env ruby
2
3 %w(
4         webvac
5 ).each &method(:require)
6
7 def die! msg
8         $stderr.puts msg
9         exit 1
10 end
11
12 def usage! o = $stderr, c = 1
13         o.puts <<-EOS.gsub(/^\t\t/, '')
14                 #{$0} [-h|-help|--help] [-d] [--] $files
15                 -d delets this (if the sweep is successful)
16                 -v Be verbose
17                 -h This usage message
18         EOS
19         exit c
20 end
21
22 include WebVac
23 c = Config.load
24 v = Vac.new c
25 t = Table.new c
26
27 args = ARGV.dup
28 deletthis = false
29 verbose = false
30
31 def die! msg
32         $stderr.puts msg
33         exit 1
34 end
35
36 def usage! o = $stderr, c = 1
37         o.puts <<-EOS.gsub(/^\t\t/, '')
38                 #{$0} [-h|-help|--help] [-l $host:$port] [-D] [--] $files
39                 -h
40                         This help.
41
42                 The following options are passed through to rainbows:
43                 -l $host:$port
44                         Address to listen on.  Defaults to localhost:8891
45                 -D
46                         Daemonize the process.
47                 -E $env
48                         Rack env to use.  (Defaults to "production".)
49         EOS
50         exit c
51 end
52
53 TopDir = File.dirname(__dir__)
54 rainbow_args = {
55         "-c" => "#{TopDir}/conf/rainbows.rb",
56         "-l" => "localhost:8891",
57         "-E" => "production",
58 }
59 rainbow_flags = []
60
61
62 until args.empty?
63         case args[0]
64         when '-h', '-help', '--help'
65                 usage! $stdout, 0
66         when '-l', '-E'
67                 rainbow_args[args[0]] = args[1]
68                 usage! if args[1].nil?
69                 args.shift
70         when '-D'
71                 rainbow_flags << args[0]
72         when '--'
73                 args.shift
74                 break
75         when /^-/
76                 usage!
77         else
78                 break
79         end
80         args.shift
81 end
82
83 exec(*[
84         'rainbows',
85         *rainbow_flags, 
86         *rainbow_args.to_a.flatten,
87         "#{TopDir}/config.ru"
88 ])