Skip to content

Commit 70dcc0a

Browse files
committed
Yep WebSocket Server
0 parents  commit 70dcc0a

20 files changed

+662
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
log
2+
.env
3+
.ruby-version
4+
*.staging
5+
*.production

Capfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Load DSL and set up stages
2+
require "capistrano/setup"
3+
4+
# Include default deployment tasks
5+
require "capistrano/deploy"
6+
7+
# Include tasks from other gems included in your Gemfile
8+
#
9+
# For documentation on these, see for example:
10+
#
11+
# https://github.com/capistrano/rvm
12+
# https://github.com/capistrano/rbenv
13+
# https://github.com/capistrano/chruby
14+
# https://github.com/capistrano/bundler
15+
# https://github.com/capistrano/rails
16+
# https://github.com/capistrano/passenger
17+
#
18+
# require 'capistrano/rvm'
19+
require 'capistrano/rbenv'
20+
# require 'capistrano/chruby'
21+
require 'capistrano/bundler'
22+
# require 'capistrano/rails/assets'
23+
# require 'capistrano/rails/migrations'
24+
# require 'capistrano/passenger'
25+
26+
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
27+
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

Gemfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
source 'https://ruby.taobao.org'
2+
3+
gem 'goliath', '~> 1.0', '>= 1.0.4'
4+
gem 'dotenv', '~> 2.1', '>= 2.1.1'
5+
gem 'faye', '~> 1.1', '>= 1.1.2'
6+
gem 'faye-websocket', '~> 0.10.3'
7+
gem 'permessage_deflate', '~> 0.1.2'
8+
gem 'redis', '~> 3.3'
9+
gem 'capistrano', '~> 3.5'
10+
gem 'capistrano-rbenv', '~> 2.0', '>= 2.0.4'
11+
gem 'capistrano-bundler', '~> 1.1', '>= 1.1.4'
12+
13+
group :development, :test do
14+
gem 'pry-byebug', '~> 3.3'
15+
end

Gemfile.lock

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
GEM
2+
remote: https://ruby.taobao.org/
3+
specs:
4+
addressable (2.4.0)
5+
airbrussh (1.0.2)
6+
sshkit (>= 1.6.1, != 1.7.0)
7+
async-rack (0.5.1)
8+
rack (~> 1.1)
9+
byebug (8.2.5)
10+
capistrano (3.5.0)
11+
airbrussh (>= 1.0.0)
12+
capistrano-harrow
13+
i18n
14+
rake (>= 10.0.0)
15+
sshkit (>= 1.9.0)
16+
capistrano-bundler (1.1.4)
17+
capistrano (~> 3.1)
18+
sshkit (~> 1.2)
19+
capistrano-harrow (0.5.1)
20+
capistrano-rbenv (2.0.4)
21+
capistrano (~> 3.1)
22+
sshkit (~> 1.3)
23+
coderay (1.1.1)
24+
cookiejar (0.3.0)
25+
dotenv (2.1.1)
26+
em-http-request (1.1.3)
27+
addressable (>= 2.3.4)
28+
cookiejar (<= 0.3.0)
29+
em-socksify (>= 0.3)
30+
eventmachine (>= 1.0.3)
31+
http_parser.rb (>= 0.6.0)
32+
em-socksify (0.3.1)
33+
eventmachine (>= 1.0.0.beta.4)
34+
em-synchrony (1.0.5)
35+
eventmachine (>= 1.0.0.beta.1)
36+
em-websocket (0.3.8)
37+
addressable (>= 2.1.1)
38+
eventmachine (>= 0.12.9)
39+
eventmachine (1.2.0.1)
40+
faye (1.1.2)
41+
cookiejar (>= 0.3.0)
42+
em-http-request (>= 0.3.0)
43+
eventmachine (>= 0.12.0)
44+
faye-websocket (>= 0.9.1)
45+
multi_json (>= 1.0.0)
46+
rack (>= 1.0.0)
47+
websocket-driver (>= 0.5.1)
48+
faye-websocket (0.10.3)
49+
eventmachine (>= 0.12.0)
50+
websocket-driver (>= 0.5.1)
51+
git-version-bump (0.15.1)
52+
goliath (1.0.4)
53+
async-rack
54+
em-synchrony (>= 1.0.0)
55+
em-websocket (= 0.3.8)
56+
eventmachine (>= 1.0.0.beta.4)
57+
http_parser.rb (= 0.6.0)
58+
log4r
59+
multi_json
60+
rack (>= 1.2.2)
61+
rack-contrib
62+
rack-respond_to
63+
http_parser.rb (0.6.0)
64+
i18n (0.7.0)
65+
log4r (1.1.10)
66+
method_source (0.8.2)
67+
multi_json (1.12.0)
68+
net-scp (1.2.1)
69+
net-ssh (>= 2.6.5)
70+
net-ssh (3.1.1)
71+
permessage_deflate (0.1.2)
72+
pry (0.10.3)
73+
coderay (~> 1.1.0)
74+
method_source (~> 0.8.1)
75+
slop (~> 3.4)
76+
pry-byebug (3.3.0)
77+
byebug (~> 8.0)
78+
pry (~> 0.10)
79+
rack (1.6.4)
80+
rack-accept-media-types (0.9)
81+
rack-contrib (1.4.0)
82+
git-version-bump (~> 0.15)
83+
rack (~> 1.4)
84+
rack-respond_to (0.9.8)
85+
rack-accept-media-types (>= 0.6)
86+
rake (11.1.2)
87+
redis (3.3.0)
88+
slop (3.6.0)
89+
sshkit (1.10.0)
90+
net-scp (>= 1.1.2)
91+
net-ssh (>= 2.8.0)
92+
websocket-driver (0.6.3)
93+
websocket-extensions (>= 0.1.0)
94+
websocket-extensions (0.1.2)
95+
96+
PLATFORMS
97+
ruby
98+
99+
DEPENDENCIES
100+
capistrano (~> 3.5)
101+
capistrano-bundler (~> 1.1, >= 1.1.4)
102+
capistrano-rbenv (~> 2.0, >= 2.0.4)
103+
dotenv (~> 2.1, >= 2.1.1)
104+
faye (~> 1.1, >= 1.1.2)
105+
faye-websocket (~> 0.10.3)
106+
goliath (~> 1.0, >= 1.0.4)
107+
permessage_deflate (~> 0.1.2)
108+
pry-byebug (~> 3.3)
109+
redis (~> 3.3)
110+
111+
BUNDLED WITH
112+
1.10.6

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Yep WebSocket Server
2+
3+
## Start Server
4+
5+
```
6+
bundle exec ruby yep_ws_server.rb -l log/development.log -e development -p 9000 -v
7+
```

