capistrano-upstart 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -21,9 +21,10 @@ Or install it yourself as:
21
21
  This recipes will try to set up Upstart service after `deploy:setup` tasks.
22
22
  To enable this recipe for your application, add following in you `config/deploy.rb`.
23
23
 
24
- # in "config/deploy.rb"
25
- require 'capistrano-upstart'
26
- set(:upstart_script, <<-EOS)
24
+ # config/deploy.rb
25
+ require "capistrano-upstart"
26
+ set :upstart_service_name, "hello"
27
+ set :upstart_script, <<-EOS
27
28
  exec echo "hello, world"
28
29
  EOS
29
30
 
@@ -18,6 +18,9 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency("capistrano")
21
- gem.add_dependency("capistrano-file-resources", "~> 0.0.1")
22
- gem.add_dependency("capistrano-file-transfer-ext", "~> 0.0.3")
21
+ gem.add_dependency("capistrano-file-resources", ">= 0.1.0")
22
+ gem.add_dependency("capistrano-file-transfer-ext", ">= 0.1.1")
23
+ gem.add_development_dependency("net-scp", "~> 1.0.4")
24
+ gem.add_development_dependency("net-ssh", "~> 2.2.2")
25
+ gem.add_development_dependency("vagrant", "~> 1.0.6")
23
26
  end
@@ -1,7 +1,6 @@
1
1
  require "capistrano-upstart/version"
2
2
  require "capistrano/configuration/actions/file_transfer_ext"
3
3
  require "capistrano/configuration/resources/file_resources"
4
- require "erb"
5
4
 
6
5
  module Capistrano
7
6
  module Upstart
@@ -51,10 +50,10 @@ module Capistrano
51
50
  }
52
51
 
53
52
  _cset(:upstart_chdir) { current_path }
54
- _cset(:upstart_console, 'none')
53
+ _cset(:upstart_console, "none")
55
54
  _cset(:upstart_respawn, true)
56
55
  _cset(:upstart_options) {{
57
- "author" => fetch(:upstart_author, 'unknown').to_s.dump,
56
+ "author" => fetch(:upstart_author, "unknown").to_s.dump,
58
57
  "chdir" => upstart_chdir,
59
58
  "console" => upstart_console,
60
59
  "description" => fetch(:upstart_description, application).to_s.dump,
@@ -67,39 +66,45 @@ module Capistrano
67
66
  configure
68
67
  }
69
68
  }
70
- after 'deploy:setup', 'upstart:setup'
69
+ after "deploy:setup", "upstart:setup"
71
70
 
71
+ _cset(:upstart_default_configure_options) {{
72
+ :install => :if_modified, :run_method => :sudo,
73
+ :owner => "root", :group => "root", :mode => "644",
74
+ }}
72
75
  task(:configure, :roles => :app, :except => { :no_release => true }) {
73
76
  t = upstart_template_files.find { |f|
74
77
  File.file?(File.join(upstart_template_source_path, "#{f}.erb")) or File.file?(File.join(upstart_template_source_path, f))
75
78
  }
76
- abort("could not find template for upstart configuration file for `#{upstart_service_name}'.") unless t
77
- safe_put(template(t, :path => upstart_template_source_path), upstart_service_file, :place => :if_modified, :sudo => true)
79
+ abort("Could not find template for upstart configuration file for `#{upstart_service_name}'.") unless t
80
+ safe_put(template(t, :path => upstart_template_source_path),
81
+ upstart_service_file,
82
+ upstart_default_configure_options.merge(fetch(:upstart_configure_options, {})))
78
83
  }
79
84
 
80
85
  desc("Start upstart service.")
81
86
  task(:start, :roles => :app, :except => { :no_release => true }) {
82
- run("#{sudo} service #{upstart_service_name} start")
87
+ run("#{sudo} start #{upstart_service_name.dump}")
83
88
  }
84
89
 
85
90
  desc("Stop upstart service.")
86
91
  task(:stop, :roles => :app, :except => { :no_release => true }) {
87
- run("#{sudo} service #{upstart_service_name} stop")
92
+ run("#{sudo} stop #{upstart_service_name.dump}")
88
93
  }
89
94
 
90
95
  desc("Restart upstart service.")
