capistrano-runit-core 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bddfd41eae20655a062eba33faa322c6e4716913
4
+ data.tar.gz: 3afac19b6ea4d5aac56a64e51dde1370559892a8
5
+ SHA512:
6
+ metadata.gz: a09f9a93a40ce648530165c317ac55028e4c03f62d582f66abf89c8658aab17ee4f09e855f76cbc5fd612607239dc0c68e287604caa3746da8a3dddd3c1c60c4
7
+ data.tar.gz: 0b474796f623a0d42fae467b71781da1ed596a3f071295e9377240a0cf0886fd460ff72ee9da116951e50ad49a47356806d12e033265f7656146fff504e693b8
@@ -0,0 +1,3 @@
1
+ /Gemfile.lock
2
+ /.ruby-version
3
+ /.idea
@@ -0,0 +1,41 @@
1
+ # capistrano-runit-core
2
+
3
+ ## 0.1.0
4
+
5
+ * Extract all supported services to separate gems
6
+ * Rename gem from capistrano-runit to capistrano-runit-core
7
+
8
+ # capistrano-runit
9
+ ## 2.0.0.rc1 (unreleased)
10
+
11
+ * Add sidekiq module.
12
+ * Add puma module.
13
+ * Drop Capistrano 2.x support.
14
+
15
+ ## 1.1.4 2014-02-06
16
+
17
+ * Added 'runit_unicorn_before_fork_code' variable for unicorn recipe.
18
+
19
+ ## 1.1.3 2013-04-19
20
+
21
+ * Added recipes for sidekiq.
22
+ * Fixed: runit:setup should run on servers with db-role too.
23
+ * Added recipes for thinking-sphinx.
24
+ * Use rails_env variable instead of hardwired 'production' in run-unicorn.
25
+
26
+ ## 1.1.2 2011-11-05
27
+
28
+ * Added double quotes for environment variables values.
29
+
30
+ ## 1.1.1 2011-11-05
31
+
32
+ * default_environment hash was added in templates (special usefull for rbenv).
33
+
34
+ ## 1.1.0 2011-10-23
35
+
36
+ * Bugfixes.
37
+ * Added Resque recipe.
38
+
39
+ ## 1.0
40
+
41
+ * Initial release.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2011-2014 Anton Ageev
4
+ Copyright (c) 2014 Oleksandr Simonov
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,80 @@
1
+ # capistrano-runit-core
2
+
3
+ Base core capistrano3 module for managing various services via runit supervisor.
4
+
5
+ ## Installation
6
+
7
+ Add to `Gemfile`:
8
+ ```
9
+ group :development do
10
+ gem "capistrano-runit-core", "~> 0.1.0"
11
+ end
12
+ ```
13
+
14
+ Run:
15
+ ```
16
+ $ bundle install
17
+ ```
18
+
19
+ ## runit setup
20
+
21
+ We need to create specific runit service for our whole application:
22
+ Create service folder inside `/etc/sv`:
23
+
24
+ ```bash
25
+ mkdir /etc/sv/runsvdir-your_application
26
+ mkdir /etc/sv/runsvdir-your_application/log
27
+ ```
28
+
29
+ Create run shell script `/etc/sv/runsvdir-your_application/run`:
30
+
31
+ ```bash
32
+ #!/bin/sh
33
+ exec 2>&1
34
+ exec chpst -udeployer runsvdir /home/deployer/apps/your_application/runit/enabled
35
+ ```
36
+
37
+ In current example expected what you deploying with `deployer` user to the `/home/deployer/apps/your_application` folder.
38
+
39
+ Create log run shell script `/etc/sv/runsvdir-your_application/log/run`:
40
+
41
+ ```bash
42
+ #!/bin/sh
43
+ exec svlogd -tt /var/log/runsvdir-your_application
44
+ ```
45
+
46
+ Create log folder:
47
+
48
+ ```bash
49
+ mkdir /var/log/runsvdir-your_application
50
+ ```
51
+
52
+ And make this scripts executable:
53
+
54
+ ```bash
55
+ chmod a+x /etc/sv/runsvdir-your_application/run /etc/sv/runsvdir-your_application/log/run
56
+ ```
57
+
58
+ And after this we will need to make symlink in `/etc/service/`
59
+
60
+ ```bash
61
+ ln -s /etc/sv/runsvdir-your_application /etc/service/runsvdir-your_application
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ Add this line in `Capfile`:
67
+ ```
68
+ require "capistrano/runit"
69
+ ```
70
+
71
+ ## Tasks
72
+
73
+ * `runit:setup` -- prepare runit directories in the project directory.
74
+
75
+ ## Variables
76
+
77
+ * `runit_roles` -- what host roles uses runit to run processes. Default value: `[:app, :db]`.
78
+ * `runit_sv_path` -- Path to the runit sv binary. Default value: `/sbin/sv`
79
+
80
+
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'capistrano-runit-core'
3
+ spec.version = '0.1.0'
4
+ spec.summary = 'Capistrano3 core recipe to manage runit services'
5
+ spec.homepage = 'http://capistrano-runit.github.io'
6
+ spec.author = ['Oleksandr Simonov', 'Anton Ageev']
7
+ spec.email = ['alex@simonov.me', 'antage@gmail.com']
8
+ spec.license = 'MIT'
9
+
10
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
11
+ spec.require_paths = ['lib']
12
+
13
+ spec.add_runtime_dependency 'capistrano', '>= 3.1'
14
+ spec.add_runtime_dependency 'sshkit', '>= 1.3'
15
+ spec.add_development_dependency 'bundler', '~> 1.6'
16
+ spec.add_development_dependency 'rake'
17
+ end
File without changes
@@ -0,0 +1,128 @@
1
+ module Capistrano
2
+ module Runit
3
+ def service_dir_for(service)
4
+ ::File.join(deploy_to, 'runit', 'available', service)
5
+ end
6
+
7
+ def enabled_service_dir_for(service)
8
+ ::File.join(deploy_to, 'runit', 'enabled', service)
9
+ end
10
+
11
+ def env_variables
12
+ ::SSHKit.config.default_env.map { |k, v| "#{k.upcase}=\"#{v}\"" }.join(' ')
13
+ end
14
+
15
+ def upload_runit_run_file(_runit_command, template_path, dest)
16
+ template = ERB.new(File.read(template_path))
17
+ stream = StringIO.new(template.result(binding))
18
+ upload! stream, dest
19
+ execute :chmod, '0755', dest
20
+ end
21
+
22
+ def pid_full_path(pid_path)
23
+ if pid_path.start_with?('/')
24
+ pid_path
25
+ else
26
+ "#{shared_path}/#{pid_path}"
27
+ end
28
+ end
29
+
30
+ def check_service(service)
31
+ if fetch("runit_#{service}_default_hooks")
32
+ ::Rake::Task['runit:setup'].invoke
33
+ ::Rake::Task["runit:#{service}:setup"].invoke
34
+ ::Rake::Task["runit:#{service}:enable"].invoke
35
+ end
36
+ end
37
+
38
+ def setup_service(service, run_command)
39
+ service_dir = service_dir_for(service)
40
+ template_key = "runit_#{service}_run_template".to_sym
41
+ on roles fetch("runit_#{service}_role".to_sym) do
42
+ if test "[ ! -d #{service_dir} ]"
43
+ execute :mkdir, '-v', service_dir
44
+ end
45
+ template_path = fetch(template_key, ::File.expand_path('../templates/run.erb', __FILE__))
46
+ if !template_path.nil? && File.exist?(template_path)
47
+ upload_runit_run_file(
48
+ run_command,
49
+ template_path,
50
+ ::File.join(service_dir, 'run')
51
+ )
52
+ else
53
+ error "Template from '#{template_key}' variable isn't found: #{template_path}"
54
+ end
55
+ end
56
+ end
57
+
58
+ def enable_service(service)
59
+ service_dir = service_dir_for(service)
60
+ enabled_service_dir = enabled_service_dir_for(service)
61
+ on roles fetch("runit_#{service}_role".to_sym) do
62
+ if test "[ -d #{service_dir} ]"
63
+ if test "[ -d #{enabled_service_dir} ]"
64
+ info "'#{service}' runit service already enabled"
65
+ else
66
+ within "#{enabled_service_dir}" do
67
+ execute :ln, '-sf', ::File.join(service, service), service
68
+ end
69
+ end
70
+ else
71
+ error "'#{service}' runit service isn't found. You should run runit:#{service}:setup first."
72
+ end
73
+ end
74
+ end
75
+
76
+ def disable_service(service)
77
+ ::Rake::Task["runit:#{service}:stop"].invoke
78
+ enabled_service_dir = enabled_service_dir_for(service)
79
+ on roles fetch("runit_#{service}_role".to_sym) do
80
+ if test "[ -d #{enabled_service_dir}"
81
+ execute :rm, '-f', enabled_service_dir
82
+ else
83
+ error "'#{service}' runit service isn't enabled."
84
+ end
85
+ end
86
+ end
87
+
88
+ def start_service(service)
89
+ on roles fetch("runit_#{service}_role".to_sym) do
90
+ runit_execute_command(service, 'start')
91
+ end
92
+ end
93
+
94
+ def stop_service(service)
95
+ pid_path = pid_full_path(fetch("runit_#{service}_pid".to_sym))
96
+ on roles fetch("runit_#{service}_role".to_sym) do
97
+ if test "[ -f #{pid_path} ]"
98
+ runit_execute_command(service, 'stop')
99
+ else
100
+ info "'#{service}' is not running yet"
101
+ end
102
+ end
103
+ end
104
+
105
+ def restart_service(service)
106
+ on roles fetch("runit_#{service}_role".to_sym) do
107
+ runit_execute_command(service, 'restart')
108
+ end
109
+ end
110
+
111
+ def kill_hup_service(service)
112
+ on roles fetch("runit_#{service}_role".to_sym) do
113
+ runit_execute_command(service, '1')
114
+ end
115
+ end
116
+
117
+ def runit_execute_command(service, command)
118
+ enabled_service_dir = enabled_service_dir_for(service)
119
+ if test "[ -d #{enabled_service_dir} ]"
120
+ execute "#{fetch(:runit_sv_path)} #{command} #{enabled_service_dir}"
121
+ else
122
+ error "'#{service}'' runit service isn't enabled."
123
+ end
124
+ end
125
+ end
126
+ end
127
+
128
+ load File.expand_path('../tasks/runit.rake', __FILE__)
@@ -0,0 +1,30 @@
1
+ namespace :runit do
2
+ desc 'Setup runit directories'
3
+ task :setup do
4
+ on roles fetch(:runit_roles) do
5
+ within fetch(:deploy_to) do
6
+ if test "[ ! -d #{deploy_to}/runit ]"
7
+ execute :mkdir, '-v', "#{deploy_to}/runit"
8
+ else
9
+ info "Directory 'runit' already exists"
10
+ end
11
+ %w(.env available enabled).each do |subdir|
12
+ if test "[ ! -d #{deploy_to}/runit/#{subdir} ]"
13
+ execute :mkdir, '-v', "#{deploy_to}/runit/#{subdir}"
14
+ else
15
+ info "Directory 'runit/#{subdir}' already exists"
16
+ end
17
+ end
18
+
19
+ execute "echo $HOME > #{deploy_to}/runit/.env/HOME"
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ namespace :load do
26
+ task :defaults do
27
+ set :runit_roles, fetch(:runit_roles, [:app, :db])
28
+ set :runit_sv_path, '/sbin/sv'
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+ cd <%= current_path %>
3
+ <%= runit_command %>
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-runit-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Oleksandr Simonov
8
+ - Anton Ageev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '3.1'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '3.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: sshkit
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '1.3'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '1.3'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.6'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.6'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description:
71
+ email:
72
+ - alex@simonov.me
73
+ - antage@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - CHANGELOG.md
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - capistrano-runit-core.gemspec
85
+ - lib/capistrano-runit-core.rb
86
+ - lib/capistrano/runit.rb
87
+ - lib/capistrano/tasks/runit.rake
88
+ - lib/capistrano/templates/run.erb
89
+ homepage: http://capistrano-runit.github.io
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Capistrano3 core recipe to manage runit services
113
+ test_files: []