app_maint 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app_maint.gemspec +1 -0
- data/lib/app_maint/version.rb +1 -1
- data/lib/app_maint.rb +14 -0
- data/lib/recipes/base.rb +44 -0
- data/lib/recipes/chef.rb +36 -0
- data/lib/recipes/git.rb +1 -1
- metadata +22 -4
data/app_maint.gemspec
CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.add_development_dependency "rake"
|
16
16
|
gem.add_dependency "capistrano"
|
17
17
|
gem.add_dependency "capistrano-ext"
|
18
|
+
gem.add_dependency "json"
|
18
19
|
|
19
20
|
gem.files = `git ls-files`.split($/)
|
20
21
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/lib/app_maint/version.rb
CHANGED
data/lib/app_maint.rb
CHANGED
@@ -2,3 +2,17 @@ require 'capistrano'
|
|
2
2
|
require 'capistrano/cli'
|
3
3
|
|
4
4
|
Dir.glob(File.join(File.dirname(__FILE__), '/recipes/*.rb')).sort.each { |recipe| load recipe }
|
5
|
+
|
6
|
+
def with_user(new_user, &block)
|
7
|
+
old_user = user
|
8
|
+
set :user, new_user
|
9
|
+
close_sessions
|
10
|
+
yield
|
11
|
+
set :user, old_user
|
12
|
+
close_sessions
|
13
|
+
end
|
14
|
+
|
15
|
+
def close_sessions
|
16
|
+
sessions.values.each { |session| session.close }
|
17
|
+
sessions.clear
|
18
|
+
end
|
data/lib/recipes/base.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Capistrano::Configuration.instance.load do
|
2
|
+
namespace :base do
|
3
|
+
desc "Prepare system for deployment"
|
4
|
+
task :setup do
|
5
|
+
init_deploy_user
|
6
|
+
install
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Init environment for deployment user"
|
10
|
+
task :init_deploy_user do
|
11
|
+
set :deploy_user, "#{user}"
|
12
|
+
with_user "#{sudo_user}" do
|
13
|
+
if capture( "#{sudo} cat /etc/passwd | grep #{deploy_user} | wc -l" ).to_i == 0
|
14
|
+
run "#{sudo} addgroup admin"
|
15
|
+
run "#{sudo} useradd deployer -m -s /bin/bash -g admin"
|
16
|
+
upload "#{Dir.home}/.ssh/id_rsa.pub", "/tmp/id_rsa.pub"
|
17
|
+
run "#{sudo} mkdir -p /home/#{deploy_user}/.ssh"
|
18
|
+
run "echo \"cat /tmp/id_rsa.pub >> /home/#{deploy_user}/.ssh/authorized_keys\" | sudo -s"
|
19
|
+
run "rm /tmp/id_rsa.pub"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Install minimum prerequisites for app_maint"
|
25
|
+
task :install do
|
26
|
+
with_user "#{sudo_user}" do
|
27
|
+
if capture( "which ruby | wc -l" ).to_i == 0
|
28
|
+
run "#{sudo} apt-get -y update"
|
29
|
+
run "#{sudo} apt-get -y install python-software-properties"
|
30
|
+
run "#{sudo} apt-get -y install curl git-core"
|
31
|
+
run "#{sudo} apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev"
|
32
|
+
run "wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz"
|
33
|
+
run "tar -xvzf ruby-1.9.3-p194.tar.gz"
|
34
|
+
run "cd ruby-1.9.3-p194/ && ./configure --prefix=/usr/local && make && #{sudo} make install"
|
35
|
+
run "#{sudo} gem install bundler --no-ri --no-rdoc"
|
36
|
+
run "#{sudo} gem install chef ruby-shadow --no-ri --no-rdoc"
|
37
|
+
run "#{sudo} gem install server_maint --no-ri --no-rdoc"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
before "deploy:setup", "base:setup"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
data/lib/recipes/chef.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
Capistrano::Configuration.instance.load do
|
4
|
+
namespace :chef do
|
5
|
+
desc "Manages all system dependencies for this application"
|
6
|
+
task :manages, roles: :web do
|
7
|
+
run "mkdir -p /home/#{user}/apps/#{application}/shared/log"
|
8
|
+
chef_cookbook_path =
|
9
|
+
capture( %q{ruby -e 'require "server_maint"; puts ServerMaint::get_cookbook_path'} ).chomp
|
10
|
+
app_cookbook_path = "/home/#{user}/apps/#{application}/shared/cookbooks"
|
11
|
+
chef_config = [
|
12
|
+
%Q(cookbook_path ["#{chef_cookbook_path}", File.expand_path("../cookbooks", __FILE__)]),
|
13
|
+
%Q(json_attribs File.expand_path("../node.json", __FILE__))
|
14
|
+
].join( "\n" )
|
15
|
+
put(
|
16
|
+
chef_config,
|
17
|
+
"/home/#{user}/apps/#{application}/shared/solo.rb"
|
18
|
+
)
|
19
|
+
node_config = { "run_list" => ["recipe[main]"] }.to_json
|
20
|
+
put node_config, "/home/#{user}/apps/#{application}/shared/node.json"
|
21
|
+
upload(
|
22
|
+
"#{cookbooks}",
|
23
|
+
"/home/#{user}/apps/#{application}/shared/cookbooks",
|
24
|
+
{:recursive => true, :via => :scp}
|
25
|
+
)
|
26
|
+
run [
|
27
|
+
"chef-solo",
|
28
|
+
"-c /home/#{user}/apps/#{application}/shared/solo.rb",
|
29
|
+
"-L /home/#{user}/apps/#{application}/shared/log/chef.log",
|
30
|
+
"1>/dev/null"
|
31
|
+
].join( ' ' )
|
32
|
+
end
|
33
|
+
before "deploy:setup", "chef:manages"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
data/lib/recipes/git.rb
CHANGED
@@ -4,7 +4,7 @@ Capistrano::Configuration.instance.load do
|
|
4
4
|
task :setup, roles: :web do
|
5
5
|
run "mkdir -p /home/deployer/repos/#{application}.git"
|
6
6
|
run "cd /home/deployer/repos/#{application}.git && git --bare init"
|
7
|
-
run_locally "git remote add
|
7
|
+
run_locally "git remote add #{remote} ssh://#{user}@#{host_name}/home/deployer/repos/#{application}.git"
|
8
8
|
end
|
9
9
|
after "deploy:setup", "git:setup"
|
10
10
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app_maint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: json
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
62
78
|
description: Provides usefull capistrano recipes for application maintenance
|
63
79
|
email: frd@doebbelin.net
|
64
80
|
executables: []
|
@@ -73,6 +89,8 @@ files:
|
|
73
89
|
- app_maint.gemspec
|
74
90
|
- lib/app_maint.rb
|
75
91
|
- lib/app_maint/version.rb
|
92
|
+
- lib/recipes/base.rb
|
93
|
+
- lib/recipes/chef.rb
|
76
94
|
- lib/recipes/git.rb
|
77
95
|
homepage: http://github.com/fdoebbelin/app_maint
|
78
96
|
licenses: []
|
@@ -88,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
106
|
version: '0'
|
89
107
|
segments:
|
90
108
|
- 0
|
91
|
-
hash:
|
109
|
+
hash: 202345415463774109
|
92
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
111
|
none: false
|
94
112
|
requirements:
|
@@ -97,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
115
|
version: '0'
|
98
116
|
segments:
|
99
117
|
- 0
|
100
|
-
hash:
|
118
|
+
hash: 202345415463774109
|
101
119
|
requirements: []
|
102
120
|
rubyforge_project:
|
103
121
|
rubygems_version: 1.8.23
|