91
96
  task(:restart, :roles => :app, :except => { :no_release => true }) {
92
- run("#{sudo} service #{upstart_service_name} restart || #{sudo} service #{upstart_service_name} start")
97
+ run("#{sudo} restart #{upstart_service_name.dump} || #{sudo} start #{upstart_service_name.dump}")
93
98
  }
94
99
 
95
100
  desc("Reload upstart service.")
96
101
  task(:reload, :roles => :app, :except => { :no_release => true }) {
97
- run("#{sudo} service #{upstart_service_name} reload || #{sudo} service #{upstart_service_name} start")
102
+ run("#{sudo} reload #{upstart_service_name.dump} || #{sudo} start #{upstart_service_name.dump}")
98
103
  }
99
104
 
100
105
  desc("Show upstart service status.")
101
106
  task(:status, :roles => :app, :except => { :no_release => true }) {
102
- run("#{sudo} service #{upstart_service_name} status")
107
+ run("#{sudo} status #{upstart_service_name.dump}")
103
108
  }
104
109
  }
105
110
  }
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Upstart
3
- VERSION = "0.0.3"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ /.bundle
2
+ /.vagrant
3
+ /known_hosts
4
+ /tmp
5
+ /vendor
@@ -0,0 +1,2 @@
1
+ load "deploy"
2
+ load "../config/deploy"
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec(:path => "../..")
@@ -0,0 +1,99 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant::Config.run do |config|
5
+ # All Vagrant configuration is done here. The most common configuration
6
+ # options are documented and commented below. For a complete reference,
7
+ # please see the online documentation at vagrantup.com.
8
+
9
+ # Every Vagrant virtual environment requires a box to build off of.
10
+ config.vm.box = "centos6-64"
11
+
12
+ # The url from where the 'config.vm.box' box will be fetched if it
13
+ # doesn't already exist on the user's system.
14
+ config.vm.box_url = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.3-x86_64-v20130101.box"
15
+
16
+ # Boot with a GUI so you can see the screen. (Default is headless)
17
+ # config.vm.boot_mode = :gui
18
+
19
+ # Assign this VM to a host-only network IP, allowing you to access it
20
+ # via the IP. Host-only networks can talk to the host machine as well as
21
+ # any other machines on the same network, but cannot be accessed (through this
22
+ # network interface) by any external networks.
23
+ config.vm.network :hostonly, "192.168.33.10"
24
+
25
+ # Assign this VM to a bridged network, allowing you to connect directly to a
26
+ # network using the host's network device. This makes the VM appear as another
27
+ # physical device on your network.
28
+ # config.vm.network :bridged
29
+
30
+ # Forward a port from the guest to the host, which allows for outside
31
+ # computers to access the VM, whereas host only networking does not.
32
+ # config.vm.forward_port 80, 8080
33
+
34
+ # Share an additional folder to the guest VM. The first argument is
35
+ # an identifier, the second is the path on the guest to mount the
36
+ # folder, and the third is the path on the host to the actual folder.
37
+ # config.vm.share_folder "v-data", "/vagrant_data", "../data"
38
+
39
+ # Enable provisioning with Puppet stand alone. Puppet manifests
40
+ # are contained in a directory path relative to this Vagrantfile.
41
+ # You will need to create the manifests directory and a manifest in
42
+ # the file precise-amd64.pp in the manifests_path directory.
43
+ #
44
+ # An example Puppet manifest to provision the message of the day:
45
+ #
46
+ # # group { "puppet":
47
+ # # ensure => "present",
48
+ # # }
49
+ # #
50
+ # # File { owner => 0, group => 0, mode => 0644 }
51
+ # #
52
+ # # file { '/etc/motd':
53
+ # # content => "Welcome to your Vagrant-built virtual machine!
54
+ # # Managed by Puppet.\n"
55
+ # # }
56
+ #
57
+ # config.vm.provision :puppet do |puppet|
58
+ # puppet.manifests_path = "manifests"
59
+ # puppet.manifest_file = "precise-amd64.pp"
60
+ # end
61
+
62
+ # Enable provisioning with chef solo, specifying a cookbooks path, roles
63
+ # path, and data_bags path (all relative to this Vagrantfile), and adding
64
+ # some recipes and/or roles.
65
+ #
66
+ # config.vm.provision :chef_solo do |chef|
67
+ # chef.cookbooks_path = "../my-recipes/cookbooks"
68
+ # chef.roles_path = "../my-recipes/roles"
69
+ # chef.data_bags_path = "../my-recipes/data_bags"
70
+ # chef.add_recipe "mysql"
71
+ # chef.add_role "web"
72
+ #
73
+ # # You may also specify custom JSON attributes:
74
+ # chef.json = { :mysql_password => "foo" }
75
+ # end
76
+
77
+ # Enable provisioning with chef server, specifying the chef server URL,
78
+ # and the path to the validation key (relative to this Vagrantfile).
79
+ #
80
+ # The Opscode Platform uses HTTPS. Substitute your organization for
81
+ # ORGNAME in the URL and validation key.
82
+ #
83
+ # If you have your own Chef Server, use the appropriate URL, which may be
84
+ # HTTP instead of HTTPS depending on your configuration. Also change the
85
+ # validation key to validation.pem.
86
+ #
87
+ # config.vm.provision :chef_client do |chef|
88
+ # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
89
+ # chef.validation_key_path = "ORGNAME-validator.pem"
90
+ # end
91
+ #
92
+ # If you're using the Opscode platform, your validator client is
93
+ # ORGNAME-validator, replacing ORGNAME with your organization name.
94
+ #
95
+ # IF you have your own Chef Server, the default validation client name is
96
+ # chef-validator, unless you changed the configuration.
97
+ #
98
+ # chef.validation_client_name = "ORGNAME-validator"
99
+ end
@@ -0,0 +1,7 @@
1
+ #!/bin/sh -e
2
+
3
+ bundle exec vagrant up
4
+ bundle exec cap test_all
5
+ bundle exec vagrant halt
6
+
7
+ # vim:set ft=sh :
@@ -0,0 +1,106 @@
1
+ set :application, "capistrano-upstart"
2
+ set :repository, "."
3
+ set :deploy_to do
4
+ File.join("/home", user, application)
5
+ end
6
+ set :deploy_via, :copy
7
+ set :scm, :none
8
+ set :use_sudo, false
9
+ set :user, "vagrant"
10
+ set :password, "vagrant"
11
+ set :ssh_options, {:user_known_hosts_file => "/dev/null"}
12
+
13
+ ## upstart ##
14
+ set(:upstart_service_name, "capistrano-upstart")
15
+ set(:upstart_script, <<-EOS)
16
+ echo "hello, world"
17
+ EOS
18
+
19
+ role :web, "192.168.33.10"
20
+ role :app, "192.168.33.10"
21
+ role :db, "192.168.33.10", :primary => true
22
+
23
+ $LOAD_PATH.push(File.expand_path("../../lib", File.dirname(__FILE__)))
24
+ require "capistrano-upstart"
25
+
26
+ def assert_file_exists(file, options={})
27
+ begin
28
+ _invoke_command("test -f #{file.dump}", options)
29
+ rescue
30
+ logger.debug("assert_file_exists(#{file}) failed.")
31
+ _invoke_command("ls #{File.dirname(file).dump}", options)
32
+ raise
33
+ end
34
+ end
35
+
36
+ def assert_file_not_exists(file, options={})
37
+ begin
38
+ _invoke_command("test \! -f #{file.dump}", options)
39
+ rescue
40
+ logger.debug("assert_file_not_exists(#{file}) failed.")
41
+ _invoke_command("ls #{File.dirname(file).dump}", options)
42
+ raise
43
+ end
44
+ end
45
+
46
+ def assert_command(cmdline, options={})
47
+ begin
48
+ _invoke_command(cmdline, options)
49
+ rescue
50
+ logger.debug("assert_command(#{cmdline}) failed.")
51
+ raise
52
+ end
53
+ end
54
+
55
+ def assert_command_fails(cmdline, options={})
56
+ failed = false
57
+ begin
58
+ _invoke_command(cmdline, options)
59
+ rescue
60
+ logger.debug("assert_command_fails(#{cmdline}) failed.")
61
+ failed = true
62
+ ensure
63
+ abort unless failed
64
+ end
65
+ end
66
+
67
+ def reset_upstart!
68
+ variables.each_key do |key|
69
+ reset!(key) if /^upstart_/ =~ key
70
+ end
71
+ end
72
+
73
+ def uninstall_services!
74
+ sudo("service #{upstart_service_name.dump} stop || true")
75
+ sudo("rm -f #{upstart_service_file.dump}")
76
+ end
77
+
78
+ task(:test_all) {
79
+ find_and_execute_task("test_default")
80
+ }
81
+
82
+ on(:start) {
83
+ run("rm -rf #{deploy_to.dump}")
84
+ }
85
+
86
+ namespace(:test_default) {
87
+ task(:default) {
88
+ methods.grep(/^test_/).each do |m|
89
+ send(m)
90
+ end
91
+ }
92
+ before "test_default", "test_default:setup"
93
+ after "test_default", "test_default:teardown"
94
+
95
+ task(:setup) {
96
+ uninstall_services!
97
+ find_and_execute_task("deploy:setup")
98
+ find_and_execute_task("deploy")
99
+ }
100
+
101
+ task(:teardown) {
102
+ uninstall_services!
103
+ }
104
+ }
105
+
106
+ # vim:set ft=ruby sw=2 ts=2 :
@@ -0,0 +1 @@
1
+ credentials += Credentials("My Repository", "repository.example.com", "username", "password")
@@ -0,0 +1,5 @@
1
+ /.bundle
2
+ /.vagrant
3
+ /known_hosts
4
+ /tmp
5
+ /vendor
@@ -0,0 +1,2 @@
1
+ load "deploy"
2
+ load "../config/deploy"
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec(:path => "../..")
@@ -0,0 +1,99 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant::Config.run do |config|
5
+ # All Vagrant configuration is done here. The most common configuration
6
+ # options are documented and commented below. For a complete reference,
7
+ # please see the online documentation at vagrantup.com.
8
+
9
+ # Every Vagrant virtual environment requires a box to build off of.
10
+ config.vm.box = "precise64"
11
+
12
+ # The url from where the 'config.vm.box' box will be fetched if it
13
+ # doesn't already exist on the user's system.
14
+ config.vm.box_url = "http://files.vagrantup.com/precise64.box"
15
+
16
+ # Boot with a GUI so you can see the screen. (Default is headless)
17
+ # config.vm.boot_mode = :gui
18
+
19
+ # Assign this VM to a host-only network IP, allowing you to access it
20
+ # via the IP. Host-only networks can talk to the host machine as well as
21
+ # any other machines on the same network, but cannot be accessed (through this
22
+ # network interface) by any external networks.
23
+ config.vm.network :hostonly, "192.168.33.10"
24
+
25
+ # Assign this VM to a bridged network, allowing you to connect directly to a
26
+ # network using the host's network device. This makes the VM appear as another
27
+ # physical device on your network.
28
+ # config.vm.network :bridged
29
+
30
+ # Forward a port from the guest to the host, which allows for outside
31
+ # computers to access the VM, whereas host only networking does not.
32
+ # config.vm.forward_port 80, 8080
33
+
34
+ # Share an additional folder to the guest VM. The first argument is
35
+ # an identifier, the second is the path on the guest to mount the
36
+ # folder, and the third is the path on the host to the actual folder.
37
+ # config.vm.share_folder "v-data", "/vagrant_data", "../data"
38
+
39
+ # Enable provisioning with Puppet stand alone. Puppet manifests
40
+ # are contained in a directory path relative to this Vagrantfile.
41
+ # You will need to create the manifests directory and a manifest in
42
+ # the file precise-amd64.pp in the manifests_path directory.
43
+ #
44
+ # An example Puppet manifest to provision the message of the day:
45
+ #
46
+ # # group { "puppet":
47
+ # # ensure => "present",
48
+ # # }
49
+ # #
50
+ # # File { owner => 0, group => 0, mode => 0644 }
51
+ # #
52
+ # # file { '/etc/motd':
53
+ # # content => "Welcome to your Vagrant-built virtual machine!
54
+ # # Managed by Puppet.\n"
55
+ # # }
56
+ #
57
+ # config.vm.provision :puppet do |puppet|
58
+ # puppet.manifests_path = "manifests"
59
+ # puppet.manifest_file = "precise-amd64.pp"
60
+ # end
61
+
62
+ # Enable provisioning with chef solo, specifying a cookbooks path, roles
63
+ # path, and data_bags path (all relative to this Vagrantfile), and adding
64
+ # some recipes and/or roles.
65
+ #
66
+ # config.vm.provision :chef_solo do |chef|
67
+ # chef.cookbooks_path = "../my-recipes/cookbooks"
68
+ # chef.roles_path = "../my-recipes/roles"
69
+ # chef.data_bags_path = "../my-recipes/data_bags"
70
+ # chef.add_recipe "mysql"
71
+ # chef.add_role "web"
72
+ #
73
+ # # You may also specify custom JSON attributes:
74
+ # chef.json = { :mysql_password => "foo" }
75
+ # end
76
+
77
+ # Enable provisioning with chef server, specifying the chef server URL,
78
+ # and the path to the validation key (relative to this Vagrantfile).
79
+ #
80
+ # The Opscode Platform uses HTTPS. Substitute your organization for
81
+ # ORGNAME in the URL and validation key.
82
+ #
83
+ # If you have your own Chef Server, use the appropriate URL, which may be
84
+ # HTTP instead of HTTPS depending on your configuration. Also change the
85
+ # validation key to validation.pem.
86
+ #
87
+ # config.vm.provision :chef_client do |chef|
88
+ # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
89
+ # chef.validation_key_path = "ORGNAME-validator.pem"
90
+ # end
91
+ #
92
+ # If you're using the Opscode platform, your validator client is
93
+ # ORGNAME-validator, replacing ORGNAME with your organization name.
94
+ #
95
+ # IF you have your own Chef Server, the default validation client name is
96
+ # chef-validator, unless you changed the configuration.
97
+ #
98
+ # chef.validation_client_name = "ORGNAME-validator"
99
+ end
@@ -0,0 +1,7 @@
1
+ #!/bin/sh -e
2
+
3
+ bundle exec vagrant up
4
+ bundle exec cap test_all
5
+ bundle exec vagrant halt
6
+
7
+ # vim:set ft=sh :
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-upstart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
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: 2013-02-27 00:00:00.000000000 Z
12
+ date: 2013-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -32,33 +32,81 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ~>
35
+ - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 0.0.1
37
+ version: 0.1.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ~>
43
+ - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: 0.0.1
45
+ version: 0.1.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: capistrano-file-transfer-ext
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ~>
51
+ - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
- version: 0.0.3
53
+ version: 0.1.1
54
54
  type: :runtime