config/application.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require_relative 'boot'
2+
require 'dotenv'
3+
Dotenv.load!
4+
INTERVAL = ENV['INTERVAL'].to_i > 0 ? ENV['INTERVAL'].to_i : 30
5+
6+
Bundler.require :default
7+
require 'goliath'
8+
Bundler.require Goliath.env
9+
10+
Dir[File.expand_path('../../config/initializers/*.rb', __FILE__)].each do |file|
11+
require file
12+
end

config/boot.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require 'rubygems'
2+
require 'bundler/setup'

config/deploy.rb

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# config valid only for current version of Capistrano
2+
lock '3.5.0'
3+
4+
set :application, 'yep_ws_server'
5+
set :repo_url, '[email protected]:me/my_repo.git'
6+
7+
# Default branch is :master
8+
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
9+
10+
# Default deploy_to directory is /var/www/my_app_name
11+
set :deploy_to, "/u/apps/#{fetch(:application)}"
12+
13+
# Default value for :scm is :git
14+
# set :scm, :git
15+
16+
# Default value for :format is :airbrussh.
17+
# set :format, :airbrussh
18+
19+
# You can configure the Airbrussh format using :format_options.
20+
# These are the defaults.
21+
# set :format_options, command_output: true, log_file: 'log/capistrano.log', color: :auto, truncate: :auto
22+
23+
# Default value for :pty is false
24+
# set :pty, true
25+
26+
# Default value for :linked_files is []
27+
set :linked_files, fetch(:linked_files, ['.env', '.ruby-version', 'yep_ws_server.pill'])
28+
29+
# Default value for linked_dirs is []
30+
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets')
31+
32+
# Default value for default_env is {}
33+
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
34+
35+
# Default value for keep_releases is 5
36+
# set :keep_releases, 5
37+
38+
set :rbenv_ruby, '2.2.2'
39+
set :rbenv_custom_path, '/opt/rbenv'
40+
41+
# Server
42+
set :goliath_worker_processes, 1
43+
set :goliath_start_port, 10000
44+
set :goliath_pidfile_path, 'tmp/pids'
45+
set :goliath_env, fetch(:stage)
46+
47+
namespace :deploy do
48+
task :start do
49+
invoke 'yep_ws_server:start'
50+
invoke 'bluepill:load'
51+
end
52+
53+
task :restart do
54+
invoke 'yep_ws_server:restart'
55+
end
56+
57+
task :stop do
58+
invoke 'bluepill:quit'
59+
invoke 'yep_ws_server:stop'
60+
end
61+
62+
after 'deploy:published', 'yep_ws_server:restart', 'bluepill:load'
63+
end

