tomo-plugin-solid_queue 0.0.1
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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +150 -0
- data/lib/tomo/plugin/solid_queue/service.erb +22 -0
- data/lib/tomo/plugin/solid_queue/tasks.rb +48 -0
- data/lib/tomo/plugin/solid_queue/version.rb +8 -0
- data/lib/tomo/plugin/solid_queue.rb +12 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6b0eeb3e1010b46eee073015145bd0747241d144020259d8a3e83f3be4aa14ab
|
4
|
+
data.tar.gz: 1b91d02b927bccbdabbfeb2db9c229532d9af8f835474251d590de24d1687bc3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 96606c598123dd2a12842f56cc47c34d51b2588d528cc969ab2b620e9a30d57435e8c88a2d9afe11bf274c8bb85d1b8c806c197af2faea00b869ab2da8916585
|
7
|
+
data.tar.gz: 47c56b96b4a9357c7b31bd8baadddab145903de2bed1d112cb6501635ecd399c71b8d02b6166deeefe26e635b0dc7bed63b6fbc475994b60cfd2ab949203ede0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 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,150 @@
|
|
1
|
+
# tomo-plugin-solid_queue
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/tomo-plugin-solid_queue)
|
4
|
+
[](https://www.ruby-toolbox.com/projects/tomo-plugin-solid_queue)
|
5
|
+
[](https://github.com/uxxman/tomo-plugin-solid_queue/actions/workflows/ci.yml)
|
6
|
+
[](https://codeclimate.com/github/uxxman/tomo-plugin-solid_queue)
|
7
|
+
|
8
|
+
This is a [tomo](https://github.com/mattbrictson/tomo) plugin that provides tasks for managing [solid_queue](https://github.com/rails/solid_queue) via [systemd](https://en.wikipedia.org/wiki/Systemd), based on the recommendations in the solid_queue 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.
|
9
|
+
|
10
|
+
**This plugin requires solid_queue 0.6.0 or newer.**
|
11
|
+
|
12
|
+
---
|
13
|
+
|
14
|
+
- [Installation](#installation)
|
15
|
+
- [Settings](#settings)
|
16
|
+
- [Tasks](#tasks)
|
17
|
+
- [Recommendations](#recommendations)
|
18
|
+
- [Support](#support)
|
19
|
+
- [License](#license)
|
20
|
+
- [Code of conduct](#code-of-conduct)
|
21
|
+
- [Contribution guide](#contribution-guide)
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
Run:
|
26
|
+
|
27
|
+
```
|
28
|
+
$ gem install tomo-plugin-solid_queue
|
29
|
+
```
|
30
|
+
|
31
|
+
Or add it to your Gemfile:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
gem "tomo-plugin-solid_queue"
|
35
|
+
```
|
36
|
+
|
37
|
+
Then add the following to `.tomo/config.rb`:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
plugin "solid_queue"
|
41
|
+
|
42
|
+
setup do
|
43
|
+
# ...
|
44
|
+
run "solid_queue:setup_systemd"
|
45
|
+
end
|
46
|
+
|
47
|
+
deploy do
|
48
|
+
# ...
|
49
|
+
# Place this task at *after* core:symlink_current
|
50
|
+
run "solid_queue:restart"
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
### enable-linger
|
55
|
+
|
56
|
+
This plugin installs solid_queue as a user-level service using `systemctl --user`. This allows solid_queue 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 solid_queue process to continue running even after the tomo deploy user disconnects:
|
57
|
+
|
58
|
+
```
|
59
|
+
# run as root
|
60
|
+
$ loginctl enable-linger <DEPLOY_USER>
|
61
|
+
```
|
62
|
+
|
63
|
+
## Settings
|
64
|
+
|
65
|
+
| Name | Purpose |
|
66
|
+
| --------------------- | ------- |
|
67
|
+
| `solid_queue_systemd_service` | Name of the systemd unit that will be used to manage solid_queue <br>**Default:** `"solid_queue_%{application}.service"` |
|
68
|
+
| `solid_queue_systemd_service_path` | Location where the systemd unit will be installed <br>**Default:** `".config/systemd/user/%{solid_queue_systemd_service}"` |
|
69
|
+
| `solid_queue_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/uxxman/tomo-plugin-solid_queue/blob/main/lib/tomo/plugin/solid_queue/service.erb) |
|
70
|
+
|
71
|
+
## Tasks
|
72
|
+
|
73
|
+
### solid_queue:setup_systemd
|
74
|
+
|
75
|
+
Configures systemd to manage solid_queue. This means that solid_queue will automatically be restarted if it crashes, or if the host is rebooted. This task essentially does two things:
|
76
|
+
|
77
|
+
1. Installs a `solid_queue.service` systemd unit
|
78
|
+
1. Enables it using `systemctl --user enable`
|
79
|
+
|
80
|
+
Note that these units will be installed and run for the deploy user. You can use `:solid_queue_systemd_service_template_path` to provide your own template and customize how solid_queue and systemd are configured.
|
81
|
+
|
82
|
+
`solid_queue:setup_systemd` is intended for use as a [setup](https://tomo.mattbrictson.com/commands/setup/) task. It must be run before solid_queue can be started during a deploy.
|
83
|
+
|
84
|
+
### solid_queue:restart
|
85
|
+
|
86
|
+
Gracefully restarts the solid_queue service via systemd, or starts it if it isn't running already. Equivalent to:
|
87
|
+
|
88
|
+
```
|
89
|
+
systemctl --user restart solid_queue.service
|
90
|
+
```
|
91
|
+
|
92
|
+
### solid_queue:start
|
93
|
+
|
94
|
+
Starts the solid_queue service via systemd, if it isn't running already. Equivalent to:
|
95
|
+
|
96
|
+
```
|
97
|
+
systemctl --user start solid_queue.service
|
98
|
+
```
|
99
|
+
|
100
|
+
### solid_queue:stop
|
101
|
+
|
102
|
+
Stops the solid_queue service via systemd. Equivalent to:
|
103
|
+
|
104
|
+
```
|
105
|
+
systemctl --user stop solid_queue.service
|
106
|
+
```
|
107
|
+
|
108
|
+
### solid_queue:status
|
109
|
+
|
110
|
+
Prints the status of the solid_queue systemd service. Equivalent to:
|
111
|
+
|
112
|
+
```
|
113
|
+
systemctl --user status solid_queue.service
|
114
|
+
```
|
115
|
+
|
116
|
+
### solid_queue:log
|
117
|
+
|
118
|
+
Uses `journalctl` (part of systemd) to view the log output of the solid_queue service. This task is intended for use as a [run](https://tomo.mattbrictson.com/commands/run/) task and accepts command-line arguments. The arguments are passed through to the `journalctl` command. For example:
|
119
|
+
|
120
|
+
```
|
121
|
+
$ tomo run -- solid_queue:log -f
|
122
|
+
```
|
123
|
+
|
124
|
+
Will run this remote script:
|
125
|
+
|
126
|
+
```
|
127
|
+
journalctl -q --user-unit=solid_queue.service -f
|
128
|
+
```
|
129
|
+
|
130
|
+
## Recommendations
|
131
|
+
|
132
|
+
### solid_queue configuration
|
133
|
+
|
134
|
+
Add a `config/solid_queue.yml` file to your application (i.e. checked into git) and use that to configure solid_queue, using environment variables as necessary. For examples see https://github.com/rails/solid_queue?tab=readme-ov-file#configuration.
|
135
|
+
|
136
|
+
## Support
|
137
|
+
|
138
|
+
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/uxxman/tomo-plugin-solid_queue/issues/new) and I will do my best to provide a helpful answer. Happy hacking!
|
139
|
+
|
140
|
+
## License
|
141
|
+
|
142
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|
143
|
+
|
144
|
+
## Code of conduct
|
145
|
+
|
146
|
+
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).
|
147
|
+
|
148
|
+
## Contribution guide
|
149
|
+
|
150
|
+
Pull requests are welcome!
|
@@ -0,0 +1,22 @@
|
|
1
|
+
[Unit]
|
2
|
+
Description=Solid Queue for <%= settings[:application] %>
|
3
|
+
After=syslog.target network.target
|
4
|
+
ConditionPathExists=<%= paths.current %>
|
5
|
+
|
6
|
+
[Service]
|
7
|
+
ExecStart=/bin/bash -lc 'exec bundle exec rake solid_queue:start'
|
8
|
+
Restart=always
|
9
|
+
RestartSec=1
|
10
|
+
StandardError=syslog
|
11
|
+
StandardOutput=syslog
|
12
|
+
SyslogIdentifier=%n
|
13
|
+
Type=notify
|
14
|
+
WatchdogSec=10
|
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::SolidQueue
|
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[:solid_queue_systemd_service],
|
30
|
+
paths.solid_queue_systemd_service_template,
|
31
|
+
paths.solid_queue_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
|
+
solid_queue 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,12 @@
|
|
1
|
+
require "tomo"
|
2
|
+
require_relative "solid_queue/tasks"
|
3
|
+
require_relative "solid_queue/version"
|
4
|
+
|
5
|
+
module Tomo::Plugin::SolidQueue
|
6
|
+
extend Tomo::PluginDSL
|
7
|
+
|
8
|
+
tasks Tomo::Plugin::SolidQueue::Tasks
|
9
|
+
defaults solid_queue_systemd_service: "solid_queue_%{application}.service",
|
10
|
+
solid_queue_systemd_service_path: ".config/systemd/user/%{solid_queue_systemd_service}",
|
11
|
+
solid_queue_systemd_service_template_path: File.expand_path("solid_queue/service.erb", __dir__)
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tomo-plugin-solid_queue
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Muhammad Usman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-08-22 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
|
+
- uxman.sherwani@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE.txt
|
35
|
+
- README.md
|
36
|
+
- lib/tomo/plugin/solid_queue.rb
|
37
|
+
- lib/tomo/plugin/solid_queue/service.erb
|
38
|
+
- lib/tomo/plugin/solid_queue/tasks.rb
|
39
|
+
- lib/tomo/plugin/solid_queue/version.rb
|
40
|
+
homepage: https://github.com/uxxman/tomo-plugin-solid_queue
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata:
|
44
|
+
bug_tracker_uri: https://github.com/uxxman/tomo-plugin-solid_queue/issues
|
45
|
+
changelog_uri: https://github.com/uxxman/tomo-plugin-solid_queue/releases
|
46
|
+
source_code_uri: https://github.com/uxxman/tomo-plugin-solid_queue
|
47
|
+
homepage_uri: https://github.com/uxxman/tomo-plugin-solid_queue
|
48
|
+
rubygems_mfa_required: 'true'
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '3.1'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubygems_version: 3.5.11
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Solid Queue deployment tasks for tomo
|
68
|
+
test_files: []
|