55
55
  prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: net-scp
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.4
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.4
78
+ - !ruby/object:Gem::Dependency
79
+ name: net-ssh
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 2.2.2
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 2.2.2
94
+ - !ruby/object:Gem::Dependency
95
+ name: vagrant
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.0.6
102
+ type: :development
103
+ prerelease: false
56
104
  version_requirements: !ruby/object:Gem::Requirement
57
105
  none: false
58
106
  requirements:
59
107
  - - ~>
60
108
  - !ruby/object:Gem::Version
61
- version: 0.0.3
109
+ version: 1.0.6
62
110
  description: a capistrano recipe to manage upstart serivce.
63
111
  email:
64
112
  - yamashita@geishatokyo.com
@@ -75,6 +123,18 @@ files:
75
123
  - lib/capistrano-upstart.rb
76
124
  - lib/capistrano-upstart/version.rb
77
125
  - lib/templates/upstart.conf.erb
126
+ - test/centos6-64/.gitignore
127
+ - test/centos6-64/Capfile
128
+ - test/centos6-64/Gemfile
129
+ - test/centos6-64/Vagrantfile
130
+ - test/centos6-64/run.sh
131
+ - test/config/deploy.rb
132
+ - test/config/templates/global.sbt.erb
133
+ - test/precise64/.gitignore
134
+ - test/precise64/Capfile
135
+ - test/precise64/Gemfile
136
+ - test/precise64/Vagrantfile
137
+ - test/precise64/run.sh
78
138
  homepage: https://github.com/yyuu/capistrano-upstart
79
139
  licenses: []
80
140
  post_install_message:
@@ -99,4 +159,16 @@ rubygems_version: 1.8.23
99
159
  signing_key:
100
160
  specification_version: 3
101
161
  summary: a capistrano recipe to manage upstart serivce.
102
- test_files: []
162
+ test_files:
163
+ - test/centos6-64/.gitignore
164
+ - test/centos6-64/Capfile
165
+ - test/centos6-64/Gemfile
166
+ - test/centos6-64/Vagrantfile
167
+ - test/centos6-64/run.sh
168
+ - test/config/deploy.rb
169
+ - test/config/templates/global.sbt.erb
170
+ - test/precise64/.gitignore
171
+ - test/precise64/Capfile
172
+ - test/precise64/Gemfile
173
+ - test/precise64/Vagrantfile
174
+ - test/precise64/run.sh