capistrano-vexxhost 1.0.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 ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in capistrano-vexxhost.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "capistrano-vexxhost/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "capistrano-vexxhost"
7
+ s.version = Capistrano::Vexxhost::VERSION
8
+ s.authors = ["Mohammed Naser"]
9
+ s.email = ["mnaser@vexxhost.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Capistrano extension allowing deployment Rails applications on VEXXHOST}
12
+ s.description = %q{Capistrano extension allowing deployment Rails applications on VEXXHOST}
13
+
14
+ s.rubyforge_project = "capistrano-vexxhost"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "capistrano"
22
+ s.add_runtime_dependency "json"
23
+ end
@@ -0,0 +1,122 @@
1
+ require 'base64'
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ Capistrano::Configuration.instance(:must_exist).load do
6
+ set(:deploy_to) { "/home/#{fetch(:user)}/apps/#{fetch(:application)}" }
7
+ set(:use_sudo) { false }
8
+ set(:auth_string) { Base64.encode64("#{fetch(:user)}:#{fetch(:password)}").strip }
9
+ _cset(:server_hostname) { fetch(:domain) }
10
+
11
+ role(:web) { fetch(:server_hostname) }
12
+ role(:app) { fetch(:server_hostname) }
13
+ role(:db) { fetch(:server_hostname) }
14
+
15
+ # Create serverside application when setting up
16
+ before 'deploy:setup', 'deploy:create_app'
17
+ # Mount application after setting it up
18
+ after 'deploy:setup', 'deploy:mount'
19
+
20
+ namespace :deploy do
21
+ desc <<-DESC
22
+ Create a remote application using the cPanel API in order to make
23
+ all the required folders and the service records.
24
+ DESC
25
+ task :create_app, :except => { :no_release => true } do
26
+ # Create the remote app first
27
+ response_hash = cpanel_api2_command(server_hostname, auth_string, "RoR", "addapp", {'appname' => application, 'path' => "apps/#{application}"})
28
+
29
+ if response_hash["cpanelresult"]["data"][0]["status"] != 1
30
+ raise response_hash["cpanelresult"]["data"][0]["statusmsg"]
31
+ end
32
+ end
33
+
34
+ desc <<-DESC
35
+ Start the Rails application on the server
36
+ DESC
37
+ task :start, :roles => :app do
38
+ response_hash = cpanel_api2_command(server_hostname, auth_string, "RoR", "startapp", {'appname' => application})
39
+
40
+ if response_hash["cpanelresult"]["data"][0]["status"] != 1
41
+ raise response_hash["cpanelresult"]["data"][0]["statusmsg"]
42
+ else
43
+ puts response_hash["cpanelresult"]["data"][0]["statusmsg"]
44
+ end
45
+ end
46
+
47
+ desc <<-DESC
48
+ Stop the Rails application on the server
49
+ DESC
50
+ task :stop, :roles => :app do
51
+ response_hash = cpanel_api2_command(server_hostname, auth_string, "RoR", "stopapp", {'appname' => application})
52
+
53
+ # Empty response = not running
54
+ if response_hash.nil?
55
+ raise "The rails application is not running."
56
+ end
57
+
58
+ if response_hash["cpanelresult"]["data"][0]["status"] != 1
59
+ raise response_hash["cpanelresult"]["data"][0]["statusmsg"]
60
+ else
61
+ puts response_hash["cpanelresult"]["data"][0]["statusmsg"]
62
+ end
63
+ end
64
+
65
+ desc <<-DESC
66
+ Restart the Rails application on the server
67
+ DESC
68
+ task :restart, :roles => :app do
69
+ response_hash = cpanel_api2_command(server_hostname, auth_string, "RoR", "restartapp", {'appname' => application})
70
+
71
+ if response_hash["cpanelresult"]["data"][0]["status"] != 1
72
+ raise response_hash["cpanelresult"]["data"][0]["statusmsg"]
73
+ else
74
+ puts response_hash["cpanelresult"]["data"][0]["statusmsg"]
75
+ end
76
+ end
77
+
78
+ desc <<-DESC
79
+ Mount the application to a specific section of the website
80
+ DESC
81
+ task :mount, :roles => :app do
82
+ response_hash = cpanel_api2_command(server_hostname, auth_string, "RoR", "setuprewrite", {'appname' => application, 'rewritedomain' => domain, 'rewriteurl' => mount_path})
83
+
84
+ if response_hash["cpanelresult"]["data"][0]["status"] != 1
85
+ raise response_hash["cpanelresult"]["data"][0]["statusmsg"]
86
+ else
87
+ puts response_hash["cpanelresult"]["data"][0]["statusmsg"]
88
+ end
89
+ end
90
+
91
+ desc <<-DESC
92
+ Unmount the application from the website
93
+ DESC
94
+ task :unmount, :roles => :app do
95
+ response_hash = cpanel_api2_command(server_hostname, auth_string, "RoR", "removerewrite", {'appname' => application, 'rewritedomain' => domain, 'rewriteurl' => mount_path})
96
+
97
+ if response_hash["cpanelresult"]["data"][0]["status"] != 1
98
+ raise response_hash["cpanelresult"]["data"][0]["statusmsg"]
99
+ else
100
+ puts response_hash["cpanelresult"]["data"][0]["statusmsg"]
101
+ end
102
+ end
103
+ end
104
+
105
+ # Run a remote command using the cPanel API2
106
+ def cpanel_api2_command(hostname, authorization, _module, func, args)
107
+ # Prepare the request
108
+ request_hash = { 'cpanel_jsonapi_module' => _module,
109
+ 'cpanel_jsonapi_func' => func }.merge(args)
110
+ request_query = request_hash.to_a.map { |kv| "#{kv[0]}=#{kv[1]}" }.join("&")
111
+ request_location = "/json-api/cpanel?#{request_query}"
112
+
113
+ # Run the request
114
+ Net::HTTP.start(hostname, 2083, :use_ssl => true, :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
115
+ request = Net::HTTP::Get.new(request_location, {'Authorization' => "Basic #{authorization}"})
116
+ response = http.request(request)
117
+
118
+ return (response.body.empty?) ? nil : JSON.parse(response.body)
119
+ end
120
+ end
121
+
122
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Vexxhost
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "capistrano-vexxhost/version"
2
+ require "capistrano-vexxhost/capistrano_integration"
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-vexxhost
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mohammed Naser
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-15 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: &70237563330120 !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: *70237563330120
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &70237563329640 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70237563329640
36
+ description: Capistrano extension allowing deployment Rails applications on VEXXHOST
37
+ email:
38
+ - mnaser@vexxhost.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - Rakefile
46
+ - capistrano-vexxhost.gemspec
47
+ - lib/capistrano-vexxhost.rb
48
+ - lib/capistrano-vexxhost/capistrano_integration.rb
49
+ - lib/capistrano-vexxhost/version.rb
50
+ homepage: ''
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project: capistrano-vexxhost
70
+ rubygems_version: 1.8.6
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Capistrano extension allowing deployment Rails applications on VEXXHOST
74
+ test_files: []