capistrano-runit-core 0.1.0 → 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/CHANGELOG.md +4 -0
- data/README.md +2 -2
- data/capistrano-runit-core.gemspec +1 -1
- data/lib/capistrano/runit.rb +41 -18
- data/lib/capistrano/tasks/runit.rake +15 -1
- data/lib/capistrano/templates/run.erb +7 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59d5057025d875e01e940730d8b00748198c7230
|
4
|
+
data.tar.gz: 7f42484232482ce6842c8ae9ab18bd9b7323d708
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff4f4a10d8298cd66a84da2c7fd4f521405a30a62ced186c9ec87ad7ada52a4417ba2b838a6029fcfb868696a77f1c0d737dc61b54ad4baf4777a5d0c7816d60
|
7
|
+
data.tar.gz: 5d36ea9a82e6947597c1ef8daef7f95c6ea49104a4686484f1bba514ae8daa46125fc91b61d5db974351c6412b68a2f846296eb23b17807e5789e2689dedf2b9
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -31,7 +31,7 @@ Create run shell script `/etc/sv/runsvdir-your_application/run`:
|
|
31
31
|
```bash
|
32
32
|
#!/bin/sh
|
33
33
|
exec 2>&1
|
34
|
-
exec chpst -udeployer runsvdir /home/deployer/apps/your_application/runit/enabled
|
34
|
+
exec chpst -udeployer:deployer -e /home/deployer/apps/your_application/runit/.env runsvdir /home/deployer/apps/your_application/runit/enabled
|
35
35
|
```
|
36
36
|
|
37
37
|
In current example expected what you deploying with `deployer` user to the `/home/deployer/apps/your_application` folder.
|
@@ -75,6 +75,6 @@ require "capistrano/runit"
|
|
75
75
|
## Variables
|
76
76
|
|
77
77
|
* `runit_roles` -- what host roles uses runit to run processes. Default value: `[:app, :db]`.
|
78
|
-
* `
|
78
|
+
* `runit_sv_search_path` -- Path of $PATH where we will try to found sv binary. Default value: `/sbin:/usr/sbin`
|
79
79
|
|
80
80
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'capistrano-runit-core'
|
3
|
-
spec.version = '0.
|
3
|
+
spec.version = '0.2.0'
|
4
4
|
spec.summary = 'Capistrano3 core recipe to manage runit services'
|
5
5
|
spec.homepage = 'http://capistrano-runit.github.io'
|
6
6
|
spec.author = ['Oleksandr Simonov', 'Anton Ageev']
|
data/lib/capistrano/runit.rb
CHANGED
@@ -27,9 +27,21 @@ module Capistrano
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
|
30
|
+
def service_running?(service)
|
31
|
+
service_dir = enabled_service_dir_for(service)
|
32
|
+
supervise_dir = ::File.join(service_dir, 'supervise')
|
33
|
+
stat_file = ::File.join(supervise_dir, 'stat')
|
34
|
+
if test("[ -d #{supervise_dir} ]") && test("[ -f #{stat_file} ]")
|
35
|
+
capture(:cat, stat_file).chomp == 'run'
|
36
|
+
else
|
37
|
+
false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def check_service(service, namespace = nil)
|
42
|
+
if fetch("runit_#{service}_default_hooks".to_sym)
|
32
43
|
::Rake::Task['runit:setup'].invoke
|
44
|
+
service = "#{service}:#{namespace}" if namespace
|
33
45
|
::Rake::Task["runit:#{service}:setup"].invoke
|
34
46
|
::Rake::Task["runit:#{service}:enable"].invoke
|
35
47
|
end
|
@@ -63,9 +75,7 @@ module Capistrano
|
|
63
75
|
if test "[ -d #{enabled_service_dir} ]"
|
64
76
|
info "'#{service}' runit service already enabled"
|
65
77
|
else
|
66
|
-
|
67
|
-
execute :ln, '-sf', ::File.join(service, service), service
|
68
|
-
end
|
78
|
+
execute :ln, '-snf', service_dir, enabled_service_dir
|
69
79
|
end
|
70
80
|
else
|
71
81
|
error "'#{service}' runit service isn't found. You should run runit:#{service}:setup first."
|
@@ -85,41 +95,54 @@ module Capistrano
|
|
85
95
|
end
|
86
96
|
end
|
87
97
|
|
88
|
-
def start_service(service)
|
98
|
+
def start_service(service, timeout = nil)
|
89
99
|
on roles fetch("runit_#{service}_role".to_sym) do
|
90
|
-
runit_execute_command(service, 'start')
|
100
|
+
runit_execute_command(service, 'start', timeout)
|
91
101
|
end
|
92
102
|
end
|
93
103
|
|
94
|
-
def stop_service(service)
|
95
|
-
pid_path = pid_full_path(fetch("runit_#{service}_pid".to_sym))
|
104
|
+
def stop_service(service, pidfile = true, timeout = nil)
|
105
|
+
pid_path = pid_full_path(fetch("runit_#{service}_pid".to_sym)) if pidfile
|
96
106
|
on roles fetch("runit_#{service}_role".to_sym) do
|
97
|
-
if
|
98
|
-
|
107
|
+
if pidfile
|
108
|
+
if test "[ -f #{pid_path} ]" && service_running?(service)
|
109
|
+
runit_execute_command(service, 'stop', timeout)
|
110
|
+
else
|
111
|
+
info "'#{service}' is not running yet"
|
112
|
+
end
|
99
113
|
else
|
100
|
-
|
114
|
+
if service_running?(service)
|
115
|
+
runit_execute_command(service, 'stop', timeout)
|
116
|
+
else
|
117
|
+
info "'#{service}' is not running yet"
|
118
|
+
end
|
101
119
|
end
|
102
120
|
end
|
103
121
|
end
|
104
122
|
|
105
|
-
def restart_service(service)
|
123
|
+
def restart_service(service, timeout = nil)
|
106
124
|
on roles fetch("runit_#{service}_role".to_sym) do
|
107
|
-
runit_execute_command(service, 'restart')
|
125
|
+
runit_execute_command(service, 'restart', timeout)
|
108
126
|
end
|
109
127
|
end
|
110
128
|
|
111
129
|
def kill_hup_service(service)
|
112
130
|
on roles fetch("runit_#{service}_role".to_sym) do
|
113
|
-
runit_execute_command(service, '
|
131
|
+
runit_execute_command(service, 'hup')
|
114
132
|
end
|
115
133
|
end
|
116
134
|
|
117
|
-
def runit_execute_command(service, command)
|
135
|
+
def runit_execute_command(service, command, timeout = nil)
|
136
|
+
# check timeout type
|
137
|
+
unless timeout.instance_of?(NilClass) || (timeout.is_a?(Integer) && timeout >= 0)
|
138
|
+
raise ArgumentError.new("'timeout' argument in '#runit_execute_command' method must be nil or positive integer.")
|
139
|
+
end
|
140
|
+
|
118
141
|
enabled_service_dir = enabled_service_dir_for(service)
|
119
142
|
if test "[ -d #{enabled_service_dir} ]"
|
120
|
-
execute "#{fetch(:runit_sv_path)} #{command} #{enabled_service_dir}"
|
143
|
+
execute "#{host.fetch(:runit_sv_path)} #{"-w #{timeout}" unless timeout.nil?} #{command} #{enabled_service_dir}"
|
121
144
|
else
|
122
|
-
error "'#{service}'
|
145
|
+
error "'#{service}' runit service isn't enabled."
|
123
146
|
end
|
124
147
|
end
|
125
148
|
end
|
@@ -20,11 +20,25 @@ namespace :runit do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
task :hook do
|
25
|
+
roles(fetch(:runit_roles, [:app, :db])).each do |server|
|
26
|
+
on server do
|
27
|
+
with path: "#{fetch(:runit_sv_search_path)}:$PATH" do
|
28
|
+
server.set :runit_sv_path, capture(:which, :sv)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Capistrano::DSL.stages.each do |stage|
|
36
|
+
after stage, 'runit:hook'
|
23
37
|
end
|
24
38
|
|
25
39
|
namespace :load do
|
26
40
|
task :defaults do
|
27
41
|
set :runit_roles, fetch(:runit_roles, [:app, :db])
|
28
|
-
set :
|
42
|
+
set :runit_sv_search_path, '/sbin:/usr/sbin'
|
29
43
|
end
|
30
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-runit-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleksandr Simonov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-06-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.4.6
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: Capistrano3 core recipe to manage runit services
|