capistrano-good-job 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: 4140969a15fda699411657c78955e661173a0d33099a76b1988a9cbba15a6f98
4
+ data.tar.gz: fd406a8d7b63a97979c643e3d04f66ccd5e55a7f969b45b600ddfc4c29d07cbe
5
+ SHA512:
6
+ metadata.gz: a6a0893e9a5b7930be5a6f00415ea30e3c3fab0aea1a7ed1a5382c4f87211c9b8de6faad8c91deec8338a38a55f684d440952db96f44d38cdfdffd2452182bcb
7
+ data.tar.gz: a365b5627fb50f3fddbcba2637e52908fb422f6652bfc64a3136d7f8f76ec3503168d520246204e818013b3430dc73430492d95e5c8db70ebc52c723db1605ff
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-02-18
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in capistrano_good_job.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "standard", "~> 1.3"
11
+
12
+ gem "solargraph"
data/Gemfile.lock ADDED
@@ -0,0 +1,102 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano-good-job (0.1.0)
5
+ capistrano (>= 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ airbrussh (1.4.1)
11
+ sshkit (>= 1.6.1, != 1.7.0)
12
+ ast (2.4.2)
13
+ backport (1.2.0)
14
+ benchmark (0.2.1)
15
+ capistrano (3.17.1)
16
+ airbrussh (>= 1.0.0)
17
+ i18n
18
+ rake (>= 10.0.0)
19
+ sshkit (>= 1.9.0)
20
+ concurrent-ruby (1.2.0)
21
+ diff-lcs (1.5.0)
22
+ e2mmap (0.1.0)
23
+ i18n (1.12.0)
24
+ concurrent-ruby (~> 1.0)
25
+ jaro_winkler (1.5.4)
26
+ json (2.6.3)
27
+ kramdown (2.4.0)
28
+ rexml
29
+ kramdown-parser-gfm (1.1.0)
30
+ kramdown (~> 2.0)
31
+ language_server-protocol (3.17.0.3)
32
+ net-scp (4.0.0)
33
+ net-ssh (>= 2.6.5, < 8.0.0)
34
+ net-ssh (7.0.1)
35
+ nokogiri (1.14.2-arm64-darwin)
36
+ racc (~> 1.4)
37
+ parallel (1.22.1)
38
+ parser (3.2.1.0)
39
+ ast (~> 2.4.1)
40
+ racc (1.6.2)
41
+ rainbow (3.1.1)
42
+ rake (13.0.6)
43
+ regexp_parser (2.7.0)
44
+ reverse_markdown (2.1.1)
45
+ nokogiri
46
+ rexml (3.2.5)
47
+ rubocop (1.44.1)
48
+ json (~> 2.3)
49
+ parallel (~> 1.10)
50
+ parser (>= 3.2.0.0)
51
+ rainbow (>= 2.2.2, < 4.0)
52
+ regexp_parser (>= 1.8, < 3.0)
53
+ rexml (>= 3.2.5, < 4.0)
54
+ rubocop-ast (>= 1.24.1, < 2.0)
55
+ ruby-progressbar (~> 1.7)
56
+ unicode-display_width (>= 2.4.0, < 3.0)
57
+ rubocop-ast (1.26.0)
58
+ parser (>= 3.2.1.0)
59
+ rubocop-performance (1.15.2)
60
+ rubocop (>= 1.7.0, < 2.0)
61
+ rubocop-ast (>= 0.4.0)
62
+ ruby-progressbar (1.11.0)
63
+ solargraph (0.48.0)
64
+ backport (~> 1.2)
65
+ benchmark
66
+ bundler (>= 1.17.2)
67
+ diff-lcs (~> 1.4)
68
+ e2mmap
69
+ jaro_winkler (~> 1.5)
70
+ kramdown (~> 2.3)
71
+ kramdown-parser-gfm (~> 1.1)
72
+ parser (~> 3.0)
73
+ reverse_markdown (>= 1.0.5, < 3)
74
+ rubocop (>= 0.52)
75
+ thor (~> 1.0)
76
+ tilt (~> 2.0)
77
+ yard (~> 0.9, >= 0.9.24)
78
+ sshkit (1.21.3)
79
+ net-scp (>= 1.1.2)
80
+ net-ssh (>= 2.8.0)
81
+ standard (1.24.3)
82
+ language_server-protocol (~> 3.17.0.2)
83
+ rubocop (= 1.44.1)
84
+ rubocop-performance (= 1.15.2)
85
+ thor (1.2.1)
86
+ tilt (2.0.11)
87
+ unicode-display_width (2.4.2)
88
+ webrick (1.7.0)
89
+ yard (0.9.28)
90
+ webrick (~> 1.7.0)
91
+
92
+ PLATFORMS
93
+ arm64-darwin-22
94
+
95
+ DEPENDENCIES
96
+ capistrano-good-job!
97
+ rake (~> 13.0)
98
+ solargraph
99
+ standard (~> 1.3)
100
+
101
+ BUNDLED WITH
102
+ 2.4.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Martin Tomov
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,93 @@
1
+ # Capistrano Systemd integration for GoodJob
2
+
3
+ Adds the following capistrano commands:
4
+
5
+ ```sh
6
+ good_job:disable # Disable good_job systemd service
7
+ good_job:enable # Enable good_job systemd service
8
+ good_job:install # Install good_job systemd service
9
+ good_job:reload # Reload good_job service via systemd
10
+ good_job:restart # Restart good_job service via systemd
11
+ good_job:start # Start good_job service via systemd
12
+ good_job:status # Get good_job service status via systemd
13
+ good_job:stop # Stop good_job service via systemd
14
+ good_job:uninstall # Uninstall good_job systemd service
15
+ ```
16
+
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ group :development do
24
+ gem 'capistrano-good-job', github: "mtomov/capistrano-good-job", require: false
25
+ end
26
+ ```
27
+
28
+ And then execute:
29
+
30
+ $ bundle
31
+
32
+ ```ruby
33
+ # Capfile
34
+
35
+ require 'capistrano/good_job'
36
+ install_plugin Capistrano::GoodJob
37
+ ```
38
+
39
+ To prevent loading [the hooks](lib/capistrano-good-job.rb) of the plugin, add false to the load_hooks param.
40
+ ```ruby
41
+ # Capfile
42
+
43
+ install_plugin Capistrano::GoodJob, load_hooks: false
44
+ ```
45
+
46
+ Then run once
47
+
48
+ ```sh
49
+ bundle exec cap production good_job:install
50
+ ```
51
+
52
+ for the initial setup. This will copy a [`systemd` service definition](lib/capistrano/templates/good_job.service.erb) to `~/.config/systemd/user/symantiq_good_job.service` on your server marked with Capistrano role `db`.
53
+
54
+ It will also `enable` it in `systemd`, allowing to to then run commands such as:
55
+
56
+ ```sh
57
+ systemctl --user status your_app_good_job_production
58
+ systemctl --user start your_app_good_job_production
59
+ systemctl --user stop your_app_good_job_production
60
+ systemctl --user reload your_app_good_job_production
61
+ systemctl --user restart your_app_good_job_production
62
+ ```
63
+
64
+ through their Capistrano counterparts, ex: `bundle exec cap good_job:restart`.
65
+
66
+ ## Usage
67
+
68
+ The plugin has registered a Capistrano `hook` to run `bundle exec cap good_job:restart` after deploy:
69
+
70
+ ```ruby
71
+ after "deploy:finished", "good_job:restart"
72
+ ```
73
+
74
+ See [`#register_hooks`](lib/capistrano/good_job.rb:17)
75
+
76
+
77
+ ## Development
78
+
79
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
80
+
81
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
82
+
83
+ ## Contributing
84
+
85
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mtomov/capistrano_good_job.
86
+
87
+ ## License
88
+
89
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
90
+
91
+ ## Credits
92
+
93
+ The structure and code of the gem are heavily inspired by [`capistrano-puma`](https://github.com/seuros/capistrano-puma)'s [`systemd` tasks](https://github.com/seuros/capistrano-puma/blob/master/lib/capistrano/tasks/systemd.rake)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "standard/rake"
5
+
6
+ task default: :standard
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CapistranoGoodJob
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,26 @@
1
+ module Capistrano
2
+ class GoodJob < Capistrano::Plugin
3
+ include PumaCommon
4
+
5
+ def set_defaults
6
+ set_if_empty :good_job_role, "db"
7
+ set_if_empty :good_job_access_log, -> { File.join(shared_path, "log", "good_job.log") }
8
+ set_if_empty :good_job_error_log, -> { File.join(shared_path, "log", "good_job.log") }
9
+ set_if_empty :good_job_service_unit_name, -> { "#{fetch(:application)}_good_job_#{fetch(:stage)}" }
10
+ set_if_empty :good_job_systemd_conf_dir, -> { File.join("/home/#{fetch(:user)}", ".config", "systemd", "user") }
11
+ end
12
+
13
+ def define_tasks
14
+ eval_rakefile File.expand_path("../tasks/good_job.rake", __FILE__)
15
+ end
16
+
17
+ def register_hooks
18
+ after "deploy:finished", "good_job:restart"
19
+ end
20
+
21
+ def execute_systemd(*args)
22
+ command = ["/bin/systemctl", "--user"] + args
23
+ backend.execute(*command)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ plugin = self
4
+
5
+ namespace :good_job do
6
+ desc "Install good_job systemd service"
7
+ task :install do
8
+ on roles(fetch(:good_job_role)) do |role|
9
+ execute :mkdir, "-p", fetch(:systemd_conf_dir)
10
+
11
+ service_file = File.expand_path("../../templates/good_job.service.erb", __FILE__)
12
+ erb = File.read(service_file)
13
+ file = StringIO.new(ERB.new(erb, trim_mode: "-").result(binding))
14
+
15
+ systemd_path = fetch(:good_job_systemd_conf_dir)
16
+ path = "#{systemd_path}/#{fetch(:good_job_service_unit_name)}.service"
17
+
18
+ execute :mkdir, "-p", systemd_path
19
+ upload! file, path
20
+
21
+ # Reload systemd
22
+ plugin.execute_systemd("daemon-reload")
23
+ invoke "good_job:enable"
24
+ end
25
+ end
26
+
27
+ desc "Uninstall good_job systemd service"
28
+ task :uninstall do
29
+ invoke "good_job:disable"
30
+ on roles(fetch(:good_job_role)) do |role|
31
+ systemd_path = fetch(:good_job_systemd_conf_dir)
32
+ execute :rm, "-f", "#{systemd_path}/#{fetch(:good_job_service_unit_name)}*"
33
+
34
+ plugin.execute_systemd("daemon-reload")
35
+ end
36
+ end
37
+
38
+ desc "Enable good_job systemd service"
39
+ task :enable do
40
+ on roles(fetch(:good_job_role)) do
41
+ plugin.execute_systemd("enable", fetch(:good_job_service_unit_name))
42
+ end
43
+ end
44
+
45
+ desc "Disable good_job systemd service"
46
+ task :disable do
47
+ on roles(fetch(:good_job_role)) do
48
+ plugin.execute_systemd("disable", fetch(:good_job_service_unit_name))
49
+ end
50
+ end
51
+
52
+ desc "Start good_job service via systemd"
53
+ task :start do
54
+ on roles(fetch(:good_job_role)) do
55
+ plugin.execute_systemd("start", fetch(:good_job_service_unit_name))
56
+ end
57
+ end
58
+
59
+ desc "Stop good_job service via systemd"
60
+ task :stop do
61
+ on roles(fetch(:good_job_role)) do
62
+ plugin.execute_systemd("stop", fetch(:good_job_service_unit_name))
63
+ end
64
+ end
65
+
66
+ desc "Restart good_job service via systemd"
67
+ task :restart do
68
+ on roles(fetch(:good_job_role)) do
69
+ plugin.execute_systemd("restart", fetch(:good_job_service_unit_name))
70
+ end
71
+ end
72
+
73
+ desc "Reload good_job service via systemd"
74
+ task :reload do
75
+ on roles(fetch(:good_job_role)) do
76
+ plugin.execute_systemd("reload", fetch(:good_job_service_unit_name))
77
+ end
78
+ end
79
+
80
+ desc "Get good_job service status via systemd"
81
+ task :status do
82
+ on roles(fetch(:good_job_role)) do
83
+ plugin.execute_systemd("status", fetch(:good_job_service_unit_name))
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,26 @@
1
+ [Unit]
2
+ Description=GoodJob background job
3
+ After=network.target
4
+
5
+ [Service]
6
+ Type=simple
7
+
8
+ WorkingDirectory=<%= current_path %>
9
+ ExecStart=<%= capture(:echo, SSHKit.config.command_map[:bundle]).strip %> exec good_job start
10
+
11
+ Environment='RAILS_ENV=production'
12
+
13
+ ExecReload=/bin/kill -s USR2 $MAINPID
14
+ ExecStop=/bin/kill -s TERM $MAINPID
15
+
16
+ # if we crash, restart
17
+ RestartSec=1
18
+ Restart=on-failure
19
+
20
+ <%="StandardOutput=append:#{fetch(:good_job_access_log)}" if fetch(:good_job_access_log) %>
21
+ <%="StandardError=append:#{fetch(:good_job_error_log)}" if fetch(:good_job_error_log) %>
22
+
23
+ SyslogIdentifier=<%= fetch(:good_job_service_unit_name) %>
24
+
25
+ [Install]
26
+ WantedBy=default.target
File without changes
@@ -0,0 +1,4 @@
1
+ module CapistranoGoodJob
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-good-job
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Tomov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-02-20 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.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ description: Adds support for GoodJob to Capistrano 3.x
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".standard.yml"
34
+ - CHANGELOG.md
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - lib/capistrano-good-job.rb
41
+ - lib/capistrano/good_job.rb
42
+ - lib/capistrano/good_job/version.rb
43
+ - lib/capistrano/tasks/good_job.rake
44
+ - lib/capistrano/templates/good_job.service.erb
45
+ - sig/capistrano_good_job.rbs
46
+ homepage: https://github.com/mtomov/capistrano-good-job
47
+ licenses:
48
+ - MIT
49
+ metadata:
50
+ homepage_uri: https://github.com/mtomov/capistrano-good-job
51
+ source_code_uri: https://github.com/mtomov/capistrano-good-job
52
+ changelog_uri: https://github.com/mtomov/capistrano-good-job/releases
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.6.0
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.4.6
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Adds support for GoodJob to Capistrano 3.x
72
+ test_files: []