capistrano-upstart 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +1 -0
- data/capistrano-upstart.gemspec +21 -0
- data/lib/capistrano-upstart.rb +123 -0
- data/lib/capistrano-upstart/version.rb +5 -0
- data/lib/templates/upstart.conf.erb +61 -0
- metadata +70 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Yamashita Yuu
|
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,61 @@
|
|
1
|
+
# Capistrano::Upstart
|
2
|
+
|
3
|
+
a capistrano recipe to manage upstart service.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'capistrano-upstart'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install capistrano-upstart
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
This recipes will try to set up Upstart service after `deploy:setup` tasks.
|
22
|
+
To enable this recipe for your application, add following in you `config/deploy.rb`.
|
23
|
+
|
24
|
+
# in "config/deploy.rb"
|
25
|
+
require 'capistrano-upstart'
|
26
|
+
set(:upstart_script, <<-EOS)
|
27
|
+
exec echo "hello, world"
|
28
|
+
EOS
|
29
|
+
|
30
|
+
Following options are available to manage your service.
|
31
|
+
|
32
|
+
* `:upstart_service_name` - the name of your Upstart service.
|
33
|
+
* `:upstart_exec` - the `exec` script of your Upstart service.
|
34
|
+
* `:upstart_script` - the script of your Upstart service. You must specify either `:upstart_exec` or `:upstart_script`.
|
35
|
+
* `:upstart_pre_start_script` - the `pre-start` script of your Upstart service.
|
36
|
+
* `:upstart_post_start_script` - the `post-start` script of your Upstart service.
|
37
|
+
* `:upstart_pre_stop_script` - the `pre-stop` script of your Upstart service.
|
38
|
+
* `:upstart_post_stop_script` - the `post-stop` script of your Upstart service.
|
39
|
+
* `:upstart_start_on` - specify when your service should be starting on. By default runlevel 2, 3, 4 and 5.
|
40
|
+
* `:upstart_stop_on` - specify when your service should be stopping on. By default runlevel 0, 1 and 6.
|
41
|
+
* `:upstart_env` - environmental variables for your service.
|
42
|
+
* `:upstart_chdir` - specify the working directory of service. Use `:current_path` by default.
|
43
|
+
* `:upstart_console` - the `console` directive of Upstart. `none` by default.
|
44
|
+
* `:upstart_respawn` - specify whether service should be respawned or not. `true` by default.
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
53
|
+
|
54
|
+
## Author
|
55
|
+
|
56
|
+
- YAMASHITA Yuu (https://github.com/yyuu)
|
57
|
+
- Geisha Tokyo Entertainment Inc. (http://www.geishatokyo.com/)
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
MIT
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano-upstart/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "capistrano-upstart"
|
8
|
+
gem.version = Capistrano::Upstart::VERSION
|
9
|
+
gem.authors = ["Yamashita Yuu"]
|
10
|
+
gem.email = ["yamashita@geishatokyo.com"]
|
11
|
+
gem.description = %q{a capistrano recipe to manage upstart serivce.}
|
12
|
+
gem.summary = %q{a capistrano recipe to manage upstart serivce.}
|
13
|
+
gem.homepage = "https://github.com/yyuu/capistrano-upstart"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency("capistrano")
|
21
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require "capistrano-upstart/version"
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module Capistrano
|
5
|
+
module Upstart
|
6
|
+
def self.extended(configuration)
|
7
|
+
configuration.load {
|
8
|
+
namespace(:deploy) {
|
9
|
+
desc("Start upstart service.")
|
10
|
+
task(:start, :roles => :app, :except => { :no_release => true }) {
|
11
|
+
find_and_execute_task("upstart:start")
|
12
|
+
}
|
13
|
+
|
14
|
+
desc("Stop upstart service.")
|
15
|
+
task(:stop, :roles => :app, :except => { :no_release => true }) {
|
16
|
+
find_and_execute_task("upstart:stop")
|
17
|
+
}
|
18
|
+
|
19
|
+
desc("Restart upstart service.")
|
20
|
+
task(:restart, :roles => :app, :except => { :no_release => true }) {
|
21
|
+
find_and_execute_task("upstart:restart")
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
namespace(:upstart) {
|
26
|
+
_cset(:upstart_template_source_path, File.join(File.dirname(__FILE__), 'templates'))
|
27
|
+
_cset(:upstart_template_files) {
|
28
|
+
[
|
29
|
+
"#{upstart_service_name}.conf",
|
30
|
+
"#{upstart_service_name}.conf.erb",
|
31
|
+
"upstart.conf",
|
32
|
+
"upstart.conf.erb",
|
33
|
+
]
|
34
|
+
}
|
35
|
+
|
36
|
+
_cset(:upstart_service_file) {
|
37
|
+
"/etc/init/#{upstart_service_name}.conf"
|
38
|
+
}
|
39
|
+
_cset(:upstart_service_name) {
|
40
|
+
abort("You must set upstart_service_name explicitly.")
|
41
|
+
}
|
42
|
+
|
43
|
+
_cset(:upstart_start_on, { :runlevel => "[2345]" })
|
44
|
+
_cset(:upstart_stop_on, { :runlevel => "[016]" })
|
45
|
+
_cset(:upstart_env, {})
|
46
|
+
_cset(:upstart_export, [])
|
47
|
+
_cset(:upstart_script) {
|
48
|
+
abort("You must specify either :upstart_exec or :upstart_script.")
|
49
|
+
}
|
50
|
+
|
51
|
+
_cset(:upstart_chdir) { current_path }
|
52
|
+
_cset(:upstart_console, 'none')
|
53
|
+
_cset(:upstart_respawn, true)
|
54
|
+
_cset(:upstart_options) {{
|
55
|
+
"author" => fetch(:upstart_author, '').to_s.dump,
|
56
|
+
"chdir" => upstart_chdir,
|
57
|
+
"console" => upstart_console,
|
58
|
+
"description" => fetch(:upstart_description, '').to_s.dump,
|
59
|
+
"respawn" => upstart_respawn,
|
60
|
+
}}
|
61
|
+
|
62
|
+
desc("Setup upstart service.")
|
63
|
+
task(:setup, :roles => :app, :except => { :no_release => true }) {
|
64
|
+
transaction {
|
65
|
+
configure
|
66
|
+
}
|
67
|
+
}
|
68
|
+
after 'deploy:setup', 'upstart:setup'
|
69
|
+
|
70
|
+
task(:configure, :roles => :app, :except => { :no_release => true }) {
|
71
|
+
tempfile = '/tmp/upstart.conf'
|
72
|
+
begin
|
73
|
+
template = upstart_template_files.map { |f| File.join(upstart_template_source_path, f) }.find { |t| File.file?(t) }
|
74
|
+
unless template
|
75
|
+
abort("could not find template for upstart configuration file for `#{upstart_service_name}'.")
|
76
|
+
end
|
77
|
+
case File.extname(template)
|
78
|
+
when '.erb'
|
79
|
+
put(ERB.new(File.read(template)).result(binding), tempfile)
|
80
|
+
else
|
81
|
+
put(File.read(template), tempfile)
|
82
|
+
end
|
83
|
+
run("diff -u #{upstart_service_file} #{tempfile} || #{sudo} mv -f #{tempfile} #{upstart_service_file}")
|
84
|
+
ensure
|
85
|
+
run("rm -f #{tempfile}")
|
86
|
+
end
|
87
|
+
}
|
88
|
+
|
89
|
+
desc("Start upstart service.")
|
90
|
+
task(:start, :roles => :app, :except => { :no_release => true }) {
|
91
|
+
run("#{sudo} service #{upstart_service_name} start")
|
92
|
+
}
|
93
|
+
|
94
|
+
desc("Stop upstart service.")
|
95
|
+
task(:stop, :roles => :app, :except => { :no_release => true }) {
|
96
|
+
run("#{sudo} service #{upstart_service_name} stop")
|
97
|
+
}
|
98
|
+
|
99
|
+
desc("Restart upstart service.")
|
100
|
+
task(:restart, :roles => :app, :except => { :no_release => true }) {
|
101
|
+
run("#{sudo} service #{upstart_service_name} restart || #{sudo} service #{upstart_service_name} start")
|
102
|
+
}
|
103
|
+
|
104
|
+
desc("Reload upstart service.")
|
105
|
+
task(:reload, :roles => :app, :except => { :no_release => true }) {
|
106
|
+
run("#{sudo} service #{upstart_service_name} reload || #{sudo} service #{upstart_service_name} start")
|
107
|
+
}
|
108
|
+
|
109
|
+
desc("Show upstart service status.")
|
110
|
+
task(:status, :roles => :app, :except => { :no_release => true }) {
|
111
|
+
run("#{sudo} service #{upstart_service_name} status")
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
if Capistrano::Configuration.instance
|
120
|
+
Capistrano::Configuration.instance.extend(Capistrano::Upstart)
|
121
|
+
end
|
122
|
+
|
123
|
+
# vim:set ft=ruby :
|
@@ -0,0 +1,61 @@
|
|
1
|
+
## start on
|
2
|
+
<% upstart_start_on.each do |key, val| %>
|
3
|
+
start on <%= key %> <%= val %>
|
4
|
+
<% end %>
|
5
|
+
|
6
|
+
## stop on
|
7
|
+
<% upstart_stop_on.each do |key, val| %>
|
8
|
+
stop on <%= key %> <%= val %>
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
## env
|
12
|
+
<% upstart_env.each do |key, val| %>
|
13
|
+
env <%= "#{key}=#{val.to_s.dump}" %>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
## export
|
17
|
+
<% upstart_export.each do |key| %>
|
18
|
+
export <%= key %>
|
19
|
+
<% end %>
|
20
|
+
|
21
|
+
## misc options
|
22
|
+
<% upstart_options.each do |key, val| %>
|
23
|
+
<%= val == true ? key : "#{key} #{val}" %>
|
24
|
+
<% end %>
|
25
|
+
|
26
|
+
## pre-start
|
27
|
+
<% if fetch(:upstart_pre_start_script, nil) %>
|
28
|
+
pre-start script
|
29
|
+
<%= upstart_pre_start_script %>
|
30
|
+
end script
|
31
|
+
<% end %>
|
32
|
+
|
33
|
+
## script
|
34
|
+
<% if fetch(:upstart_exec, nil) %>
|
35
|
+
exec <%= upstart_exec %>
|
36
|
+
<% else %>
|
37
|
+
script
|
38
|
+
<%= upstart_script %>
|
39
|
+
end script
|
40
|
+
<% end %>
|
41
|
+
|
42
|
+
## post-start
|
43
|
+
<% if fetch(:upstart_post_start_script, nil) %>
|
44
|
+
post-start script
|
45
|
+
<%= upstart_post_start_script %>
|
46
|
+
end script
|
47
|
+
<% end %>
|
48
|
+
|
49
|
+
## pre-stop
|
50
|
+
<% if fetch(:upstart_pre_stop_script, nil) %>
|
51
|
+
pre-stop script
|
52
|
+
<%= upstart_pre_stop_script %>
|
53
|
+
end script
|
54
|
+
<% end %>
|
55
|
+
|
56
|
+
## post-stop
|
57
|
+
<% if fetch(:upstart_post_stop_script, nil) %>
|
58
|
+
post-stop script
|
59
|
+
<%= upstart_post_stop_script %>
|
60
|
+
end script
|
61
|
+
<% end %>
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-upstart
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Yamashita Yuu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
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
|
+
description: a capistrano recipe to manage upstart serivce.
|
31
|
+
email:
|
32
|
+
- yamashita@geishatokyo.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- capistrano-upstart.gemspec
|
43
|
+
- lib/capistrano-upstart.rb
|
44
|
+
- lib/capistrano-upstart/version.rb
|
45
|
+
- lib/templates/upstart.conf.erb
|
46
|
+
homepage: https://github.com/yyuu/capistrano-upstart
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.23
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: a capistrano recipe to manage upstart serivce.
|
70
|
+
test_files: []
|