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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/starling/server_runner.rb', line 56
def parse_options
self.options = { :host => '127.0.0.1',
:port => 22122,
:path => File.join('', 'var', 'spool', 'starling'),
:log_level => Logger::INFO,
:daemonize => false,
:timeout => 0,
:pid_file => File.join('', 'var', 'run', 'starling.pid') }
OptionParser.new do |opts|
opts.summary_width = 25
opts.banner = "Starling (#{StarlingServer::VERSION})\n\n",
"usage: starling [options...]\n",
" starling --help\n",
" starling --version\n"
opts.separator ""
opts.separator "Configuration:"
opts.on("-f", "--config FILENAME",
"Config file (yaml) to load") do |filename|
load_config_file(filename)
end
opts.on("-q", "--queue_path PATH",
:REQUIRED,
"Path to store Starling queue logs", "(default: #{options[:path]})") do |queue_path|
options[:path] = File.expand_path(queue_path)
end
opts.separator ""; opts.separator "Network:"
opts.on("-hHOST", "--host HOST", "Interface on which to listen (default: #{options[:host]})") do |host|
options[:host] = host
end
opts.on("-pHOST", "--port PORT", Integer, "TCP port on which to listen (default: #{options[:port]})") do |port|
options[:port] = port
end
opts.separator ""; opts.separator "Process:"
opts.on("-d", "Run as a daemon.") do
options[:daemonize] = true
end
opts.on("-PFILE", "--pid FILENAME", "save PID in FILENAME when using -d option.", "(default: #{options[:pid_file]})") do |pid_file|
options[:pid_file] = File.expand_path(pid_file)
end
opts.on("-u", "--user USER", "User to run as") do |user|
options[:user] = user.to_i == 0 ? Etc.getpwnam(user).uid : user.to_i
end
opts.on("-gGROUP", "--group GROUP", "Group to run as") do |group|
options[:group] = group.to_i == 0 ? Etc.getgrnam(group).gid : group.to_i
end
opts.separator ""; opts.separator "Logging:"
opts.on("-L", "--log [FILE]", "Path to print debugging information.") do |log_path|
options[:logger] = File.expand_path(log_path)
end
begin
require 'syslog_logger'
opts.on("-l", "--syslog CHANNEL", "Write logs to the syslog instead of a log file.") do |channel|
options[:syslog_channel] = channel
end
rescue LoadError
end
opts.on("-v", "Increase logging verbosity (may be used multiple times).") do
options[:log_level] -= 1
end
opts.on("-t", "--timeout [SECONDS]", Integer,
"Time in seconds before disconnecting inactive clients (0 to disable).",
"(default: #{options[:timeout]})") do |timeout|
options[:timeout] = timeout
end
opts.separator ""; opts.separator "Miscellaneous:"
opts.on_tail("-?", "--help", "Display this usage information.") do
puts "#{opts}\n"
exit
end
opts.on_tail("-V", "--version", "Print version number and exit.") do
puts "Starling #{StarlingServer::VERSION}\n\n"
exit
end
end.parse!
end
|