capistrano-procsd 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3750ba4bc43d0a0bbb89551c6fe7b8a7aed6256d0ee80eff0d30da7b104fb814
4
+ data.tar.gz: 50eb8cada745c68fe0f4c3f795f85228831a413a5c87ffa666efaade8541a540
5
+ SHA512:
6
+ metadata.gz: ae68476dbfd4e433134b0c39907c6b4ccf5aad6599f80985af3faca56a76cf3422423e39679107dba7301ea1e2b285f11df980cd37fb555f30091573097514b8
7
+ data.tar.gz: aad52774d9cd39733df3fd11779b90bc44b7948420c2f0c01d861d67050198dab0bb73198ab2b115a8925f386d4a296e6b381768afe611a05401affb91a5cbf7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in capistrano-procsd.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Victor Afanasev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # Capistrano::Procsd
2
+
3
+ Capistrano integration for [Procsd](https://github.com/vifreefly/procsd). All available tasks:
4
+
5
+ ```
6
+ cap procsd:create[arguments] # Create app services
7
+ cap procsd:create_or_restart # Create or restart (if already created) app services
8
+ cap procsd:destroy # Destroy app services
9
+ cap procsd:list # List all services
10
+ cap procsd:logs[arguments] # Check app services logs
11
+ cap procsd:restart # Restart app services
12
+ cap procsd:run[cmd] # Run command on the remote server
13
+ cap procsd:start # Start app services
14
+ cap procsd:status[arguments] # Check status of app services
15
+ cap procsd:stop # Stop app services
16
+ ```
17
+
18
+ ## Configuration
19
+
20
+ Add to your application `Gemfile` somewhere:
21
+
22
+ ```ruby
23
+ # Gemfile
24
+
25
+ group :development do
26
+ gem 'capistrano-procsd' require: false
27
+ end
28
+ ```
29
+
30
+ Require procsd tasks inside `Capfile`:
31
+
32
+ ```ruby
33
+ # Capfile
34
+
35
+ require 'capistrano/procsd'
36
+ ```
37
+
38
+ And finally add hook to call `procsd:create_or_restart` task each time after publishing:
39
+
40
+ ```ruby
41
+ # config/deploy.rb
42
+
43
+ after "deploy:publishing", "procsd:create_or_restart"
44
+ ```
45
+
46
+ Done!
47
+
48
+ ### Note about procsd location on the remote server
49
+
50
+ Configuration above assumes that you have `$ procsd` executable somewhere in the system path on your remote server. You can install gem system-wide this way:
51
+
52
+ ```bash
53
+ # Install ruby system-wide from apt repositories:
54
+ $ sudo apt install ruby
55
+
56
+ # Install procsd gem system-wide:
57
+ $ sudo gem install procsd
58
+ ```
59
+
60
+ Or, if you already use [Rbenv](https://github.com/rbenv/rbenv) you can do instead following:
61
+
62
+ Add `procsd` gem to your application Gemfile:
63
+
64
+ ```ruby
65
+ # Gemfile
66
+
67
+ group :development do
68
+ # You're probably already have it
69
+ gem 'capistrano-rbenv', require: false
70
+ gem 'capistrano-bundler', require: false
71
+ end
72
+
73
+ # Add procsd gem
74
+ gem 'procsd', require: false
75
+ ```
76
+
77
+ Require `capistrano/rbenv` and `capistrano/bundler` inside Capfile (if not required yet):
78
+
79
+ ```ruby
80
+ # Capfile
81
+
82
+ require 'capistrano/rbenv'
83
+ require 'capistrano/bundler'
84
+ ```
85
+
86
+ And finally add `procsd` to rbenv and bundle bins:
87
+
88
+ ```ruby
89
+ # config/deploy.rb
90
+
91
+ append :rbenv_map_bins, "procsd"
92
+ append :bundle_bins, "procsd"
93
+ ```
94
+
95
+ ## Usage
96
+
97
+ At the first deploy `$ bundle exec cap production deploy` app services will be created and started. You will be prompted to fill in remote user password (make sure that your deploy user added to the sudo group `adduser deploy sudo`).
98
+
99
+ If you don't want to type password each time while deploying, you can add start/stop/restart commands to the sudoers file:
100
+
101
+ 1. Login to the remote server, `cd` into application folder, and type `$ procsd config sudoers`. Example:
102
+
103
+ ```
104
+ deploy@server:~/sample_app/current$ procsd config sudoers
105
+
106
+ deploy ALL=NOPASSWD: /bin/systemctl start sample_app.target, /bin/systemctl stop sample_app.target, /bin/systemctl restart sample_app.target
107
+ ```
108
+
109
+ 2. Copy sudoers rule from above to the sudoers file (just type `$ sudo visudo` and paste line at the bottom then save and exit). Logout from the server.
110
+
111
+ Now try to call restart task `$ bundle exec cap production procsd:restart`. If all is fine, task will execute without password prompt.
112
+
113
+
114
+ **Also, steps above can be done automatically:**
115
+
116
+ ```ruby
117
+ # config/deploy.rb
118
+
119
+ # pass `--add-to-sudoers` option to the `procsd create` command:
120
+ set :procsd_sudoers_at_create_or_restart, true
121
+ ```
122
+
123
+ Now sudoers rule will be added at the first deploy automatically.
124
+
125
+ ## Examples
126
+
127
+ * `bundle exec cap production procsd:logs[-t]` - Tail application logs
128
+ * `bundle exec cap production procsd:run[bash]` - `ssh` into app server, `cd` into app directory and leave the bash session open
129
+
130
+ ## License
131
+
132
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "capistrano-procsd"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["Victor Afanasev"]
9
+ spec.email = ["vicfreefly@gmail.com"]
10
+
11
+ spec.summary = "Capistrano integration for Procsd"
12
+ spec.description = "Capistrano integration for Procsd"
13
+ spec.homepage = "https://github.com/vifreefly/capistrano-procsd"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "capistrano", "~> 3.1"
24
+ spec.add_dependency "sshkit-sudo", "~> 0.1"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path("../tasks/procsd.rake", __FILE__)
@@ -0,0 +1,126 @@
1
+ require 'sshkit/sudo'
2
+
3
+ namespace :procsd do
4
+ desc "Create or restart (if already created) app services"
5
+ task :create_or_restart do
6
+ on roles(:all) do
7
+ within "#{deploy_to}/current" do
8
+ cmd = %i(procsd create --or-restart)
9
+ cmd << :'--add-to-sudoers' if fetch(:procsd_sudoers_at_create_or_restart)
10
+
11
+ execute! *cmd
12
+ end
13
+ end
14
+ end
15
+
16
+ desc "Create app services"
17
+ task :create, :arguments do |t, args|
18
+ arguments = args[:arguments]
19
+
20
+ on roles(:all) do
21
+ within "#{deploy_to}/current" do
22
+ execute! :procsd, :create, arguments
23
+ end
24
+ end
25
+ end
26
+
27
+ desc "Destroy app services"
28
+ task :destroy do
29
+ on roles(:all) do
30
+ within release_path do
31
+ execute! :procsd, :destroy
32
+ end
33
+ end
34
+ end
35
+
36
+ ###
37
+
38
+ desc "Start app services"
39
+ task :start do
40
+ on roles(:all) do
41
+ within release_path do
42
+ execute! :procsd, :start
43
+ end
44
+ end
45
+ end
46
+
47
+ desc "Stop app services"
48
+ task :stop do
49
+ on roles(:all) do
50
+ within release_path do
51
+ execute! :procsd, :stop
52
+ end
53
+ end
54
+ end
55
+
56
+ desc "Restart app services"
57
+ task :restart do
58
+ on roles(:all) do
59
+ within release_path do
60
+ execute! :procsd, :restart
61
+ end
62
+ end
63
+ end
64
+
65
+ ###
66
+
67
+ desc "Check status of app services"
68
+ task :status, :arguments do |t, args|
69
+ arguments = args[:arguments]
70
+
71
+ on roles(:all) do
72
+ ssh_exec cmd_with_env("procsd status #{arguments}")
73
+ end
74
+ end
75
+
76
+ desc "Check app services logs"
77
+ task :logs, :arguments do |t, args|
78
+ arguments = args[:arguments]
79
+
80
+ on roles(:all) do
81
+ ssh_exec cmd_with_env("procsd logs #{arguments}")
82
+ end
83
+ end
84
+
85
+ desc "List all services"
86
+ task :list do
87
+ on roles(:all) do
88
+ ssh_exec cmd_with_env("procsd list")
89
+ end
90
+ end
91
+
92
+ ###
93
+
94
+ desc "Run command on a remote server"
95
+ task :run, :cmd do |t, args|
96
+ cmd = args[:cmd]
97
+ raise "Please provide a command to run" if cmd.nil? || cmd.empty?
98
+
99
+ on roles(:all) do
100
+ ssh_exec cmd_with_env(cmd)
101
+ end
102
+ end
103
+
104
+ ###
105
+
106
+ private def cmd_with_env(cmd)
107
+ cmd = cmd.split(" ", 2)
108
+ cmd[0] = cmd[0].to_sym
109
+ command(cmd, {}).to_s
110
+ end
111
+
112
+ private def ssh_exec(command)
113
+ full_command = %W(ssh #{host.user}@#{host.hostname} -t)
114
+
115
+ ssh_options = fetch(:ssh_options, {})
116
+ ssh_options[:keys]&.each { |key_path| full_command.push("-i", key_path) }
117
+ full_command.push("-A") unless ssh_options[:forward_agent] == false
118
+ full_command.push("-p", ssh_options[:port]) if ssh_options[:port]
119
+
120
+ command = "'cd #{release_path} && #{command}'"
121
+ full_command << command
122
+
123
+ puts "Executing: `#{full_command.join(' ')}`\n\n"
124
+ exec full_command.join(" ")
125
+ end
126
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-procsd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Victor Afanasev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sshkit-sudo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description: Capistrano integration for Procsd
84
+ email:
85
+ - vicfreefly@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - capistrano-procsd.gemspec
96
+ - lib/capistrano/procsd.rb
97
+ - lib/capistrano/tasks/procsd.rake
98
+ homepage: https://github.com/vifreefly/capistrano-procsd
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.7.6
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Capistrano integration for Procsd
122
+ test_files: []