capistrano-runit-core 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bddfd41eae20655a062eba33faa322c6e4716913
4
- data.tar.gz: 3afac19b6ea4d5aac56a64e51dde1370559892a8
3
+ metadata.gz: 59d5057025d875e01e940730d8b00748198c7230
4
+ data.tar.gz: 7f42484232482ce6842c8ae9ab18bd9b7323d708
5
5
  SHA512:
6
- metadata.gz: a09f9a93a40ce648530165c317ac55028e4c03f62d582f66abf89c8658aab17ee4f09e855f76cbc5fd612607239dc0c68e287604caa3746da8a3dddd3c1c60c4
7
- data.tar.gz: 0b474796f623a0d42fae467b71781da1ed596a3f071295e9377240a0cf0886fd460ff72ee9da116951e50ad49a47356806d12e033265f7656146fff504e693b8
6
+ metadata.gz: ff4f4a10d8298cd66a84da2c7fd4f521405a30a62ced186c9ec87ad7ada52a4417ba2b838a6029fcfb868696a77f1c0d737dc61b54ad4baf4777a5d0c7816d60
7
+ data.tar.gz: 5d36ea9a82e6947597c1ef8daef7f95c6ea49104a4686484f1bba514ae8daa46125fc91b61d5db974351c6412b68a2f846296eb23b17807e5789e2689dedf2b9
@@ -1,5 +1,9 @@
1
1
  # capistrano-runit-core
2
2
 
3
+ ## 0.1.1 (unreleased)
4
+
5
+ * Path to runit's sv depend on system.
6
+
3
7
  ## 0.1.0
4
8
 
5
9
  * Extract all supported services to separate gems
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
- * `runit_sv_path` -- Path to the runit sv binary. Default value: `/sbin/sv`
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.1.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']
@@ -27,9 +27,21 @@ module Capistrano
27
27
  end
28
28
  end
29
29
 
30
- def check_service(service)
31
- if fetch("runit_#{service}_default_hooks")
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
- within "#{enabled_service_dir}" do
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 test "[ -f #{pid_path} ]"
98
- runit_execute_command(service, 'stop')
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
- info "'#{service}' is not running yet"
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, '1')
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}'' runit service isn't enabled."
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 :runit_sv_path, '/sbin/sv'
42
+ set :runit_sv_search_path, '/sbin:/usr/sbin'
29
43
  end
30
44
  end
@@ -1,3 +1,7 @@
1
- #!/bin/bash
2
- cd <%= current_path %>
3
- <%= runit_command %>
1
+ #!/bin/sh
2
+ if [ -d <%= current_path %> ]; then
3
+ cd <%= current_path %>
4
+ <%= _runit_command %>
5
+ else
6
+ echo "Directory <%= current_path %> is missing. Retrying ..."
7
+ fi
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.1.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: 2014-09-29 00:00:00.000000000 Z
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.2.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