config/deploy/production.rb

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# server-based syntax
2+
# ======================
3+
# Defines a single server with a list of roles and multiple properties.
4+
# You can define all roles on a single server, or split them:
5+
6+
# server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value
7+
# server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
8+
# server 'db.example.com', user: 'deploy', roles: %w{db}
9+
server 'faye-deploy', user: 'deploy', roles: %w{web app db}
10+
set :goliath_worker_processes, 10
11+
12+
13+
14+
# role-based syntax
15+
# ==================
16+
17+
# Defines a role with one or multiple servers. The primary server in each
18+
# group is considered to be the first unless any hosts have the primary
19+
# property set. Specify the username and a domain or IP for the server.
20+
# Don't use `:all`, it's a meta role.
21+
22+
# role :app, %w{[email protected]}, my_property: :my_value
23+
# role :web, %w{[email protected] [email protected]}, other_property: :other_value
24+
# role :db, %w{[email protected]}
25+
26+
27+
28+
# Configuration
29+
# =============
30+
# You can set any configuration variable like in config/deploy.rb
31+
# These variables are then only loaded and set in this stage.
32+
# For available Capistrano configuration variables see the documentation page.
33+
# http://capistranorb.com/documentation/getting-started/configuration/
34+
# Feel free to add new variables to customise your setup.
35+
36+
37+
38+
# Custom SSH Options
39+
# ==================
40+
# You may pass any option but keep in mind that net/ssh understands a
41+
# limited set of options, consult the Net::SSH documentation.
42+
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
43+
#
44+
# Global options
45+
# --------------
46+
# set :ssh_options, {
47+
# keys: %w(/home/rlisowski/.ssh/id_rsa),
48+
# forward_agent: false,
49+
# auth_methods: %w(password)
50+
# }
51+
#
52+
# The server-based syntax can be used to override options:
53+
# ------------------------------------
54+
# server 'example.com',
55+
# user: 'user_name',
56+
# roles: %w{web app},
57+
# ssh_options: {
58+
# user: 'user_name', # overrides user setting above
59+
# keys: %w(/home/user_name/.ssh/id_rsa),
60+
# forward_agent: false,
61+
# auth_methods: %w(publickey password)
62+
# # password: 'please use keys'
63+
# }

config/deploy/staging.rb

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# server-based syntax
2+
# ======================
3+
# Defines a single server with a list of roles and multiple properties.
4+
# You can define all roles on a single server, or split them:
5+
6+
# server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value
7+
# server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
8+
# server 'db.example.com', user: 'deploy', roles: %w{db}
9+
server 'staging-deploy', user: 'deploy', roles: %w{web app db}
10+
set :goliath_worker_processes, 1
11+
12+
13+
# role-based syntax
14+
# ==================
15+
16+
# Defines a role with one or multiple servers. The primary server in each
17+
# group is considered to be the first unless any hosts have the primary
18+
# property set. Specify the username and a domain or IP for the server.
19+
# Don't use `:all`, it's a meta role.
20+
21+
# role :app, %w{[email protected]}, my_property: :my_value
22+
# role :web, %w{[email protected] [email protected]}, other_property: :other_value
23+
# role :db, %w{[email protected]}
24+
25+
26+
27+
# Configuration
28+
# =============
29+
# You can set any configuration variable like in config/deploy.rb
30+
# These variables are then only loaded and set in this stage.
31+
# For available Capistrano configuration variables see the documentation page.
32+
# http://capistranorb.com/documentation/getting-started/configuration/
33+
# Feel free to add new variables to customise your setup.
34+
35+
36+
37+
# Custom SSH Options
38+
# ==================
39+
# You may pass any option but keep in mind that net/ssh understands a
40+
# limited set of options, consult the Net::SSH documentation.
41+
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
42+
#
43+
# Global options
44+
# --------------
45+
# set :ssh_options, {
46+
# keys: %w(/home/rlisowski/.ssh/id_rsa),
47+
# forward_agent: false,
48+
# auth_methods: %w(password)
49+
# }
50+
#
51+
# The server-based syntax can be used to override options:
52+
# ------------------------------------
53+
# server 'example.com',
54+
# user: 'user_name',
55+
# roles: %w{web app},
56+
# ssh_options: {
57+
# user: 'user_name', # overrides user setting above
58+
# keys: %w(/home/user_name/.ssh/id_rsa),
59+
# forward_agent: false,
60+
# auth_methods: %w(publickey password)
61+
# # password: 'please use keys'
62+
# }

config/environment.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require File.expand_path('../application', __FILE__)

config/initializes/redis.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Redis.current = Redis.new(host: ENV['REDIS_HOST'], port: ENV['REDIS_PORT'], db: ENV['REDIS_DB'])

example.env

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Faye Config
2+
FAYE_SERVER_URL=ws://0.0.0.0:8000/faye
3+
FAYE_SERVER_VERSION=v1
4+
5+
# Redis Config
6+
REDIS_HOST=127.0.0.1
7+
REDIS_PORT=6379
8+
REDIS_DB=1
9+
REDIS_NAMESPACE=park_server_dev:sotre

0 commit comments

Comments
 (0)