This repository has been archived by the owner on Jul 23, 2023. It is now read-only.
/
slanger
executable file
·137 lines (105 loc) · 4.32 KB
/
slanger
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
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
#!/usr/bin/env ruby
# encoding: utf-8
require 'optparse'
require 'eventmachine'
require 'yaml'
require 'active_support/core_ext/hash'
options = {}
OptionParser.new do |opts|
opts.on '-h', '--help', 'Display this screen' do
puts opts
exit
end
opts.on '-k', '--app_key APP_KEY', "Pusher application key. This parameter is required on command line or in optional config file." do |k|
options[:app_key] = k
end
opts.on '-s', '--secret SECRET', "Pusher application secret. This parameter is required on command line or in optional config file." do |k|
options[:secret] = k
end
opts.on '-C', '--config_file FILE', "Path to Yaml file that can contain all configuration options, including required ones." do |k|
options[:config_file] = k
end
opts.on '-r', '--redis_address URL', "Address to bind to (Default: redis://127.0.0.1:6379/0)" do |h|
options[:redis_address] = h
end
opts.on '-a', '--api_host HOST', "API service address (Default: 0.0.0.0:4567)" do |p|
options[:api_host], options[:api_port] = p.split(':')
end
opts.on '-w', '--websocket_host HOST', "WebSocket service address (Default: 0.0.0.0:8080)" do |p|
options[:websocket_host], options[:websocket_port] = p.split(':')
end
opts.on '-i', '--require FILE', "Require a file before starting Slanger" do |p|
options[:require] ||= []
options[:require] << p
end
opts.on '-p', '--private_key_file FILE', "Private key file for SSL transport" do |p|
options[:tls_options] ||= {}
options[:tls_options][:private_key_file] = p
end
opts.on '-b', '--webhook_url URL', "Callback URL for webhooks" do |p|
options[:webhook_url] = p
end
opts.on '-c', '--cert_file FILE', "Certificate file for SSL transport" do |p|
options[:tls_options] ||= {}
options[:tls_options][:cert_chain_file] = p
end
opts.on "-v", "--[no-]verbose", "Run verbosely" do |v|
options[:debug] = v
end
opts.on "-t" "--activity_timeout", "Activity (ping-pong) Timeout" do |t|
options[:activity_timeout] = t
end
opts.on '--pid_file PIDFILE', "The Slanger process ID file name." do |k|
options[:pid_file] = k
end
opts.parse!
if options[:config_file] and File.exists? options[:config_file]
config_file_contents = YAML::load(File.open(options[:config_file]))
options.reverse_merge! config_file_contents.deep_symbolize_keys!
end
%w<app_key secret>.each do |parameter|
unless options[parameter.to_sym]
puts "--#{parameter} STRING is a required argument. Use your Pusher #{parameter}.\n"
puts opts
exit
end
end
end
if options[:tls_options]
[:cert_chain_file, :private_key_file].each do |param|
raise RuntimeError.new "Both --cert_file and --private_key_file need to be specified" unless options[:tls_options][param]
raise RuntimeError.new "--#{param} does not exist at `#{options[:tls_options][param]}`" unless File.exists? options[:tls_options][param]
end
end
STDOUT.sync = true
case
when EM.epoll? then EM.epoll
when EM.kqueue? then EM.kqueue
end
EM.run do
File.tap { |f| require f.expand_path(f.join(f.dirname(__FILE__),'..', 'slanger.rb')) }
Slanger::Config.load options
# Write PID to file
unless options[:pid_file].nil?
File.open(options[:pid_file], 'w') { |f| f.puts Process.pid }
end
Slanger::Service.run
puts "\n"
puts "\n"
puts " .d8888b. 888 "
puts " d88P Y88b 888 "
puts " Y88b. 888 "
puts ' "Y888b. 888 8888b. 88888b. .d88b. .d88b. 888d888 '
puts ' "Y88b. 888 "88b 888 "88b d88P"88b d8P Y8b 888P" '
puts ' "888 888 .d888888 888 888 888 888 88888888 888 '
puts " Y88b d88P 888 888 888 888 888 Y88b 888 Y8b. 888 "
puts ' "Y8888P" 888 "Y888888 888 888 "Y88888 "Y8888 888 '
puts " 888 "
puts " Y8b d88P "
puts ' "Y88P" '
puts "\n" * 2
puts "Running Slanger v.#{Slanger::VERSION}"
puts "\n"
puts "Slanger API server listening on port #{Slanger::Config.api_port}"
puts "Slanger WebSocket server listening on port #{Slanger::Config.websocket_port}"
end