capistrano-daemonize 0.9.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.
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/LICENSE +18 -0
- data/README.md +27 -0
- data/Rakefile +2 -0
- data/capistrano-daemonize.gemspec +22 -0
- data/lib/capistrano-daemonize/daemonize.rb +64 -0
- data/lib/capistrano-daemonize/version.rb +13 -0
- data/lib/capistrano-daemonize.rb +2 -0
- metadata +88 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2013 Christopher Schramm.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to
|
8
|
+
do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
14
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
15
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
16
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
17
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
18
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
capistrano-daemonize adds a daemonize method to Capistrano's DSL to generate tasks that control arbitrary processes as daemons.
|
2
|
+
It makes use of Debian's /sbin/start-stop-daemon, which is available in every Debian-based Linux distribution like Ubuntu.
|
3
|
+
OpenSuSE and Mandriva do have the binary in both the sysvinit and dpkg packages.
|
4
|
+
|
5
|
+
Sample usage in your `deploy.rb`:
|
6
|
+
|
7
|
+
require 'capistrano-daemonize'
|
8
|
+
daemonize '/usr/bin/env bundle exec rake qc:work', as: 'myworker', callbacks: true, role: :worker
|
9
|
+
|
10
|
+
This creates three tasks: myworker:start, myworker:stop and myworker:restart.
|
11
|
+
The namspace is defined by the mandatory option `:as`.
|
12
|
+
|
13
|
+
If `:callbacks` is set, the tasks are automatically added to the respective
|
14
|
+
deploy tasks. You could do that manually by adding:
|
15
|
+
|
16
|
+
after 'deploy:restart', 'myworker:restart'
|
17
|
+
after 'deploy:start', 'myworker:start'
|
18
|
+
after 'deploy:stop', 'myworker:stop'
|
19
|
+
|
20
|
+
You can use the `:pidfile` and `:logfile` options to defined the respective
|
21
|
+
files, which default to `"#{shared_path}/pids/myworker.pid"` and
|
22
|
+
`"#{shared_path}/log/myworker.log"`.
|
23
|
+
|
24
|
+
`:chdir` may be used to set the the working directory for the daemon and
|
25
|
+
`:user` to switch to another user than logged in.
|
26
|
+
|
27
|
+
Other options, like `:role` in the example above, will be used when defining the tasks.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/capistrano-daemonize/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'capistrano-daemonize'
|
6
|
+
s.version = Capistrano::Daemonize::Version.to_s
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.author = 'Christopher Schramm'
|
9
|
+
s.email = 'cschramm@shakaweb.org'
|
10
|
+
s.homepage = 'https://github.com/cschramm/capistrano-daemonize'
|
11
|
+
s.summary = %q{Control arbitrary jobs using start-stop-daemon in Capistrano}
|
12
|
+
s.description = %q{Adds a daemonize method to the Capistrano DSL to generate start, stop and restart tasks for an arbitrary command controlled with start-stop-daemon.}
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.require_paths = %w(lib)
|
17
|
+
s.extra_rdoc_files = %w(README.md)
|
18
|
+
|
19
|
+
s.add_development_dependency 'rake'
|
20
|
+
|
21
|
+
s.add_runtime_dependency 'capistrano'
|
22
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Capistrano
|
2
|
+
class Configuration
|
3
|
+
def daemonize(command, options)
|
4
|
+
raise "Must pass a hash containing 'as'" if not options.is_a?(Hash) or
|
5
|
+
not options.has_key?(:as)
|
6
|
+
|
7
|
+
name = options.delete(:as)
|
8
|
+
opts = Hash[[:pidfile, :logfile, :chdir, :user].map do
|
9
|
+
|option| [option, options.delete(option)]
|
10
|
+
end]
|
11
|
+
callbacks = options.delete(:callbacks)
|
12
|
+
sudo_command = ''
|
13
|
+
|
14
|
+
before(%w(start stop restart).map { |action| "#{name}:#{action}" }) do
|
15
|
+
_cset(:rails_env) { fetch(:rails_env) || 'production' }
|
16
|
+
_cset(:daemonize_pidfile) do
|
17
|
+
opts[:pidfile] || "#{fetch(:shared_path)}/pids/#{name}.pid"
|
18
|
+
end
|
19
|
+
_cset(:daemonize_logfile) do
|
20
|
+
opts[:logfile] || "#{fetch(:shared_path)}/log/#{name}.log"
|
21
|
+
end
|
22
|
+
_cset(:daemonize_chdir) { opts[:chdir] || fetch(:current_path) }
|
23
|
+
_cset(:daemonize_user) { opts[:user] || fetch(:user) }
|
24
|
+
_cset(:daemonize_sudo) do
|
25
|
+
opts[:user] == fetch(:user) && try_sudo || ''
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
namespace name do
|
30
|
+
task :start, options do
|
31
|
+
run <<-SCRIPT
|
32
|
+
if [ -e #{daemonize_pidfile} ]; then
|
33
|
+
echo 'pidfile exists';
|
34
|
+
exit 1;
|
35
|
+
fi;
|
36
|
+
|
37
|
+
#{daemonize_sudo} /sbin/start-stop-daemon --pidfile #{daemonize_pidfile} \
|
38
|
+
--start --make-pidfile --chdir #{daemonize_chdir} --user #{daemonize_user} \
|
39
|
+
--background --exec #{command.split[0]} -- #{command.split[1..-1].join(' ')} \
|
40
|
+
2>&1 >>#{daemonize_logfile} RAILS_ENV=#{rails_env}
|
41
|
+
SCRIPT
|
42
|
+
end
|
43
|
+
|
44
|
+
task :stop, options do
|
45
|
+
run <<-SCRIPT
|
46
|
+
#{sudo_command} /sbin/start-stop-daemon --stop --pidfile #{daemonize_pidfile};
|
47
|
+
rm -f #{daemonize_pidfile}
|
48
|
+
SCRIPT
|
49
|
+
end
|
50
|
+
|
51
|
+
task :restart, options do
|
52
|
+
stop
|
53
|
+
start
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
if callbacks
|
58
|
+
after 'deploy:start', "#{name}:start"
|
59
|
+
after 'deploy:stop', "#{name}:stop"
|
60
|
+
after 'deploy:restart', "#{name}:restart"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-daemonize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christopher Schramm
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: capistrano
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Adds a daemonize method to the Capistrano DSL to generate start, stop
|
47
|
+
and restart tasks for an arbitrary command controlled with start-stop-daemon.
|
48
|
+
email: cschramm@shakaweb.org
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.md
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- capistrano-daemonize.gemspec
|
60
|
+
- lib/capistrano-daemonize.rb
|
61
|
+
- lib/capistrano-daemonize/daemonize.rb
|
62
|
+
- lib/capistrano-daemonize/version.rb
|
63
|
+
homepage: https://github.com/cschramm/capistrano-daemonize
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.23
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Control arbitrary jobs using start-stop-daemon in Capistrano
|
87
|
+
test_files: []
|
88
|
+
has_rdoc:
|