This repository has been archived by the owner on Oct 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipemaster
100 lines (78 loc) · 2.6 KB
/
pipemaster
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/this/will/be/overwritten/or/wrapped/anyways/do/not/worry/ruby
# -*- encoding: binary -*-
require "pipemaster"
require "optparse"
ENV["PIPE_ENV"] ||= "development"
server = false
daemonize = false
listeners = []
options = { :listeners => listeners }
opts = OptionParser.new("", 24, ' ') do |opts|
opts.banner = "Usage: #{File.basename($0)}\n" \
"[ruby options] [pipemaster options] command [args]\n" \
"[ruby options] [pipemaster options] --server [Pipefile]"
opts.separator "Ruby options:"
lineno = 1
opts.on("-e", "--eval LINE", "evaluate a LINE of code") do |line|
eval line, TOPLEVEL_BINDING, "-e", lineno
lineno += 1
end
opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") do
$DEBUG = true
end
opts.on("-w", "--warn", "turn warnings on for your script") do
$-w = true
end
opts.on("-I", "--include PATH",
"specify $LOAD_PATH (may be used more than once)") do |path|
$LOAD_PATH.unshift(*path.split(/:/))
end
opts.on("-r", "--require LIBRARY",
"require the library, before executing your script") do |library|
require library
end
opts.separator "Pipemaster options:"
opts.on("-s", "--socket {HOST:PORT|PATH}",
"communicate on HOST:PORT or PATH",
"for server, this may be specified multiple times",
"(default: #{Pipemaster::DEFAULT_LISTEN})") do |address|
listeners << address
end
opts.on("-E", "--env ENVIRONMENT",
"use ENVIRONMENT for defaults (default: development)") do |e|
ENV["PIPE_ENV"] = e
end
opts.on("-S", "--server", "run as server (default: client)") do |s|
server = s ? true : false
end
opts.on("-D", "--daemonize", "run daemonized in the background") do |d|
daemonize = d ? true : false
end
opts.separator "Common options:"
opts.on_tail("-h", "--help", "Show this message") do
puts opts.to_s.gsub(/^.*DEPRECATED.*$/s, '')
exit
end
opts.on_tail("-v", "--version", "Show version") do
puts "Pipemaster v#{Pipemaster::VERSION}"
exit
end
opts.parse! ARGV
end
if server
gem "unicorn"
require "pipemaster/server"
require "unicorn/launcher"
config = ARGV[0] || "Pipefile"
abort "configuration file #{config} not found" unless File.exist?(config)
options[:config_file] = config
options[:working_directory] = File.dirname(config)
Unicorn::Launcher.daemonize!(options) if daemonize
Pipemaster.run(options)
else
require "pipemaster/client"
client = Pipemaster::Client.new(listeners.first)
client.input = $stdin unless $stdin.isatty
client.output = $stdout
exit client.request(*ARGV)
end