cs-service 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a2856bc352649501e862a9da28f00082ddb073ec
4
+ data.tar.gz: a0c4bae9b9b5efd6d4e3a7b69d9742248afa47d3
5
+ SHA512:
6
+ metadata.gz: d268b88ce0ac759287303c50649c544285e9e8fe27efe4a549c6e726e3621bfc840c98d1bf6a6d5e8214e8261fc5b49fccf856360245cead28622c937d8a0443
7
+ data.tar.gz: eba8dea9fe2d86525efa9c801a9de3ba1823623e43a7e41ac452f06615177c3a889da0f7bdcf56f2cecf8737967cfe3215c0269bcf4e8a704625d745c1848b96
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://ruby.taobao.org'
2
+
3
+ # Specify your gem's dependencies in cs-service.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 王长明
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Cs::Service
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cs/service`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cs-service'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install cs-service
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cs-service. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/cs-service ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib]))
3
+ require 'eye'
4
+ require 'cs/service'
5
+
6
+ Cs::Service::Cli.start
@@ -0,0 +1 @@
1
+ Eye.load('processes/*.rb')
@@ -0,0 +1,20 @@
1
+ Eye.config do
2
+ logger '/tmp/eye.log'
3
+ end
4
+
5
+ def process_global_app(proxy)
6
+ proxy.trigger :flapping, times: 3, within: 10.seconds, retry_in: 10.minutes
7
+ proxy.check :cpu, every: 10.seconds, below: 80, times: 3 # global check for all processes
8
+ proxy.chain grace: 5.seconds
9
+
10
+ proxy.start_timeout 20.seconds
11
+ proxy.start_grace 20.seconds
12
+ proxy.stop_timeout 5.seconds
13
+ proxy.restart_grace 20.seconds
14
+ proxy.check_alive_period 1
15
+ proxy.use_leaf_child true
16
+
17
+ proxy.stop_signals [:QUIT, 3.seconds, :TERM, 2.seconds, :KILL]
18
+ proxy.auto_start false
19
+
20
+ end
@@ -0,0 +1,14 @@
1
+ def process_puma(proxy)
2
+ proxy.process :puma do
3
+ daemonize true
4
+ pid_file "tmp/pids/puma.pid"
5
+ start_command "bundle exec puma -C config/puma.conf.rb --daemon"
6
+ restart_command "bundle exec pumactl -S tmp/pids/puma.state -F config/puma.conf.rb phased-restart"
7
+ stdall 'log/puma.log'
8
+
9
+ monitor_children do
10
+ check :memory, below: 500.megabytes, times: 3
11
+ check :cpu, below: 50, times: 3
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ def process_realtime(proxy, queues)
2
+ queues.each do |market, num|
3
+ proxy.group "realtime_#{market}" do
4
+ (1..num).each do |i|
5
+ process("worker_#{market}_#{i}") do
6
+ daemonize true
7
+ pid_file "tmp/pids/realtime_worker_#{market}.#{i}.pid"
8
+ stdall 'log/realtime.log'
9
+
10
+ env 'PIDFILE' => "tmp/pids/realtime_worker_#{market}.#{i}.pid",
11
+ 'RACK_ENV' => RACK_ENV
12
+
13
+ start_command "bundle exec rake stock:realtime_#{market} --trace"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ def process_scheduler(proxy)
2
+ proxy.process :scheduler do
3
+ daemonize true
4
+ pid_file 'tmp/pids/scheduler.pid'
5
+ stdall 'log/scheduler.log'
6
+
7
+ env 'BACKGROUND' => 'yes',
8
+ 'PIDFILE' => 'tmp/pids/scheduler.pid',
9
+ 'RACK_ENV' => RACK_ENV,
10
+ 'VERBOSE' => '1',
11
+ 'NEWRELIC_ENABLE' => 'false'
12
+ start_command 'bundle exec rake environment resque:scheduler'
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ def process_sneaker(proxy, workers)
2
+ proxy.process :sneaker do
3
+ daemonize true
4
+ pid_file "tmp/pids/sneakers.pid"
5
+ stdall 'log/sneakers.log'
6
+
7
+ env 'PIDFILE' => "tmp/pids/sneakers.pid",
8
+ 'RACK_ENV' => RACK_ENV,
9
+ 'WORKERS' => workers
10
+
11
+ start_command 'bundle exec rake sneakers:run'
12
+
13
+ monitor_children
14
+ end
15
+
16
+ end
@@ -0,0 +1,22 @@
1
+ def process_worker(proxy, queues)
2
+ queues.map { |k, v| Array.new(v, k) }.flatten.each_with_index do |queue_name, index|
3
+ n = index + 1
4
+ proxy.process "worker_#{n}" do
5
+ daemonize true
6
+ pid_file "tmp/pids/worker#{n}.pid"
7
+ stdall 'log/resque.log'
8
+
9
+ env 'PIDFILE' => "tmp/pids/worker#{n}.pid",
10
+ 'RACK_ENV' => RACK_ENV,
11
+ 'QUEUE' => "@#{queue_name}",
12
+ 'TERM_CHILD' => n,
13
+ 'RESQUE_TERM_TIMEOUT' => 10,
14
+ 'BACKGROUND' => 'yes',
15
+ 'INTERVAL' => 0.2
16
+
17
+ start_command 'bundle exec rake environment resque:work --trace'
18
+
19
+ monitor_children
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cs/service/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cs-service"
8
+ spec.version = Cs::Service::VERSION
9
+ spec.authors = ["wangchangming"]
10
+ spec.email = ["wangchangming@caishuo.com"]
11
+
12
+ spec.summary = %q{caishuo service}
13
+ spec.description = %q{caishuo service}
14
+ spec.homepage = "http://www.caishuo.com"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "Set to 'http://mygemserver.com'"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "bin"
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency 'thor'
31
+ spec.add_dependency 'eye'
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.10"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ end
@@ -0,0 +1,84 @@
1
+ require 'thor'
2
+ module Cs
3
+ module Service
4
+
5
+ HOME_PATH = File.realpath(File.join(File.dirname(__FILE__), '..', '..', '..'))
6
+
7
+ class Eye < ::Eye::Cli
8
+ end
9
+
10
+ class Cli < Thor
11
+
12
+ # CONFIG_FILE =
13
+
14
+ desc 'load [FILE]', '加载配置文件,为空时加载默认配置'
15
+ def load_conf(file = nil)
16
+ run_eye("load #{file || File.join(HOME_PATH, 'config/caishuo.eye')}")
17
+ end
18
+
19
+ desc 'check [ENV_NAME]', '环境变量检查'
20
+ long_desc <<-LONGDESC
21
+ `cs-service check` 将打印出环境变量. \n
22
+ > $ cs-service check \n
23
+ > $ cs-service check REST_SERVER_ROOT \n
24
+ > $ cs-service check TRADING_SERVER_ROOT \n
25
+ LONGDESC
26
+ ENVS = %w{ REST_SERVER_ROOT TRADING_SERVER_ROOT RAILS_ROOT RACK_ENV RAILS_ENV }
27
+ def check(env_name = nil)
28
+ if env_name.nil?
29
+ ENVS.each do |e|
30
+ puts "#{e}=#{ENV[e]}"
31
+ end
32
+ elsif ENV[env_name]
33
+ puts "#{env_name}=#{ENV[env_name]}"
34
+ else
35
+ puts "#{env_name} is blank"
36
+ end
37
+ end
38
+
39
+ desc 'info [NAME]', 'eye info'
40
+ def info(name = nil)
41
+ run_eye("info #{name}")
42
+ end
43
+
44
+ desc 'quit', 'exit cs-service'
45
+ def quit
46
+ run_eye("quit")
47
+ end
48
+
49
+ desc "help [COMMAND]", "Describe available commands or one specific command"
50
+ def help(command = nil, subcommand = false)
51
+ puts Motd.msg
52
+ super(command, subcommand)
53
+ end
54
+
55
+ # %w{start stop restart info trace monitor unmonitor delete}.each do |command|
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'
63
+ subcommand 'eye', Eye
64
+
65
+ # desc 'eye [ARGS]', 'run eye'
66
+ # def eye(args = nil)
67
+ # run_eye(args)
68
+ # end
69
+
70
+
71
+
72
+ private
73
+
74
+ def run_eye(args = '')
75
+ puts `eye #{args}`
76
+ end
77
+
78
+ end
79
+
80
+
81
+
82
+
83
+ end
84
+ end
@@ -0,0 +1,37 @@
1
+ module Cs
2
+ module Service
3
+ # "message of the day"
4
+ class Motd
5
+ MSG =
6
+ %q{
7
+ _/\_ _ooOoo_ _/`.
8
+ / \ o8888888o / `.
9
+ | 财 | 88" . "88 / 说 .
10
+ \ _\ (| -_- |) /_ .
11
+ \__/ \\\\ O\ = /O // `. .
12
+ \\\\ ____/`---'\____// `
13
+ \\\\ \\\\|| |// //.
14
+ / \\\\ ||| : |||// \
15
+ / _||||| -:- |||||- \
16
+ | | \\\\\ - /// | |
17
+ | \_| ''\---/'' | |
18
+ \ .-\__ `-` ___/-. /
19
+ ___`. .' /--.--\ `. . __
20
+ ."" '< `.___\_<|>_/___.' >'"".
21
+ | | : `- \`.;`\ _ /`;.`/ - ` : | |
22
+ \ \ `-. \_ __\ /__ _/ .-` / /
23
+ ======`-.____`-.___\_____/___.-`____.-'======
24
+ `=---='
25
+
26
+
27
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28
+ 佛祖保佑 永不死机
29
+ 我佛慈悲 干掉bug!}
30
+
31
+ def self.msg
32
+ MSG
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module Cs
2
+ module Service
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
data/lib/cs/service.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "cs/service/version"
2
+ require "cs/service/motd"
3
+ require "cs/service/cli"
4
+
5
+ module Cs
6
+ module Service
7
+ # Your code goes here...
8
+
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cs-service
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - wangchangming
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: eye
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: caishuo service
70
+ email:
71
+ - wangchangming@caishuo.com
72
+ executables:
73
+ - cs-service
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/cs-service
84
+ - config/caishuo.eye
85
+ - config/processes/global.rb
86
+ - config/processes/puma.rb
87
+ - config/processes/realtime.rb
88
+ - config/processes/scheduler.rb
89
+ - config/processes/sneaker.rb
90
+ - config/processes/worker.rb
91
+ - cs-service.gemspec
92
+ - lib/cs/service.rb
93
+ - lib/cs/service/cli.rb
94
+ - lib/cs/service/motd.rb
95
+ - lib/cs/service/version.rb
96
+ homepage: http://www.caishuo.com
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.5
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: caishuo service
120
+ test_files: []