cs-service 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +21 -15
- data/config/caishuo.eye +2 -1
- data/config/env.rb +0 -0
- data/config/processes/project.rb +48 -0
- data/config/processes/puma.rb +6 -3
- data/config/processes/scheduler.rb +10 -11
- data/config/processes/sneaker.rb +6 -5
- data/config/processes/worker.rb +2 -3
- data/cs-service.gemspec +1 -0
- data/lib/cs/service/cli.rb +88 -42
- data/lib/cs/service/motd.rb +5 -1
- data/lib/cs/service/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68a3a808e4be8df60711d444aae302a3f9623a5f
|
4
|
+
data.tar.gz: c1b395f6d0e704454ee8c727e8af77457136f532
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19e123ff7c164f9b50faee7f6c153b8c93698e7c7986ad852e433ffcac254ffdc1f12127bb1de7f3b8e034c1ffb371473258cfee893743a5a2c99979fed901be
|
7
|
+
data.tar.gz: 6679bfcafaab9900b51e4692d7bf625ebfdc2a9abbb84b355f5f9cfe064c4f608c239f4107afb2f0becaa02f6f3e09a7e53c2ac66fd47fd2953451d9aebce295
|
data/README.md
CHANGED
@@ -1,28 +1,35 @@
|
|
1
1
|
# Cs::Service
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
cs-service 财说服务管理工具
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
|
7
|
+
$ gem install cs-service
|
10
8
|
|
11
|
-
|
12
|
-
gem 'cs-service'
|
13
|
-
```
|
9
|
+
## Commands:
|
14
10
|
|
15
|
-
|
11
|
+
cs-service env [ENV_NAME] # 环境变量检查
|
12
|
+
cs-service eye ...ARGS # 执行eye口令, 详细参考 cs-service eye
|
13
|
+
cs-service help [COMMAND] # 帮助
|
14
|
+
cs-service info [NAME] # 查看当前运行状态
|
15
|
+
cs-service load [FILE] # 加载配置文件,为空时加载默认配置
|
16
|
+
cs-service quit # 退出 cs-service
|
16
17
|
|
17
|
-
|
18
|
+
### Step1 加载配置
|
18
19
|
|
19
|
-
|
20
|
+
$ cs-service load
|
20
21
|
|
21
|
-
|
22
|
+
### Step2 检查配置是否生效
|
22
23
|
|
23
|
-
|
24
|
+
$ cs-service env
|
25
|
+
|
26
|
+
### Step3 如果环境设置正确,则启动项目
|
27
|
+
|
28
|
+
$ cs-service start # 启动所有项目
|
29
|
+
$ cs-service start web # 启动caishuo主站
|
30
|
+
$ cs-service start rest_server # 启动Rest Server
|
31
|
+
$ cs-service start trading_server # 启动Trading Server
|
24
32
|
|
25
|
-
TODO: Write usage instructions here
|
26
33
|
|
27
34
|
## Development
|
28
35
|
|
@@ -37,5 +44,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
37
44
|
|
38
45
|
## License
|
39
46
|
|
40
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
47
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/config/caishuo.eye
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
Eye.load('processes/*.rb')
|
1
|
+
Eye.load('processes/*.rb')
|
2
|
+
run_projects
|
data/config/env.rb
ADDED
File without changes
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
# 启动项目
|
3
|
+
def run_projects
|
4
|
+
fetch_config_files(project_roots).each do |root_path|
|
5
|
+
project(root_path, ENV['RACK_ENV']||'development')
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
# 启动单独项目
|
10
|
+
def project(root_path, env = :development)
|
11
|
+
config = load_config(root_path, env)
|
12
|
+
return unless config[:app_name]
|
13
|
+
|
14
|
+
Eye.application config[:app_name] do
|
15
|
+
env 'RAILS_ENV' => env,
|
16
|
+
'RACK_ENV' => env,
|
17
|
+
'RAILS_ROOT' => root_path,
|
18
|
+
'RACK_ROOT' => root_path
|
19
|
+
|
20
|
+
working_dir root_path
|
21
|
+
|
22
|
+
process_global_app(self)
|
23
|
+
|
24
|
+
process_puma(self, config[:puma]) if config[:puma]
|
25
|
+
process_sneaker(self, config[:sneaker]) if config[:sneaker]
|
26
|
+
group :resque do
|
27
|
+
process_scheduler(self) if config[:resque][:scheduler]
|
28
|
+
process_worker(self, config[:resque][:worker]) if config[:resque][:worker]
|
29
|
+
end if config[:resque]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def project_roots
|
36
|
+
[ENV['REST_SERVER_ROOT'], ENV['TRADING_SERVER_ROOT'], ENV['RAILS_ROOT']]
|
37
|
+
end
|
38
|
+
|
39
|
+
def load_config(root_path, env = :development)
|
40
|
+
Hashie.symbolize_keys(YAML.load_file(File.join(root_path, 'config', 'project.yml'))[env.to_s])
|
41
|
+
end
|
42
|
+
|
43
|
+
def fetch_config_files(project_roots = [])
|
44
|
+
project_roots << ENV['CURRENT_PWD']
|
45
|
+
a = project_roots.compact.uniq.find_all{|project_root| Eye::Logger.info('='*100 + File.join(project_root, 'config', 'project.yml')); File.exist?(File.join(project_root, 'config', 'project.yml'))}
|
46
|
+
Eye::Logger.info('========='*100 + ENV['PWD'])
|
47
|
+
a
|
48
|
+
end
|
data/config/processes/puma.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
def process_puma(proxy)
|
1
|
+
def process_puma(proxy, workers: 2, threads: 8, cpu: 50, memory: 300)
|
2
2
|
proxy.process :puma do
|
3
|
+
env 'THREADS' => threads,
|
4
|
+
'WORKERS' => workers
|
5
|
+
|
3
6
|
daemonize true
|
4
7
|
pid_file "tmp/pids/puma.pid"
|
5
8
|
start_command "bundle exec puma -C config/puma.conf.rb --daemon"
|
@@ -7,8 +10,8 @@ def process_puma(proxy)
|
|
7
10
|
stdall 'log/puma.log'
|
8
11
|
|
9
12
|
monitor_children do
|
10
|
-
check :memory, below:
|
11
|
-
check :cpu, below:
|
13
|
+
check :memory, below: memory, times: 3
|
14
|
+
check :cpu, below: cpu, times: 3
|
12
15
|
end
|
13
16
|
end
|
14
17
|
end
|
@@ -1,14 +1,13 @@
|
|
1
1
|
def process_scheduler(proxy)
|
2
2
|
proxy.process :scheduler do
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
daemonize true
|
4
|
+
pid_file 'tmp/pids/scheduler.pid'
|
5
|
+
stdall 'log/scheduler.log'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
7
|
+
env 'BACKGROUND' => 'yes',
|
8
|
+
'PIDFILE' => 'tmp/pids/scheduler.pid',
|
9
|
+
'VERBOSE' => '1',
|
10
|
+
'NEWRELIC_ENABLE' => 'false'
|
11
|
+
start_command 'bundle exec rake environment resque:scheduler'
|
12
|
+
end
|
13
|
+
end
|
data/config/processes/sneaker.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
-
def process_sneaker(proxy,
|
1
|
+
def process_sneaker(proxy, queue: '')
|
2
|
+
return if queue.blank?
|
2
3
|
proxy.process :sneaker do
|
3
4
|
daemonize true
|
4
5
|
pid_file "tmp/pids/sneakers.pid"
|
5
6
|
stdall 'log/sneakers.log'
|
6
7
|
|
7
8
|
env 'PIDFILE' => "tmp/pids/sneakers.pid",
|
8
|
-
'
|
9
|
-
'WORKERS' => workers
|
9
|
+
'WORKERS' => queue
|
10
10
|
|
11
11
|
start_command 'bundle exec rake sneakers:run'
|
12
12
|
|
13
|
+
use_leaf_child false
|
14
|
+
|
13
15
|
monitor_children
|
14
16
|
end
|
15
|
-
|
16
|
-
end
|
17
|
+
end
|
data/config/processes/worker.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
def process_worker(proxy,
|
2
|
-
|
1
|
+
def process_worker(proxy, pool: {default: 8})
|
2
|
+
pool.map { |k, v| Array.new(v, k) }.flatten.each_with_index do |queue_name, index|
|
3
3
|
n = index + 1
|
4
4
|
proxy.process "worker_#{n}" do
|
5
5
|
daemonize true
|
@@ -7,7 +7,6 @@ def process_worker(proxy, queues)
|
|
7
7
|
stdall 'log/resque.log'
|
8
8
|
|
9
9
|
env 'PIDFILE' => "tmp/pids/worker#{n}.pid",
|
10
|
-
'RACK_ENV' => RACK_ENV,
|
11
10
|
'QUEUE' => "@#{queue_name}",
|
12
11
|
'TERM_CHILD' => n,
|
13
12
|
'RESQUE_TERM_TIMEOUT' => 10,
|
data/cs-service.gemspec
CHANGED
data/lib/cs/service/cli.rb
CHANGED
@@ -1,84 +1,130 @@
|
|
1
1
|
require 'thor'
|
2
2
|
module Cs
|
3
3
|
module Service
|
4
|
-
|
5
4
|
HOME_PATH = File.realpath(File.join(File.dirname(__FILE__), '..', '..', '..'))
|
6
5
|
|
7
6
|
class Eye < ::Eye::Cli
|
8
7
|
end
|
9
8
|
|
9
|
+
# Cli
|
10
10
|
class Cli < Thor
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
ENVS = %w(REST_SERVER_ROOT TRADING_SERVER_ROOT RAILS_ROOT RACK_ENV).freeze
|
12
|
+
PROJECTS = %w( rest_server trading_server web).freeze
|
13
|
+
CONFIG_FILES = {
|
14
|
+
web: ENV['RAILS_ROOT'],
|
15
|
+
trading_server: ENV['TRADING_SERVER_ROOT'],
|
16
|
+
rest_server: ENV['REST_SERVER_ROOT']
|
17
|
+
}
|
18
|
+
|
19
|
+
desc 'load', '首次加载配置文件'
|
20
|
+
method_option :force, type: :boolean, aliases: '-f', desc: '强制重新加载配置文件'
|
21
|
+
def load_conf
|
22
|
+
quit if options[:force]
|
23
|
+
run_eye("load #{File.join(HOME_PATH, 'config/caishuo.eye')}")
|
17
24
|
end
|
18
25
|
|
19
|
-
desc '
|
26
|
+
desc 'env [ENV_NAME]', '环境变量检查'
|
20
27
|
long_desc <<-LONGDESC
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
28
|
+
请声明以下环境变量设置:\n
|
29
|
+
REST_SERVER_ROOT
|
30
|
+
TRADING_SERVER_ROOT
|
31
|
+
RAILS_ROOT
|
32
|
+
RACK_ENV
|
25
33
|
LONGDESC
|
26
|
-
|
27
|
-
def check(env_name = nil)
|
34
|
+
def env(env_name = nil)
|
28
35
|
if env_name.nil?
|
29
|
-
|
30
|
-
puts "#{e}=#{ENV[e]}"
|
31
|
-
end
|
36
|
+
print_env
|
32
37
|
elsif ENV[env_name]
|
33
38
|
puts "#{env_name}=#{ENV[env_name]}"
|
34
39
|
else
|
35
|
-
|
40
|
+
say "#{env_name} is blank", :yellow
|
36
41
|
end
|
42
|
+
say "\nConfig Files:"
|
43
|
+
fetch_config_files
|
44
|
+
say "详见 cs-service help env"
|
37
45
|
end
|
38
46
|
|
39
|
-
desc 'info [
|
47
|
+
desc 'info [PROJECT]', '查看当前运行状态'
|
40
48
|
def info(name = nil)
|
41
49
|
run_eye("info #{name}")
|
42
50
|
end
|
43
51
|
|
44
|
-
desc '
|
52
|
+
desc 'start [PROJECT]', '启动项目'
|
53
|
+
def start(name = nil)
|
54
|
+
name ||= PROJECTS * ' '
|
55
|
+
run_eye("start #{name}")
|
56
|
+
end
|
57
|
+
|
58
|
+
desc 'stop [PROJECT]', '停止项目'
|
59
|
+
def stop(name = nil)
|
60
|
+
name ||= PROJECTS * ' '
|
61
|
+
run_eye("stop #{name}")
|
62
|
+
end
|
63
|
+
|
64
|
+
desc 'restart [PROJECT]', '重启项目'
|
65
|
+
def restart(name = nil)
|
66
|
+
name ||= PROJECTS * ' '
|
67
|
+
run_eye("restart #{name}")
|
68
|
+
end
|
69
|
+
|
70
|
+
desc 'quit', '退出 cs-service'
|
45
71
|
def quit
|
46
|
-
|
72
|
+
invoke(:stop)
|
73
|
+
run_eye('quit')
|
47
74
|
end
|
48
75
|
|
49
|
-
desc
|
76
|
+
desc 'help [COMMAND]', '帮助'
|
50
77
|
def help(command = nil, subcommand = false)
|
51
|
-
|
78
|
+
say Motd.msg unless command
|
52
79
|
super(command, subcommand)
|
53
80
|
end
|
54
81
|
|
55
|
-
|
56
|
-
# desc command, "same as eye #{command}"
|
57
|
-
# define_method command do |args|
|
58
|
-
# run_eye(args)
|
59
|
-
# end
|
60
|
-
# end
|
61
|
-
|
62
|
-
desc 'eye ...ARGS', 'manage set of tracked repositories'
|
82
|
+
desc 'eye ...ARGS', '执行eye口令, 详细参考 cs-service eye'
|
63
83
|
subcommand 'eye', Eye
|
64
84
|
|
65
|
-
# desc 'eye [ARGS]', 'run eye'
|
66
|
-
# def eye(args = nil)
|
67
|
-
# run_eye(args)
|
68
|
-
# end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
85
|
private
|
73
86
|
|
87
|
+
def print_env
|
88
|
+
say("Env: #{rack_env}", :green)
|
89
|
+
ENVS.each do |e|
|
90
|
+
puts " #{e}=#{ENV[e]}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
74
94
|
def run_eye(args = '')
|
75
|
-
|
95
|
+
puts `CURRENT_PWD=#{current_root} eye #{args}`
|
76
96
|
end
|
77
97
|
|
78
|
-
|
98
|
+
# 查找有效的配置文件
|
99
|
+
def fetch_config_files
|
100
|
+
config_files = CONFIG_FILES.values.compact.uniq.map do |file|
|
101
|
+
check_config_file(file)
|
102
|
+
end.compact
|
103
|
+
return config_files unless config_files == []
|
104
|
+
check_config_file(current_root).nil? ? [] : File.join(current_root, 'config', 'project.yml')
|
105
|
+
end
|
79
106
|
|
107
|
+
# 判断当个配置文件是否存在
|
108
|
+
def check_config_file(file_root)
|
109
|
+
file = File.join(file_root, 'config', 'project.yml')
|
110
|
+
if File.exist?(file)
|
111
|
+
say("Found: #{file}", :green)
|
112
|
+
file
|
113
|
+
else
|
114
|
+
say("Not Found: #{file}", :red)
|
115
|
+
nil
|
116
|
+
end
|
117
|
+
end
|
80
118
|
|
81
|
-
|
119
|
+
# 当前root
|
120
|
+
def current_root
|
121
|
+
File.expand_path('.')
|
122
|
+
end
|
82
123
|
|
124
|
+
# 当前运行环境
|
125
|
+
def rack_env
|
126
|
+
ENV['RACK_ENV'] || 'development'
|
127
|
+
end
|
128
|
+
end
|
83
129
|
end
|
84
|
-
end
|
130
|
+
end
|
data/lib/cs/service/motd.rb
CHANGED
data/lib/cs/service/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cs-service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wangchangming
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: hashie
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +96,9 @@ files:
|
|
82
96
|
- Rakefile
|
83
97
|
- bin/cs-service
|
84
98
|
- config/caishuo.eye
|
99
|
+
- config/env.rb
|
85
100
|
- config/processes/global.rb
|
101
|
+
- config/processes/project.rb
|
86
102
|
- config/processes/puma.rb
|
87
103
|
- config/processes/realtime.rb
|
88
104
|
- config/processes/scheduler.rb
|