capistrano-chef-eye 0.2.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5149447b4a9dfea5632ec31d24dddb19c63701be
4
+ data.tar.gz: 2ce17233b61011a6cc7c13634a2037bfb934d19d
5
+ SHA512:
6
+ metadata.gz: 29dc828a922f16316f2be6a75c1feddb6418944bff2c78073d346d34df54b873dfdbdc3a735347ad92bc2db010143598068981aa3f74b95b46a9091efefa94fd
7
+ data.tar.gz: 3e1a34e261668947750e076cf131cc6d4767ee41d67e1f63c217803f28dac58c07c71458457db017d87228a0028230e3016636bd8292579ceedc48bb468b4299
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ /.idea/
16
+ /.vagrant/
17
+ *.iml
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-chef-eye.gemspec
4
+ gemspec
5
+
6
+ gem 'capistrano', '~> 3.0'
7
+ gem 'capistrano-rvm'
8
+ gem 'capistrano-rails'
9
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Nikolay Murga
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # Capistrano::Chef::Eye
2
+
3
+ [Chef Eye] (https://github.com/MurgaNikolay/chef_eye) cookbook companion for [Capistrano] (https://github.com/capistrano/capistrano).
4
+
5
+ [![GitHub version](https://badge.fury.io/gh/MurgaNikolay%2Fcapistrano-chef-eye.svg)](http://badge.fury.io/gh/MurgaNikolay%2Fcapistrano-chef-eye)
6
+ [![Code Climate](https://codeclimate.com/github/MurgaNikolay/capistrano-chef-eye/badges/gpa.svg)](https://codeclimate.com/github/MurgaNikolay/capistrano-chef-eye)
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'capistrano-chef-eye'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```bash
20
+ $ bundle
21
+ ```
22
+ Or install it yourself as:
23
+
24
+ ```bash
25
+ $ gem install capistrano-chef-eye
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ Capfile
31
+
32
+ ```ruby
33
+ require 'capistrano/chef_eye'
34
+ ```
35
+ In command line:
36
+
37
+ cap production eye:help
38
+ cap production eye:processes # List of commands per processes
39
+
40
+ ### Properties
41
+
42
+ ```ruby
43
+ set :eye_strategy, 'local' # chef_eye strategy. 'local' or 'user'
44
+ set :eye_application, -> { fetch(:application) } # eye application name. Used for generate path to eye file, and service name
45
+ set :eye_roles, :all
46
+ set :eye_servers, -> { release_roles(fetch(:eye_roles)) } # Servers with eye. Fetched by eye_roles
47
+ set :eye_processes, nil # List of eye processes. Library try to detect processes automatically, if nil
48
+ set :eye_user, -> { 'auto' } # Owner of eye process
49
+ set :eye_file, -> { # Path to eye application config
50
+ if fetch(:eye_strategy).to_s == 'local'
51
+ 'Eyefile'
52
+ else
53
+ "/etc/eye/{eye_user}/#{fetch(:eye_application)}.eye"
54
+ end
55
+ }
56
+ set :eye_home, -> { # Path to eye home.
57
+ if fetch(:eye_strategy).to_s == 'local'
58
+ "#{shared_path}"
59
+ else
60
+ "#{fetch(:deploy_to)}"
61
+ end
62
+ }
63
+
64
+ set :eye_bin, -> { # Path to eye bin
65
+ if fetch(:eye_strategy).to_s == 'local'
66
+ '/usr/local/bin/leye'
67
+ else
68
+ '/usr/local/bin/eye'
69
+ end
70
+ }
71
+ ```
72
+ The major property is:
73
+
74
+ * `eye_processes` this is the array of availables eye appplications processes. You need to set up it manualy.
75
+
76
+ ### Available tasks
77
+
78
+ cap eye:check # Check configuration
79
+ cap eye:help # Show help
80
+ cap eye:history # Show monitoring history
81
+ cap eye:info # Current process status
82
+ cap eye:processes # Show available process list and commands
83
+ cap eye:reload # Reload configuration
84
+ cap eye:restart # Restart all processes
85
+ cap eye:force_restart # Force restart all processes (stop and start)
86
+ cap eye:start # Start all processes
87
+ cap eye:stop # Stop all processes
88
+ cap eye:trace # Trace log for application
89
+
90
+ ## Example
91
+
92
+ See [example/README.md](example/README.md)
93
+
94
+
95
+ # TODO
96
+
97
+ - Set processes per roles
98
+ - Something else :)
99
+
100
+ ## Contributing
101
+
102
+ 1. Fork it ( https://github.com/[my-github-username]/capistrano-chef-eye/fork )
103
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
104
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
105
+ 4. Push to the branch (`git push origin my-new-feature`)
106
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/chef_eye/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'capistrano-chef-eye'
8
+ spec.version = Capistrano::ChefEye::VERSION
9
+ spec.authors = ['Nikolay Murga']
10
+ spec.email = ['nikolay.m@murga.kiev.ua']
11
+ spec.summary = %q{Chef Eye plugin companion for Capistrano.}
12
+ spec.description = %q{Chef Eye plugin companion for Capistrano.}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ end
data/example/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Usage example for chef_eye cookbook and capistrano chef_eye plugin
2
+
3
+ ## Provision on virtualbox
4
+
5
+ ### Preapre
6
+
7
+ - Install Vagrant
8
+ - Install Virtualbox
9
+
10
+ ### Run and provision vagrant box with virtualbox provider
11
+
12
+ cd application
13
+ vagrant up
14
+ cap staging eye:processes
15
+ cap staging eye:info
16
+
17
+
18
+
19
+ ## Provision on AWS
20
+
21
+ ### Setup vagrant
22
+
23
+ vagrant plugin install vagrant-aws
24
+ vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
25
+
26
+ ### Set AWS config
27
+
28
+ export AWS_ACCESS_KEY=AERTHMLP3VVFJ4MHFRG
29
+ export AWS_SECRET_KEY= 34DFSC423FDS./+DDSC3WEFSDCDSVR#$R3442e32432
30
+ export AWS_SESSION_TOKEN=
31
+ export AWS_SSH_KEY_ID=test
32
+ export AWS_DEFAULT_AMI=ami-7747d01e
33
+ export AWS_DEFAULT_REGION=us-east-1
34
+ export AWS_USERNAME=ubuntu
35
+ export AWS_PRIVATE_KEY=~/.ssh/test.pem
36
+
37
+ ### Up and provision instances
38
+
39
+ cd application
40
+ vagrant up --provider=aws
41
+ cap staging eye:processes
42
+ cap staging eye:info
43
+
44
+
45
+ ### Example for `local` eye strategy (leye per project)
46
+
47
+ Set `export EYE_LOCAL=true` before `vagrant up`. If you have provisioned boxes, destroy it before.
48
+
49
+
@@ -0,0 +1 @@
1
+ /.vagrant/
@@ -0,0 +1 @@
1
+ capistrano-chef-eye
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -0,0 +1,9 @@
1
+ source "https://supermarket.getchef.com"
2
+
3
+
4
+ cookbook 'chef_eye', path: '/Users/nikolay/Projects/chef-cookbooks/chef-eye'
5
+ #cookbook 'chef_eye', git: 'https://github.com/MurgaNikolay/chef_eye.git'
6
+ cookbook 'chef_eye_capistrano_example', path: '../cookbook'
7
+ cookbook 'build-essential'
8
+ cookbook 'apt'
9
+
@@ -0,0 +1,29 @@
1
+ DEPENDENCIES
2
+ apt
3
+ build-essential
4
+ chef_eye
5
+ path: ../../../chef-eye
6
+ chef_eye_capistrano_example
7
+ path: ../cookbook
8
+
9
+ GRAPH
10
+ apt (2.7.0)
11
+ bsw_gpg (0.2.3)
12
+ build-essential (2.2.3)
13
+ chef_eye (1.0.2)
14
+ apt (>= 0.0.0)
15
+ build-essential (>= 0.0.0)
16
+ chef_eye_capistrano_example (0.0.4)
17
+ apt (>= 0.0.0)
18
+ build-essential (>= 0.0.0)
19
+ chef_eye (>= 0.0.0)
20
+ ruby_rvm (>= 0.0.0)
21
+ chef_gem (0.1.0)
22
+ java (1.31.0)
23
+ ruby_rvm (0.4.9)
24
+ apt (>= 0.0.0)
25
+ bsw_gpg (>= 0.0.0)
26
+ chef_gem (>= 0.0.0)
27
+ java (>= 0.0.0)
28
+ sudo (>= 0.0.0)
29
+ sudo (2.7.1)
@@ -0,0 +1,26 @@
1
+ # Load DSL and Setup Up Stages
2
+ require 'capistrano/setup'
3
+
4
+ # Includes default deployment tasks
5
+ require 'capistrano/deploy'
6
+
7
+ # Includes 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
+ #
17
+ require 'capistrano/rvm'
18
+ # require 'capistrano/rbenv'
19
+ # require 'capistrano/chruby'
20
+ require 'capistrano/rails'
21
+ require 'capistrano/chef_eye'
22
+ # require 'capistrano/rails/assets'
23
+ # require 'capistrano/rails/migrations'
24
+
25
+ # Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
26
+ # Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ gemspec path: '../..'
3
+ gem 'capistrano', '~> 3.0'
4
+ gem 'capistrano-rvm'
5
+ gem 'capistrano-rails'
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ capistrano-chef-eye (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ capistrano (3.4.0)
10
+ i18n
11
+ rake (>= 10.0.0)
12
+ sshkit (~> 1.3)
13
+ capistrano-bundler (1.1.4)
14
+ capistrano (~> 3.1)
15
+ sshkit (~> 1.2)
16
+ capistrano-rails (1.1.3)
17
+ capistrano (~> 3.1)
18
+ capistrano-bundler (~> 1.1)
19
+ capistrano-rvm (0.1.2)
20
+ capistrano (~> 3.0)
21
+ sshkit (~> 1.2)
22
+ colorize (0.7.7)
23
+ i18n (0.7.0)
24
+ net-scp (1.2.1)
25
+ net-ssh (>= 2.6.5)
26
+ net-ssh (2.9.2)
27
+ rake (10.4.2)
28
+ sshkit (1.7.1)
29
+ colorize (>= 0.7.0)
30
+ net-scp (>= 1.1.2)
31
+ net-ssh (>= 2.8.0)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.7)
38
+ capistrano (~> 3.0)
39
+ capistrano-chef-eye!
40
+ capistrano-rails
41
+ capistrano-rvm
42
+ rake (~> 10.0)
@@ -0,0 +1,207 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+ Vagrant.configure('2') do |config|
4
+ # All Vagrant configuration is done here. The most common configuration
5
+ # options are documented and commented below. For a complete reference,
6
+ # please see the online documentation at vagrantup.com.
7
+ config.trigger.before :reload, stdout: true do
8
+ puts "Remove 'synced_folders' file"
9
+ `rm .vagrant/machines/web1/virtualbox/synced_folders`
10
+ `rm .vagrant/machines/web2/virtualbox/synced_folders`
11
+ `rm .vagrant/machines/web3/aws/synced_folders`
12
+ `rm .vagrant/machines/web4/aws/synced_folders`
13
+ end
14
+
15
+ config.vm.define "web1" do |web|
16
+ web.vm.hostname = 'rails-sample1'
17
+ web.vm.network :private_network, ip: '33.33.33.35'
18
+ end
19
+
20
+ config.vm.define "web2" do |web|
21
+ web.vm.hostname = 'rails-sample2'
22
+ web.vm.network :private_network, ip: '33.33.33.36'
23
+ end
24
+
25
+ # Every Vagrant virtual environment requires a box to build off of.
26
+ config.vm.box = 'chef/ubuntu-14.04'
27
+ config.omnibus.chef_version = :latest
28
+ # The url from where the 'config.vm.box' box will be fetched if it
29
+ # doesn't already exist on the user's system.
30
+
31
+ # Assign this VM to a host-only network IP, allowing you to access it
32
+ # via the IP. Host-only networks can talk to the host machine as well as
33
+ # any other machines on the same network, but cannot be accessed (through this
34
+ # network interface) by any external networks.
35
+
36
+ # Create a public network, which generally matched to bridged network.
37
+ # Bridged networks make the machine appear as another physical device on
38
+ # your network.
39
+
40
+ # config.vm.network :public_network
41
+
42
+ # Create a forwarded port mapping which allows access to a specific port
43
+ # within the machine from a port on the host machine. In the example below,
44
+ # accessing "localhost:8080" will access port 80 on the guest machine.
45
+
46
+ # Share an additional folder to the guest VM. The first argument is
47
+ # the path on the host to the actual folder. The second argument is
48
+ # the path on the guest to mount the folder. And the optional third
49
+ # argument is a set of non-required options.
50
+ # config.vm.synced_folder "eye_test", "/eye_test", owner: "ubuntu", group: "ubuntu"
51
+
52
+ # Provider-specific configuration so you can fine-tune various
53
+ # backing providers for Vagrant. These expose provider-specific options.
54
+ # Example for VirtualBox:
55
+ #
56
+ # config.vm.provider :virtualbox do |vb|
57
+ # # Don't boot with headless mode
58
+ # vb.gui = true
59
+ #
60
+ # # Use VBoxManage to customize the VM. For example to change memory:
61
+ # vb.customize ["modifyvm", :id, "--memory", "1024"]
62
+ # end
63
+
64
+ #
65
+ # View the documentation for the provider you're using for more
66
+ # information on available options.
67
+
68
+ # The path to the Berksfile to use with Vagrant Berkshelf
69
+ config.berkshelf.berksfile_path = './Berksfile'
70
+
71
+ # Enabling the Berkshelf plugin. To enable this globally, add this configuration
72
+ # option to your ~/.vagrant.d/Vagrantfile file
73
+ config.berkshelf.enabled = true
74
+
75
+ # An array of symbols representing groups of cookbook described in the Vagrantfile
76
+ # to exclusively install and copy to Vagrant's shelf.
77
+ # config.berkshelf.only = []
78
+
79
+ # An array of symbols representing groups of cookbook described in the Vagrantfile
80
+ # to skip installing and copying to Vagrant's shelf.
81
+ # config.berkshelf.except = []
82
+ config.vm.provision :chef_zero do |chef|
83
+ chef.log_level = :debug
84
+ chef.json = {
85
+ chef_eye: {
86
+ services: {
87
+ 'vagrant' => {
88
+ plugins: ['eye-hipchat', 'eye-bugsnag'],
89
+ config: {
90
+ mail: { :host => "mx.some.host", :port => 25, :domain => 'some.host' },
91
+ http: { :enable => true, :host => "127.0.0.1", :port => 12345 },
92
+ bugsnag: {
93
+ api_key: '123yourbugsnagapikeygoeshere321',
94
+ release_stage: 'production',
95
+ notify_release_stages: %w(staging production)
96
+ },
97
+ hipchat: {
98
+ token: 'hipchat_v1_token',
99
+ message: '<strong>#name#</strong> (#pid#) on #host# #message# at #time#.'
100
+ },
101
+ contact: {
102
+ errors: { type: 'mail', contact: 'carcassw@gmail.com' },
103
+ dev: { type: 'hipchat', contact: 'carcassw2@gmail.com' },
104
+ devs: { type: 'bugsnag', contact: 'whatever' },
105
+ }
106
+ }
107
+ }
108
+ },
109
+ plugins: {
110
+ 'eye-hipchat' => {
111
+ require: 'eye/notify/hipchat',
112
+ },
113
+ 'eye-bugsnag' => {
114
+ require: 'eye/notify/bugsnag',
115
+ },
116
+ 'eye-http' => {
117
+ require: 'eye-http',
118
+ }
119
+ }
120
+ },
121
+ chef_eye_capistrano_example: {
122
+ local: ENV['EYE_LOCAL']
123
+ },
124
+ :'build-essential' => {
125
+ compile_time: true
126
+ },
127
+ apt: {
128
+ compile_time_update: true
129
+ }
130
+ }
131
+ chef.run_list = %w(
132
+ chef_eye_capistrano_example::default
133
+ )
134
+ end
135
+
136
+ config.vm.provider :virtualbox do |v|
137
+ v.memory = 1024
138
+ v.cpus = 2
139
+ end
140
+
141
+ config.vm.provider :aws do |aws, override|
142
+ aws.access_key_id = ENV['AWS_ACCESS_KEY']
143
+ aws.secret_access_key = ENV['AWS_SECRET_KEY']
144
+ # aws.session_token = ENV['AWS_SESSION_TOKEN']
145
+ aws.keypair_name = ENV['AWS_SSH_KEY_ID']
146
+ aws.ami = ENV['AWS_DEFAULT_AMI'] || "ami-7747d01e"
147
+ aws.region = ENV['AWS_DEFAULT_REGION'] || 'us-east-1'
148
+ override.ssh.username = ENV['AWS_USERNAME'] || 'ubuntu'
149
+ override.ssh.private_key_path = ENV['AWS_PRIVATE_KEY']
150
+ override.vm.box = "dummy"
151
+ override.vm.provision :chef_zero do |chef|
152
+ chef.log_level = :debug
153
+ chef.json = {
154
+ chef_eye: {
155
+ services: {
156
+ 'ubuntu' => {
157
+ plugins: ['eye-hipchat', 'eye-bugsnag'],
158
+ config: {
159
+ mail: { :host => "mx.some.host", :port => 25, :domain => 'some.host' },
160
+ http: { :enable => true, :host => "127.0.0.1", :port => 12345 },
161
+ bugsnag: {
162
+ api_key: '123yourbugsnagapikeygoeshere321',
163
+ release_stage: 'production',
164
+ notify_release_stages: %w(staging production)
165
+ },
166
+ hipchat: {
167
+ token: 'hipchat_v1_token',
168
+ message: '<strong>#name#</strong> (#pid#) on #host# #message# at #time#.'
169
+ },
170
+ contact: {
171
+ errors: { type: 'mail', contact: 'carcassw@gmail.com' },
172
+ dev: { type: 'hipchat', contact: 'carcassw2@gmail.com' },
173
+ devs: { type: 'bugsnag', contact: 'whatever' },
174
+ }
175
+ }
176
+ }
177
+ },
178
+ plugins: {
179
+ 'eye-hipchat' => {
180
+ require: 'eye/notify/hipchat',
181
+ },
182
+ 'eye-bugsnag' => {
183
+ require: 'eye/notify/bugsnag',
184
+ },
185
+ 'eye-http' => {
186
+ require: 'eye-http',
187
+ }
188
+ }
189
+ },
190
+ chef_eye_capistrano_example: {
191
+ local: ENV['EYE_LOCAL'],
192
+ user: 'ubuntu'
193
+ },
194
+ :'build-essential' => {
195
+ compile_time: true
196
+ },
197
+ apt: {
198
+ compile_time_update: true
199
+ }
200
+ }
201
+ chef.run_list = %w(
202
+ chef_eye_capistrano_example::default
203
+ )
204
+ end
205
+ end
206
+ end
207
+
@@ -0,0 +1,18 @@
1
+ require 'tempfile'
2
+ puts 'Get SSH config for vagrant'
3
+ file = Tempfile.new('vagrant')
4
+ file.write `vagrant ssh-config 2>/dev/null`
5
+ file.rewind
6
+
7
+ %w(web1 web2).each do |host|
8
+ config = Net::SSH::Config.load(file.path, host)
9
+ server(config['hostname'], port: config['port'], user: config['user'], roles: %w{web app}, ssh_options: {
10
+ keys: config['identityfile'],
11
+ forward_agent: false,
12
+ auth_methods: %w(publickey)
13
+ }) if config['hostname']
14
+ end
15
+
16
+ file.close
17
+ file.unlink
18
+
@@ -0,0 +1,52 @@
1
+ # config valid only for Capistrano 3.1
2
+ lock '3.4.0'
3
+
4
+ set :application, 'rails_sample'
5
+ set :repo_url, 'https://github.com/MurgaNikolay/rails-base.git'
6
+
7
+ # Default branch is :master
8
+ # ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
9
+ set :eye_strategy, ENV['EYE_LOCAL'] ? 'local' : 'user'
10
+ # Default deploy_to directory is /var/www/my_app
11
+ set :deploy_to, '/var/www/rails_sample'
12
+ set :rvm_ruby_version, '2.0.0@default' # Defaults to: 'default'
13
+ set :pty, false
14
+ # set :eye_processes, %w(unicorn)
15
+ # Default value for :scm is :git
16
+ # set :scm, :git
17
+
18
+ # Default value for :format is :pretty
19
+ set :format, :pretty
20
+
21
+ # Default value for :log_level is :debug
22
+ # set :log_level, :debug
23
+
24
+ # Default value for :linked_files is []
25
+ # set :linked_files, %w{config/database.yml}
26
+
27
+ # Default value for linked_dirs is []
28
+ set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
29
+
30
+ # Default value for default_env is {}
31
+ # set :default_env, { path: "/opt/ruby/bin:$PATH" }
32
+
33
+ # Default value for keep_releases is 5
34
+ # set :keep_releases, 3
35
+
36
+ namespace :deploy do
37
+ desc 'Restart unicorn'
38
+ task :restart do
39
+ invoke 'eye:unicorn:restart'
40
+ end
41
+
42
+ after :publishing, :restart
43
+
44
+ after :restart, :clear_cache do
45
+ on roles(:web), in: :groups, limit: 3, wait: 10 do
46
+ # Here we can do anything such as:
47
+ # within release_path do
48
+ # execute :rake, 'cache:clear'
49
+ # end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1 @@
1
+ *.log
@@ -0,0 +1,2 @@
1
+ default['chef_eye_capistrano_example']['local'] = false
2
+ default['chef_eye_capistrano_example']['user'] = 'vagrant'
@@ -0,0 +1,12 @@
1
+ name 'chef_eye_capistrano_example'
2
+ maintainer 'Nikolay Murga'
3
+ maintainer_email 'nikolay.m@randrmusic.com'
4
+ license 'MIT'
5
+ description 'Cookbook for test'
6
+ # long_description 'Cookbook for test'
7
+ version '0.0.4'
8
+
9
+ depends 'chef_eye'
10
+ depends 'ruby_rvm'
11
+ depends 'apt'
12
+ depends 'build-essential'
@@ -0,0 +1,78 @@
1
+
2
+ #cretae applications
3
+ include_recipe 'chef_eye::default'
4
+
5
+ user = node['chef_eye_capistrano_example']['user']
6
+ app_name = "rails_sample"
7
+ ruby_rvm user do
8
+ rubies '2.0.0'
9
+ end
10
+
11
+ %W(/var/www/#{app_name} /var/www/#{app_name}/shared /var/www/#{app_name}/config /var/www/#{app_name}/shared/log).each do |dir|
12
+ directory dir do
13
+ recursive true
14
+ owner user
15
+ group user
16
+ end
17
+ end
18
+
19
+ bash "#{app_name}_bundle" do
20
+ code <<EOF
21
+ /home/#{user}/.rvm/bin/rvm 2.0.0@default do gem install bundler
22
+ /home/#{user}/.rvm/bin/rvm 2.0.0@default do bundle install --jobs 2
23
+ EOF
24
+ user user
25
+ group user
26
+ env 'HOME' => "/home/#{user}"
27
+ cwd "/var/www/#{app_name}/current"
28
+ action :nothing
29
+ end
30
+
31
+ git "/var/www/#{app_name}/current" do
32
+ user user
33
+ group user
34
+ repository 'https://github.com/MurgaNikolay/rails-base.git'
35
+ revision 'master'
36
+ action :sync
37
+ notifies :run, "bash[#{app_name}_bundle]", :immediately
38
+ end
39
+
40
+ chef_eye_application app_name do
41
+ owner user
42
+ group user
43
+ config do
44
+ working_dir "/var/www/#{app_name}/current"
45
+ process 'unicorn' do
46
+ pid_file 'tmp/pids/unicorn.pid'
47
+ stdall 'log/eye.log'
48
+ start_command "/home/#{user}/.rvm/bin/rvm 2.0.0@default do bundle exec unicorn_rails -D -E development -c config/unicorn.rb"
49
+ stop_signals [:TERM, 10.seconds, :KILL]
50
+ start_timeout 10
51
+ restart_grace 10
52
+ restart_command 'kill -USR2 {PID}'
53
+ monitor_children do
54
+ stop_command 'kill -QUIT {PID}'
55
+ check :cpu, :every => 30, :below => 80, :times => 3
56
+ check :memory, :every => 30, :below => 150.megabytes, :times => [3, 5]
57
+ end
58
+ end
59
+ end
60
+ if node['chef_eye_capistrano_example']['local']
61
+ provider Chef::Provider::ChefEyeApplicationLocal
62
+ eye_home "/var/www/#{app_name}/shared"
63
+ eye_config do
64
+ mail({host: 'mx.some.host', port: 25, domain: 'some.host'})
65
+ http({enable: true, host: '127.0.0.1', port: 12345})
66
+ bugsnag({api_key: '123yourbugsnagapikeygoeshere321', release_stage: 'production', notify_release_stages: ['staging', 'production']})
67
+ hipchat({token: 'hipchat_v1_token', message: '<strong>#name#</strong> (#pid#) on #host# #message# at #time#.'})
68
+ contact(:errors, :mail, 'carcassw@gmail.com', {})
69
+ contact(:dev, :hipchat, 'carcassw2@gmail.com', {})
70
+ contact(:devs, :bugsnag, 'whatever', {})
71
+ end
72
+ else
73
+ notifies :restart, "chef_eye_service[eye_#{user}]", :immediately
74
+ end
75
+ action :configure
76
+ end
77
+
78
+
@@ -0,0 +1,8 @@
1
+
2
+ include_recipe 'apt'
3
+ package 'build-essential'
4
+ package 'nodejs-legacy'
5
+ package 'git'
6
+ package 'curl'
7
+
8
+ include_recipe 'chef_eye_capistrano_example::application'
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module ChefEye
3
+ VERSION = '0.2.1'
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/chef_eye.cap', __FILE__)
@@ -0,0 +1,130 @@
1
+ namespace :eye do
2
+ desc 'Show help'
3
+ commands = [:start, :restart, :stop, :history, :info, :trace]
4
+
5
+ task :hook do
6
+ processes = fetch(:eye_processes)
7
+ output = SSHKit.config.output
8
+ SSHKit.config.format = :dot
9
+ processes ||= begin
10
+ r = eye_execute('info')
11
+ r.map! do |info|
12
+ info.split("\n").map! do |i|
13
+ Array(i.match(/^\s\s(\S+)/))[1]
14
+ end
15
+ end.flatten!.compact!.uniq
16
+ end
17
+ SSHKit.config.output = output
18
+ set(:eye_processes, processes)
19
+ processes.each do |process|
20
+ commands.each do |command|
21
+ Rake::Task.define_task("eye:#{process}:#{command}") do
22
+ process = "#{fetch(:eye_application)}:#{process}" unless fetch(:eye_strategy) == 'local'
23
+ eye_execute(command, process)
24
+ end
25
+ end
26
+
27
+ Rake::Task.define_task("eye:#{process}:force_restart") do
28
+ eye_execute(:stop, process)
29
+ eye_execute(:start, process)
30
+ end
31
+ end
32
+ end
33
+
34
+ desc 'Show available process list and commands'
35
+ task :processes do
36
+ fetch(:eye_processes).each do |process|
37
+ puts "#{process}".bold.yellow
38
+ commands.each do |command|
39
+ puts "cap eye:#{process.to_s.yellow}:#{command}"
40
+ end
41
+ puts "cap eye:#{process.to_s.yellow}:force_restart"
42
+ end
43
+ end
44
+
45
+ commands.each do |command|
46
+ desc command.to_s
47
+ task command do
48
+ process = 'all'
49
+ process = "#{fetch(:eye_application)}:#{process}" unless fetch(:eye_strategy) == 'local'
50
+ eye_execute(command, process)
51
+ end
52
+ end
53
+
54
+ desc 'Force restart services'
55
+ task :force_restart do
56
+ Rake::Task['eye:stop'].invoke
57
+ Rake::Task['eye:start'].invoke
58
+ end
59
+
60
+ desc 'Check configuration'
61
+ task :check do
62
+ eye_execute(:check, fetch(:eye_file))
63
+ end
64
+
65
+ desc 'Reload configuration'
66
+ task :reload do
67
+ eye_execute(:load, fetch(:eye_file))
68
+ end
69
+
70
+ # after 'deploy:restart', 'eye:restart'
71
+ end
72
+
73
+ Capistrano::DSL.stages.each do |stage|
74
+ after stage, 'eye:hook'
75
+ end
76
+
77
+ namespace :load do
78
+ task :defaults do
79
+ set :eye_strategy, 'local'
80
+ set :eye_application, -> { fetch(:application) }
81
+ set :eye_roles, :all
82
+ set :eye_servers, -> { release_roles(fetch(:eye_roles)) }
83
+ set :eye_processes, nil
84
+ set :eye_user, -> { 'auto' }
85
+ set :eye_file, -> {
86
+ if fetch(:eye_strategy).to_s == 'local'
87
+ 'Eyefile'
88
+ else
89
+ "/etc/eye/{eye_user}/#{fetch(:eye_application)}.eye"
90
+ end
91
+ }
92
+ set :eye_home, -> {
93
+ if fetch(:eye_strategy).to_s == 'local'
94
+ "#{shared_path}"
95
+ else
96
+ "#{fetch(:deploy_to)}"
97
+ end
98
+ }
99
+
100
+ set :eye_bin, -> {
101
+ if fetch(:eye_strategy).to_s == 'local'
102
+ '/usr/local/bin/leye'
103
+ else
104
+ '/usr/local/bin/eye'
105
+ end
106
+ }
107
+ end
108
+ end
109
+
110
+ def eye_execute(command, mask='')
111
+ res = []
112
+ rvm_path = fetch(:rvm_path)
113
+ eye_bin = fetch(:eye_bin)
114
+ eye_bin = "#{rvm_path}/bin/rvm system do #{eye_bin}" if rvm_path
115
+ cmd = "#{eye_bin} #{command} #{mask}".strip
116
+
117
+ on fetch(:eye_servers) do
118
+ begin
119
+ within fetch(:eye_home) do
120
+ cmd.gsub!('{eye_user}', capture('whoami'))
121
+ result = capture(*cmd.split(' '))
122
+ res << result
123
+ # puts result unless fetch(:format) == :pretty
124
+ end
125
+ rescue Exception => e
126
+ # puts e.message
127
+ end
128
+ end
129
+ res
130
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-chef-eye
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Nikolay Murga
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Chef Eye plugin companion for Capistrano.
42
+ email:
43
+ - nikolay.m@murga.kiev.ua
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - capistrano-chef-eye.gemspec
54
+ - example/README.md
55
+ - example/application/.gitignore
56
+ - example/application/.ruby-gemset
57
+ - example/application/.ruby-version
58
+ - example/application/Berksfile
59
+ - example/application/Berksfile.lock
60
+ - example/application/Capfile
61
+ - example/application/Gemfile
62
+ - example/application/Gemfile.lock
63
+ - example/application/Vagrantfile
64
+ - example/application/config/deploy.rb
65
+ - example/application/config/deploy/staging.rb
66
+ - example/application/log/.gitignore
67
+ - example/cookbook/attributes/default.rb
68
+ - example/cookbook/metadata.rb
69
+ - example/cookbook/recipes/application.rb
70
+ - example/cookbook/recipes/default.rb
71
+ - lib/capistrano/chef_eye.rb
72
+ - lib/capistrano/chef_eye/version.rb
73
+ - lib/capistrano/tasks/chef_eye.cap
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.6
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Chef Eye plugin companion for Capistrano.
98
+ test_files: []