tomo-plugin-good_job 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e06b8143748c4cbac1f8fd4bcb9c1377ba4f8c0c4b2128f0e4f4c1c87cd69edb
4
+ data.tar.gz: 8f8738057daf529320d0642cc23422f19779122d24122ae1cf5fc509ddf35537
5
+ SHA512:
6
+ metadata.gz: 3ebca4f89c2f2b70424a7b7e93df468bea3ca000e4521e060a1d8ebff9927501bdf6d913dfa10a0b64af9387990cf1befe26dded235940c7e3e273cd59cd7039
7
+ data.tar.gz: 15a2a7f681a34b5034397970a43095278c89043ac9fda2f62269ab6cbb724b91b58455be290bc0eebb92b6ebdca5fa14134f16b1d06b95ea6af90055aa329db9
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Matt Brictson
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,140 @@
1
+ # tomo-plugin-good_job
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/tomo-plugin-good_job.svg)](https://rubygems.org/gems/tomo-plugin-good_job)
4
+ [![Circle](https://circleci.com/gh/gauravtiwari/tomo-plugin-good_job/tree/main.svg?style=shield)](https://app.circleci.com/pipelines/github/gauravtiwari/tomo-plugin-good_job?branch=main)
5
+ [![Code Climate](https://codeclimate.com/github/gauravtiwari/tomo-plugin-good_job/badges/gpa.svg)](https://codeclimate.com/github/gauravtiwari/tomo-plugin-good_job)
6
+
7
+ This is a [tomo](https://github.com/mattbrictson/tomo) plugin that provides tasks for managing [good_job](https://github.com/bensheldon/good_job) via [systemd](https://en.wikipedia.org/wiki/Systemd), based on the recommendations in the good_job documentation. This plugin assumes that you are also using the tomo `rbenv` and `env` plugins, and that you are using a systemd-based Linux distribution like Ubuntu 18 LTS.
8
+
9
+ ---
10
+
11
+ - [Installation](#installation)
12
+ - [Settings](#settings)
13
+ - [Tasks](#tasks)
14
+ - [Support](#support)
15
+ - [License](#license)
16
+ - [Code of conduct](#code-of-conduct)
17
+ - [Contribution guide](#contribution-guide)
18
+
19
+ ## Installation
20
+
21
+ Run:
22
+
23
+ ```
24
+ $ gem install tomo-plugin-good_job
25
+ ```
26
+
27
+ Or add it to your Gemfile:
28
+
29
+ ```ruby
30
+ gem "tomo-plugin-good_job"
31
+ ```
32
+
33
+ Then add the following to `.tomo/config.rb`:
34
+
35
+ ```ruby
36
+ plugin "good_job"
37
+
38
+ setup do
39
+ # ...
40
+ run "good_job:setup_systemd"
41
+ end
42
+
43
+ deploy do
44
+ # ...
45
+ # Place this task at *after* core:symlink_current
46
+ run "good_job:restart"
47
+ end
48
+ ```
49
+
50
+ ### enable-linger
51
+
52
+ This plugin installs good_job as a user-level service using systemctl --user. This allows good_job to be installed, started, stopped, and restarted without a root user or sudo. However, when provisioning the host you must make sure to run the following command as root to allow the good_job process to continue running even after the tomo deploy user disconnects:
53
+
54
+ ```
55
+ # run as root
56
+ $ loginctl enable-linger <DEPLOY_USER>
57
+ ```
58
+
59
+ ## Settings
60
+
61
+ | Name | Purpose |
62
+ | ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
63
+ | `good_job_systemd_service` | Name of the systemd unit that will be used to manage good*job <br>**Default:** `"good_job*%{application}.service"` |
64
+ | `good_job_systemd_service_path` | Location where the systemd unit will be installed <br>**Default:** `".config/systemd/user/%{good_job_systemd_service}"` |
65
+ | `good_job_systemd_service_template_path` | Local path to the ERB template that will be used to create the systemd unit <br>**Default:** [service.erb](https://github.com/gauravtiwari/tomo-plugin-good_job/blob/main/lib/tomo/plugin/good_job/service.erb) |
66
+
67
+ ## Tasks
68
+
69
+ ### good_job:setup_systemd
70
+
71
+ Configures systemd to manage good_job. This means that good_job will automatically be restarted if it crashes, or if the host is rebooted. This task essentially does two things:
72
+
73
+ 1. Installs a `good_job.service` systemd unit
74
+ 1. Enables it using `systemctl --user enable`
75
+
76
+ Note that these units will be installed and run for the deploy user. You can use `:good_job_systemd_service_template_path` to provide your own template and customize how good_job and systemd are configured.
77
+
78
+ `good_job:setup_systemd` is intended for use as a [setup](https://tomo-deploy.com/commands/setup/) task. It must be run before good_job can be started during a deploy.
79
+
80
+ ### good_job:restart
81
+
82
+ Gracefully restarts the good_job service via systemd, or starts it if it isn't running already. Equivalent to:
83
+
84
+ ```
85
+ systemctl --user restart good_job.service
86
+ ```
87
+
88
+ ### good_job:start
89
+
90
+ Starts the good_job service via systemd, if it isn't running already. Equivalent to:
91
+
92
+ ```
93
+ systemctl --user start good_job.service
94
+ ```
95
+
96
+ ### good_job:stop
97
+
98
+ Stops the good_job service via systemd. Equivalent to:
99
+
100
+ ```
101
+ systemctl --user stop good_job.service
102
+ ```
103
+
104
+ ### good_job:status
105
+
106
+ Prints the status of the good_job systemd service. Equivalent to:
107
+
108
+ ```
109
+ systemctl --user status good_job.service
110
+ ```
111
+
112
+ ### good_job:log
113
+
114
+ Uses `journalctl` (part of systemd) to view the log output of the good_job service. This task is intended for use as a [run](https://tomo-deploy.com/commands/run/) task and accepts command-line arguments. The arguments are passed through to the `journalctl` command. For example:
115
+
116
+ ```
117
+ $ tomo run -- good_job:log -f
118
+ ```
119
+
120
+ Will run this remote script:
121
+
122
+ ```
123
+ journalctl -q --user-unit=good_job.service -f
124
+ ```
125
+
126
+ ## Support
127
+
128
+ If you want to report a bug, or have ideas, feedback or questions about the gem, [let me know via GitHub issues](https://github.com/gauravtiwari/tomo-plugin-good_job/issues/new) and I will do my best to provide a helpful answer. Happy hacking!
129
+
130
+ ## License
131
+
132
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
133
+
134
+ ## Code of conduct
135
+
136
+ Everyone interacting in this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
137
+
138
+ ## Contribution guide
139
+
140
+ Pull requests are welcome! Thanks @mattbrictson for Tomo 🙏
@@ -0,0 +1,22 @@
1
+ [Unit]
2
+ Description=GoodJob for <%= settings[:application] %>
3
+ After=syslog.target network.target
4
+ ConditionPathExists=<%= paths.current %>
5
+
6
+ [Service]
7
+ ExecReload=/usr/bin/kill -TSTP $MAINPID
8
+ ExecStart=/bin/bash -lc 'exec bundle exec good_job start'
9
+ Restart=on-failure
10
+ RestartSec=1
11
+ StandardError=syslog
12
+ StandardOutput=syslog
13
+ SyslogIdentifier=%n
14
+ Type=simple
15
+ WorkingDirectory=<%= paths.current %>
16
+
17
+ # Greatly reduce Ruby memory fragmentation and heap usage
18
+ # https://www.mikeperham.com/2018/04/25/taming-rails-memory-bloat/
19
+ Environment=MALLOC_ARENA_MAX=2
20
+
21
+ [Install]
22
+ WantedBy=default.target
@@ -0,0 +1,48 @@
1
+ module Tomo::Plugin::GoodJob
2
+ class Tasks < Tomo::TaskLibrary
3
+ SystemdUnit = Struct.new(:name, :template, :path)
4
+
5
+ def setup_systemd
6
+ linger_must_be_enabled!
7
+
8
+ remote.mkdir_p service.path.dirname
9
+ remote.write template: service.template, to: service.path
10
+
11
+ remote.run "systemctl --user daemon-reload"
12
+ remote.run "systemctl", "--user", "enable", service.name
13
+ end
14
+
15
+ %i[reload restart start stop status].each do |action|
16
+ define_method(action) do
17
+ remote.run "systemctl", "--user", action, service.name
18
+ end
19
+ end
20
+
21
+ def log
22
+ remote.attach "journalctl", "-q", raw("--user-unit=#{service.name.shellescape}"), *settings[:run_args]
23
+ end
24
+
25
+ private
26
+
27
+ def service
28
+ SystemdUnit.new(
29
+ settings[:good_job_systemd_service],
30
+ paths.good_job_systemd_service_template,
31
+ paths.good_job_systemd_service
32
+ )
33
+ end
34
+
35
+ def linger_must_be_enabled!
36
+ linger_users = remote.list_files("/var/lib/systemd/linger", raise_on_error: false)
37
+ return if dry_run? || linger_users.include?(remote.host.user)
38
+
39
+ die <<~ERROR.strip
40
+ Linger must be enabled for the #{remote.host.user} user in order for
41
+ good_job to stay running in the background via systemd. Run the following
42
+ command as root:
43
+
44
+ loginctl enable-linger #{remote.host.user}
45
+ ERROR
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,8 @@
1
+ module Tomo
2
+ module Plugin
3
+ end
4
+ end
5
+
6
+ module Tomo::Plugin::GoodJob
7
+ VERSION = "1.0.0".freeze
8
+ end
@@ -0,0 +1,12 @@
1
+ require "tomo"
2
+ require_relative "good_job/tasks"
3
+ require_relative "good_job/version"
4
+
5
+ module Tomo::Plugin::GoodJob
6
+ extend Tomo::PluginDSL
7
+
8
+ tasks Tomo::Plugin::GoodJob::Tasks
9
+ defaults good_job_systemd_service: "good_job_%{application}.service",
10
+ good_job_systemd_service_path: ".config/systemd/user/%{good_job_systemd_service}",
11
+ good_job_systemd_service_template_path: File.expand_path("good_job/service.erb", __dir__)
12
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tomo-plugin-good_job
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Brictson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-04-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tomo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description:
28
+ email:
29
+ - opensource@gauravtiwari.com
30
+ - gaurav@gauravtiwari.co.uk
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE.txt
36
+ - README.md
37
+ - lib/tomo/plugin/good_job.rb
38
+ - lib/tomo/plugin/good_job/service.erb
39
+ - lib/tomo/plugin/good_job/tasks.rb
40
+ - lib/tomo/plugin/good_job/version.rb
41
+ homepage: https://github.com/gauravtiwari/tomo-plugin-good_job
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ bug_tracker_uri: https://github.com/gauravtiwari/tomo-plugin-good_job/issues
46
+ changelog_uri: https://github.com/gauravtiwari/tomo-plugin-good_job/releases
47
+ source_code_uri: https://github.com/gauravtiwari/tomo-plugin-good_job
48
+ homepage_uri: https://github.com/gauravtiwari/tomo-plugin-good_job
49
+ rubygems_mfa_required: 'true'
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 2.6.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.3.3
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: GoodJob background tasks for tomo
69
+ test_files: []