tomo-plugin-aws_sqs 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +143 -0
- data/lib/tomo/plugin/aws_sqs/service.erb +22 -0
- data/lib/tomo/plugin/aws_sqs/tasks.rb +48 -0
- data/lib/tomo/plugin/aws_sqs/version.rb +8 -0
- data/lib/tomo/plugin/aws_sqs.rb +13 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a5b782131008005080a7cc35ea61db18c311989ec26c702a3040c6ccc484ffeb
|
4
|
+
data.tar.gz: 6e00c8a1d411fe7397723c2f8155730dd75966382dff3862db24f44680658205
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7fbe9b9d6612f6df7ce13f8c79a24fc34365fd0a7522defc35a1759bd72b630a4b4187f5dd4779bb45b44ebd04e9db3933f0c5cff8ebad5b9012318b52b6f93
|
7
|
+
data.tar.gz: afa276555aefd9da584f933b249f6b375edfaac9d178307459e85adb11292506854097f094434b8ad7e3f7254c19a7804c2dcc079403effd4a67bea3c4223e54
|
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,143 @@
|
|
1
|
+
# tomo-plugin-aws_sqs
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/tomo-plugin-aws_sqs.svg)](https://rubygems.org/gems/tomo-plugin-aws_sqs)
|
4
|
+
[![Circle](https://circleci.com/gh/gauravtiwari/tomo-plugin-aws_sqs/tree/main.svg?style=shield)](https://app.circleci.com/pipelines/github/gauravtiwari/tomo-plugin-aws_sqs?branch=main)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/gauravtiwari/tomo-plugin-aws_sqs/badges/gpa.svg)](https://codeclimate.com/github/gauravtiwari/tomo-plugin-aws_sqs)
|
6
|
+
|
7
|
+
This is a [tomo](https://github.com/mattbrictson/tomo) plugin that provides tasks for managing [aws_sqs](https://github.com/bensheldon/aws_sqs) via [systemd](https://en.wikipedia.org/wiki/Systemd), based on the recommendations in the aws_sqs 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-aws_sqs
|
25
|
+
```
|
26
|
+
|
27
|
+
Or add it to your Gemfile:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
gem "tomo-plugin-aws_sqs"
|
31
|
+
```
|
32
|
+
|
33
|
+
Then add the following to `.tomo/config.rb`:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
plugin "aws_sqs"
|
37
|
+
|
38
|
+
setup do
|
39
|
+
# ...
|
40
|
+
run "aws_sqs:setup_systemd"
|
41
|
+
end
|
42
|
+
|
43
|
+
deploy do
|
44
|
+
# ...
|
45
|
+
# Place this task at *after* core:symlink_current
|
46
|
+
run "aws_sqs:restart"
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
### enable-linger
|
51
|
+
|
52
|
+
This plugin installs aws_sqs as a user-level service using systemctl --user. This allows aws_sqs 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 aws_sqs 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
|
+
| `aws_sqs_systemd_service` | Name of the systemd unit that will be used to manage good*job <br>**Default:** `"aws_sqs*%{application}.service"` |
|
64
|
+
| `aws_sqs_systemd_service_path` | Location where the systemd unit will be installed <br>**Default:** `".config/systemd/user/%{aws_sqs_systemd_service}"`
|
65
|
+
| `aws_sqs_systemd_command` | Command to run <br>**Default:** `"bundle exec aws_sqs_active_job --queue default"` |
|
66
|
+
| `aws_sqs_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-aws_sqs/blob/main/lib/tomo/plugin/aws_sqs/service.erb) |
|
67
|
+
|
68
|
+
## Tasks
|
69
|
+
|
70
|
+
### aws_sqs:setup_systemd
|
71
|
+
|
72
|
+
Configures systemd to manage aws_sqs. This means that aws_sqs will automatically be restarted if it crashes, or if the host is rebooted. This task essentially does two things:
|
73
|
+
|
74
|
+
1. Installs a `aws_sqs.service` systemd unit
|
75
|
+
1. Enables it using `systemctl --user enable`
|
76
|
+
|
77
|
+
Note that these units will be installed and run for the deploy user. You can use `:aws_sqs_systemd_service_template_path` to provide your own template and customize how aws_sqs and systemd are configured.
|
78
|
+
|
79
|
+
`aws_sqs:setup_systemd` is intended for use as a [setup](https://tomo-deploy.com/commands/setup/) task. It must be run before aws_sqs can be started during a deploy.
|
80
|
+
|
81
|
+
### aws_sqs:restart
|
82
|
+
|
83
|
+
Gracefully restarts the aws_sqs service via systemd, or starts it if it isn't running already. Equivalent to:
|
84
|
+
|
85
|
+
```
|
86
|
+
systemctl --user restart aws_sqs.service
|
87
|
+
```
|
88
|
+
|
89
|
+
### aws_sqs:start
|
90
|
+
|
91
|
+
Starts the aws_sqs service via systemd, if it isn't running already. Equivalent to:
|
92
|
+
|
93
|
+
```
|
94
|
+
systemctl --user start aws_sqs.service
|
95
|
+
```
|
96
|
+
|
97
|
+
### aws_sqs:stop
|
98
|
+
|
99
|
+
Stops the aws_sqs service via systemd. Equivalent to:
|
100
|
+
|
101
|
+
```
|
102
|
+
systemctl --user stop aws_sqs.service
|
103
|
+
```
|
104
|
+
|
105
|
+
### aws_sqs:status
|
106
|
+
|
107
|
+
Prints the status of the aws_sqs systemd service. Equivalent to:
|
108
|
+
|
109
|
+
```
|
110
|
+
systemctl --user status aws_sqs.service
|
111
|
+
```
|
112
|
+
|
113
|
+
### aws_sqs:log
|
114
|
+
|
115
|
+
Uses `journalctl` (part of systemd) to view the log output of the aws_sqs 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:
|
116
|
+
|
117
|
+
```
|
118
|
+
$ tomo run -- aws_sqs:log -f
|
119
|
+
```
|
120
|
+
|
121
|
+
Will run this remote script:
|
122
|
+
|
123
|
+
```
|
124
|
+
journalctl -q --user-unit=aws_sqs.service -f
|
125
|
+
```
|
126
|
+
|
127
|
+
## Support
|
128
|
+
|
129
|
+
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-aws_sqs/issues/new) and I will do my best to provide a helpful answer. Happy hacking!
|
130
|
+
|
131
|
+
## License
|
132
|
+
|
133
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|
134
|
+
|
135
|
+
Most of the code is taken from https://github.com/mattbrictson/tomo-plugin-sidekiq
|
136
|
+
|
137
|
+
## Code of conduct
|
138
|
+
|
139
|
+
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).
|
140
|
+
|
141
|
+
## Contribution guide
|
142
|
+
|
143
|
+
Pull requests are welcome! Thanks @mattbrictson for Tomo 🙏
|
@@ -0,0 +1,22 @@
|
|
1
|
+
[Unit]
|
2
|
+
Description=AwsSqs 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 <%= settings[:aws_sqs_systemd_command] %>'
|
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::AwsSqs
|
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[:aws_sqs_systemd_service],
|
30
|
+
paths.aws_sqs_systemd_service_template,
|
31
|
+
paths.aws_sqs_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
|
+
aws_sqs 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,13 @@
|
|
1
|
+
require "tomo"
|
2
|
+
require_relative "aws_sqs/tasks"
|
3
|
+
require_relative "aws_sqs/version"
|
4
|
+
|
5
|
+
module Tomo::Plugin::AwsSqs
|
6
|
+
extend Tomo::PluginDSL
|
7
|
+
|
8
|
+
tasks Tomo::Plugin::AwsSqs::Tasks
|
9
|
+
defaults aws_sqs_systemd_service: "aws_sqs_%{application}.service",
|
10
|
+
aws_sqs_systemd_service_path: ".config/systemd/user/%{aws_sqs_systemd_service}",
|
11
|
+
aws_sqs_systemd_service_template_path: File.expand_path("aws_sqs/service.erb", __dir__),
|
12
|
+
aws_sqs_systemd_command: "bundle exec aws_sqs_active_job --queue default"
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tomo-plugin-aws_sqs
|
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-06-14 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/aws_sqs.rb
|
38
|
+
- lib/tomo/plugin/aws_sqs/service.erb
|
39
|
+
- lib/tomo/plugin/aws_sqs/tasks.rb
|
40
|
+
- lib/tomo/plugin/aws_sqs/version.rb
|
41
|
+
homepage: https://github.com/gauravtiwari/tomo-plugin-aws_sqs
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata:
|
45
|
+
bug_tracker_uri: https://github.com/gauravtiwari/tomo-plugin-aws_sqs/issues
|
46
|
+
changelog_uri: https://github.com/gauravtiwari/tomo-plugin-aws_sqs/releases
|
47
|
+
source_code_uri: https://github.com/gauravtiwari/tomo-plugin-aws_sqs
|
48
|
+
homepage_uri: https://github.com/gauravtiwari/tomo-plugin-aws_sqs
|
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.7
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Aws::Sqs background tasks for tomo
|
69
|
+
test_files: []
|