avm-eac_rails_base1 0.1.4 → 0.2.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 +4 -4
- data/lib/avm/eac_rails_base1/runner/tasks_scheduler/systemd_unit.rb +46 -0
- data/lib/avm/eac_rails_base1/runner/tasks_scheduler.rb +17 -0
- data/lib/avm/eac_rails_base1/systemd_unit/service.rb +70 -0
- data/lib/avm/eac_rails_base1/systemd_unit/tasks_scheduler_command.rb +29 -0
- data/lib/avm/eac_rails_base1/systemd_unit.rb +57 -0
- data/lib/avm/eac_rails_base1/version.rb +1 -1
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cd8c0188de46ffd74cfc9a51b1de67af3d13119bc01f649e3be5f6930a69bd5
|
4
|
+
data.tar.gz: 17e2b42827e8b9849ff1139e60272d804c8a320c2b7b64e9ebada03bc813ec7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 687ae601d3f0ac0b3c5c30a385ff7674e563a56fa67501c6421d5e10e2c39f31563b622aafaf8543e0eeb767e1571c86f5a1b9a7d296c01b5ef2faf3b3980153
|
7
|
+
data.tar.gz: 2fc11c3e7087262191ea5474c656ddc3c10025d29104c957ad0dc2ed39a9a1197aa985548ab7f91963316a64394318e958544192fff3f8987ca3cd87e05c10fe
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/eac_rails_base1/systemd_unit'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module Avm
|
7
|
+
module EacRailsBase1
|
8
|
+
class Runner < ::Avm::EacWebappBase0::Runner
|
9
|
+
class TasksScheduler
|
10
|
+
class SystemdUnit
|
11
|
+
DEFAULT_RESTART = 'on-failure'
|
12
|
+
|
13
|
+
runner_with :help do
|
14
|
+
desc 'Configure Systemd unit for instace\'s tasks scheduler daemon (Reference: ' \
|
15
|
+
'https://www.freedesktop.org/software/systemd/man/systemd.service.html).'
|
16
|
+
bool_opt '-e', '--exec-run', 'Run daemon with "run" instead of "start"/"stop".'
|
17
|
+
arg_opt '-r', '--restart', 'Value for systemd.service, Restart=.',
|
18
|
+
default: DEFAULT_RESTART
|
19
|
+
end
|
20
|
+
|
21
|
+
delegate :restart, to: :parsed
|
22
|
+
|
23
|
+
def run
|
24
|
+
if result.error?
|
25
|
+
fatal_error result.to_s
|
26
|
+
else
|
27
|
+
infov 'Result', result.label
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def systemd_unit_uncached
|
34
|
+
::Avm::EacRailsBase1::SystemdUnit.new(runner_context.call(:instance),
|
35
|
+
restart: parsed.restart,
|
36
|
+
exec_run: parsed.exec_run?)
|
37
|
+
end
|
38
|
+
|
39
|
+
def result_uncached
|
40
|
+
systemd_unit.run
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module EacRailsBase1
|
7
|
+
class Runner < ::Avm::EacWebappBase0::Runner
|
8
|
+
class TasksScheduler
|
9
|
+
require_sub __FILE__
|
10
|
+
|
11
|
+
runner_with :help, :subcommands do
|
12
|
+
subcommands
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module EacRailsBase1
|
7
|
+
class SystemdUnit
|
8
|
+
module Service
|
9
|
+
def service_content
|
10
|
+
template.child('tasks_scheduler.service').apply(variables_source)
|
11
|
+
end
|
12
|
+
|
13
|
+
def service_exec_lines
|
14
|
+
service_exec_operations
|
15
|
+
.map { |k, v| "#{k}=#{tasks_scheduler_command_path} #{v}" }
|
16
|
+
.join("\n")
|
17
|
+
end
|
18
|
+
|
19
|
+
def service_path
|
20
|
+
::Pathname.new('/etc/systemd/system').join(unit_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def service_link_path
|
24
|
+
::Pathname.new('/etc/systemd/system/multi-user.target.wants').join(unit_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def verify_service
|
28
|
+
sudo_system!('systemd-analyze', 'verify', service_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def enable_service
|
34
|
+
systemctl('enable', unit_name)
|
35
|
+
end
|
36
|
+
|
37
|
+
def link_service
|
38
|
+
sudo_execute!('rm', '-f', service_link_path)
|
39
|
+
sudo_execute!('ln', '-s', service_path, service_link_path)
|
40
|
+
end
|
41
|
+
|
42
|
+
def reload_systemd
|
43
|
+
systemctl('daemon-reload')
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [Hash<String, String>]
|
47
|
+
def service_exec_operations
|
48
|
+
if exec_run?
|
49
|
+
{ 'ExecStart' => 'run' }
|
50
|
+
else
|
51
|
+
{ 'ExecStart' => 'start', 'ExecStop' => 'stop' }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def start_service
|
56
|
+
systemctl('start', unit_name)
|
57
|
+
end
|
58
|
+
|
59
|
+
def systemctl(*args)
|
60
|
+
sudo_system!('systemctl', *args)
|
61
|
+
end
|
62
|
+
|
63
|
+
def write_service
|
64
|
+
infom 'Writing service\'s unit file...'
|
65
|
+
platform_instance.file_sudo_write(service_path, service_content)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module Avm
|
6
|
+
module EacRailsBase1
|
7
|
+
class SystemdUnit
|
8
|
+
module TasksSchedulerCommand
|
9
|
+
def tasks_scheduler_command_content
|
10
|
+
template.child('tasks_scheduler_command.sh').apply(variables_source)
|
11
|
+
end
|
12
|
+
|
13
|
+
def tasks_scheduler_command_path
|
14
|
+
"/opt/aux/#{instance.id}/tasks_scheduler.sh"
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def write_tasks_scheduler_command
|
20
|
+
infom 'Writing tasks scheduler\'s command...'
|
21
|
+
sudo_execute!('mkdir', '-p', ::File.dirname(tasks_scheduler_command_path))
|
22
|
+
platform_instance.file_sudo_write(tasks_scheduler_command_path,
|
23
|
+
tasks_scheduler_command_content)
|
24
|
+
sudo_execute!('chmod', '+x', tasks_scheduler_command_path)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/jobs/base'
|
4
|
+
require 'avm/eac_ubuntu_base0/apache'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
|
7
|
+
module Avm
|
8
|
+
module EacRailsBase1
|
9
|
+
class SystemdUnit
|
10
|
+
JOBS = %w[write_tasks_scheduler_command write_service link_service verify_service
|
11
|
+
reload_systemd enable_service start_service].freeze
|
12
|
+
|
13
|
+
include ::Avm::Jobs::Base
|
14
|
+
require_sub __FILE__, include_modules: true
|
15
|
+
delegate :platform_instance, to: :instance
|
16
|
+
|
17
|
+
enable_listable
|
18
|
+
lists.add_symbol :option, :exec_run, :restart
|
19
|
+
|
20
|
+
def description
|
21
|
+
"#{instance.id} Tasks Scheduler"
|
22
|
+
end
|
23
|
+
|
24
|
+
def exec_run?
|
25
|
+
options[OPTION_EXEC_RUN]
|
26
|
+
end
|
27
|
+
|
28
|
+
def option_list
|
29
|
+
self.class.lists.option
|
30
|
+
end
|
31
|
+
|
32
|
+
def restart
|
33
|
+
options[OPTION_RESTART]
|
34
|
+
end
|
35
|
+
|
36
|
+
def unit_name
|
37
|
+
"#{instance.id}_tasks_scheduler.service"
|
38
|
+
end
|
39
|
+
|
40
|
+
def user
|
41
|
+
instance.ssh_username
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def sudo_execute!(*args)
|
47
|
+
platform_instance.host_env.command(['sudo'] + args).execute!
|
48
|
+
end
|
49
|
+
|
50
|
+
def sudo_system!(*args)
|
51
|
+
command_args = ['sudo'] + args
|
52
|
+
infom "Running \"#{::Shellwords.join(command_args)}\"..."
|
53
|
+
platform_instance.host_env.command(command_args).system!
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avm-eac_rails_base1
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Put here the authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avm-eac_webapp_base0
|
@@ -16,20 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 0.2.1
|
19
|
+
version: '0.3'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0.
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 0.2.1
|
26
|
+
version: '0.3'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: eac_ruby_gems_utils
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,8 +88,13 @@ files:
|
|
94
88
|
- lib/avm/eac_rails_base1/runner/logs.rb
|
95
89
|
- lib/avm/eac_rails_base1/runner/logs/clear.rb
|
96
90
|
- lib/avm/eac_rails_base1/runner/rails_server.rb
|
91
|
+
- lib/avm/eac_rails_base1/runner/tasks_scheduler.rb
|
92
|
+
- lib/avm/eac_rails_base1/runner/tasks_scheduler/systemd_unit.rb
|
97
93
|
- lib/avm/eac_rails_base1/runner_with/bundle.rb
|
98
94
|
- lib/avm/eac_rails_base1/runner_with/rails_environment.rb
|
95
|
+
- lib/avm/eac_rails_base1/systemd_unit.rb
|
96
|
+
- lib/avm/eac_rails_base1/systemd_unit/service.rb
|
97
|
+
- lib/avm/eac_rails_base1/systemd_unit/tasks_scheduler_command.rb
|
99
98
|
- lib/avm/eac_rails_base1/version.rb
|
100
99
|
homepage:
|
101
100
|
licenses: []
|