capistrano-hutch-systemd 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: b61c1412f7da9dfca04499fe74ac5925574f632b5dbac451bc5286f18412e047
4
+ data.tar.gz: 8528110a64e713a76a2ac6115f311ce44e72b460e28c4bec1bd21c54becdf0f2
5
+ SHA512:
6
+ metadata.gz: 18f2b69736df9c7f8d1e6fe48b5a8510e9612561b935ccb1cd7032ef885dd698896989289ab911664bac0c92db6fd9de3546d03b6c2cc420362886a509fc7ca0
7
+ data.tar.gz: d2c791df64c476ed3efda97ab4512f1a1b9ac4223888fa06150d4fdb8c1fa064a0ba0773b5a0ca73f18ff6206ca893a97e119f17f1786e0594b7dadf1507d9f0
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-11-09
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at m.yunan.helmy@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
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-hutch-systemd.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.21"
11
+
12
+ gem "bump"
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano-hutch-systemd (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ bump (0.10.0)
11
+ json (2.6.2)
12
+ parallel (1.22.1)
13
+ parser (3.1.2.1)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.1.1)
16
+ rake (13.0.6)
17
+ regexp_parser (2.6.0)
18
+ rexml (3.2.5)
19
+ rubocop (1.38.0)
20
+ json (~> 2.3)
21
+ parallel (~> 1.10)
22
+ parser (>= 3.1.2.1)
23
+ rainbow (>= 2.2.2, < 4.0)
24
+ regexp_parser (>= 1.8, < 3.0)
25
+ rexml (>= 3.2.5, < 4.0)
26
+ rubocop-ast (>= 1.23.0, < 2.0)
27
+ ruby-progressbar (~> 1.7)
28
+ unicode-display_width (>= 1.4.0, < 3.0)
29
+ rubocop-ast (1.23.0)
30
+ parser (>= 3.1.1.0)
31
+ ruby-progressbar (1.11.0)
32
+ unicode-display_width (2.3.0)
33
+
34
+ PLATFORMS
35
+ x86_64-darwin-21
36
+
37
+ DEPENDENCIES
38
+ bump
39
+ capistrano-hutch-systemd!
40
+ rake (~> 13.0)
41
+ rubocop (~> 1.21)
42
+
43
+ BUNDLED WITH
44
+ 2.3.23
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Yunan Helmy
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,76 @@
1
+ # Capistrano::Hutch::Systemd
2
+
3
+ Hutch + SystemD integration for Capistrano
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add capistrano-hutch-systemd
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install capistrano-hutch-systemd
14
+
15
+ Or add in your Gemfile :
16
+
17
+ ```
18
+ gem 'capistrano-hutch-systemd'
19
+ ```
20
+
21
+ And then
22
+
23
+ $ bundle install
24
+
25
+ Install hutch to your server before running deployment :
26
+
27
+ $ cap {your_stage} hutch:install
28
+
29
+ ## Usage
30
+
31
+ In your Capfile :
32
+
33
+ ```
34
+ require 'capistrano/hutch'
35
+ install_plugin Capistrano::Hutch
36
+ install_plugin Capistrano::HutchPlugin::Systemd
37
+ ```
38
+
39
+ Add preference in your deploy.rb
40
+
41
+ ```
42
+ set :hutch_default_hooks, true
43
+ set :hutch_env, fetch(:rack_env, fetch(:rails_env, fetch(:stage)))
44
+ set :hutch_roles, :app
45
+ set :hutch_use_config_file, true
46
+ set :hutch_config_files, ['hutch.yml']
47
+ set :hutch_service_unit_user, :user
48
+ set :hutch_log, '/path/to/shared/log/events.log'
49
+ set :hutch_error_log, '/path/to/shared/log/events.log'
50
+ ```
51
+
52
+ ## Example
53
+
54
+ [TODO] Create example
55
+
56
+ ## Development
57
+
58
+ The code was modified from https://github.com/seuros/capistrano-sidekiq
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it
63
+ 2. Create your feature branch (git checkout -b my-new-feature)
64
+ 3. Commit your changes (git commit -am 'Add some feature')
65
+ 4. Push to the branch (git push origin my-new-feature)
66
+ 5. Create new Pull Request
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yunanhelmy/capistrano-hutch-systemd. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yunanhelmy/capistrano-hutch-systemd/blob/master/CODE_OF_CONDUCT.md).
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
73
+
74
+ ## Code of Conduct
75
+
76
+ Everyone interacting in the Capistrano::Hutch::Systemd project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yunanhelmy/capistrano-hutch-systemd/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "capistrano/bundler"
4
+ require "capistrano/plugin"
5
+
6
+ module Capistrano
7
+ module HutchCommon
8
+ def compiled_template(config_file = "hutch.yml", use_config_file: false)
9
+ @use_config_file = use_config_file
10
+ @config_file = config_file
11
+ local_template_directory = fetch(:hutch_service_templates_path)
12
+ search_paths = [
13
+ File.join(local_template_directory, "hutch.service.capistrano.erb"),
14
+ File.expand_path(
15
+ File.join(*%w[.. templates hutch.service.capistrano.erb]),
16
+ __FILE__
17
+ )
18
+ ]
19
+ template_path = search_paths.detect { |path| File.file?(path) }
20
+ template = File.read(template_path)
21
+ ERB.new(template, trim_mode: "-").result(binding)
22
+ end
23
+
24
+ def expanded_bundle_path
25
+ backend.capture(:echo, SSHKit.config.command_map[:bundle]).strip
26
+ end
27
+
28
+ def hutch_config
29
+ "--config config/#{@config_file}" if @use_config_file
30
+ end
31
+
32
+ def hutch_systemd_env
33
+ "RAILS_ENV=#{fetch(:hutch_env)}"
34
+ end
35
+
36
+ def switch_user(role, &block)
37
+ su_user = hutch_user(role)
38
+ if su_user == role.user
39
+ yield
40
+ else
41
+ as su_user, &block
42
+ end
43
+ end
44
+
45
+ def hutch_user(role = nil)
46
+ if role.nil?
47
+ fetch(:hutch_user)
48
+ else
49
+ properties = role.properties
50
+ properties.fetch(:hutch_user) || # local property for hutch only
51
+ fetch(:hutch_user) ||
52
+ properties.fetch(:run_as) || # global property across multiple capistrano gems
53
+ role.user
54
+ end
55
+ end
56
+ end
57
+
58
+ class Hutch < Capistrano::Plugin
59
+ def define_tasks
60
+ eval_rakefile File.expand_path("tasks/hutch.rake", __dir__)
61
+ end
62
+
63
+ def set_defaults
64
+ set_if_empty :hutch_default_hooks, true
65
+
66
+ set_if_empty :hutch_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:rake_env, fetch(:stage)))) }
67
+ set_if_empty :hutch_roles, fetch(:hutch_role, :app)
68
+ set_if_empty :hutch_configs, %w[hutch] # hutch.yml
69
+
70
+ set_if_empty :hutch_log, -> { File.join(shared_path, "log", "hutch.log") }
71
+ set_if_empty :hutch_error_log, -> { File.join(shared_path, "log", "hutch.log") }
72
+
73
+ set_if_empty :hutch_config_files, ["hutch.yml"]
74
+
75
+ # Rbenv, Chruby, and RVM integration
76
+ append :rbenv_map_bins, "hutch", "hutchctl"
77
+ append :rvm_map_bins, "hutch", "hutchctl"
78
+ append :chruby_map_bins, "hutch", "hutchctl"
79
+ # Bundler integration
80
+ append :bundle_bins, "hutch", "hutchctl"
81
+ end
82
+ end
83
+
84
+ module HutchPlugin
85
+ end
86
+ end
87
+
88
+ require_relative "hutch_plugin/systemd"
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Capistrano
4
+ module HutchPlugin
5
+ class Systemd < Capistrano::Plugin
6
+ include HutchCommon
7
+ def define_tasks
8
+ eval_rakefile File.expand_path("../tasks/systemd.rake", __dir__)
9
+ end
10
+
11
+ def set_defaults
12
+ set_if_empty :systemctl_bin, "/bin/systemctl"
13
+ set_if_empty :hutch_service_unit_user, :user
14
+ set_if_empty :hutch_systemctl_user, fetch(:hutch_service_unit_user, :user) == :user
15
+
16
+ set_if_empty :hutch_service_unit_name, -> { "#{fetch(:application)}_hutch_#{fetch(:stage)}" }
17
+ set_if_empty :hutch_lingering_user, -> { fetch(:lingering_user, fetch(:user)) }
18
+
19
+ ## Hutch could have a stripped down or more complex version of the environment variables
20
+ set_if_empty :hutch_service_unit_env_files, -> { fetch(:service_unit_env_files, []) }
21
+ set_if_empty :hutch_service_unit_env_vars, -> { fetch(:service_unit_env_vars, []) }
22
+
23
+ set_if_empty :hutch_service_templates_path, fetch(:service_templates_path, "config/deploy/templates")
24
+
25
+ set_if_empty :hutch_use_config_file, false
26
+ end
27
+
28
+ def systemd_command(*args)
29
+ command = [fetch(:systemctl_bin)]
30
+
31
+ command << "--user" unless fetch(:hutch_service_unit_user) == :system
32
+
33
+ command + args
34
+ end
35
+
36
+ def sudo_if_needed(*command)
37
+ if fetch(:hutch_service_unit_user) == :system
38
+ backend.sudo command.map(&:to_s).join(" ")
39
+ else
40
+ backend.execute(*command)
41
+ end
42
+ end
43
+
44
+ def execute_systemd(*args)
45
+ sudo_if_needed(*systemd_command(*args))
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Capistrano
4
+ module HutchVersion
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :deploy do
4
+ before :starting, :check_hutch_hooks do
5
+ invoke "hutch:add_default_hooks" if fetch(:hutch_default_hooks)
6
+ end
7
+ end
8
+
9
+ namespace :hutch do
10
+ task :add_default_hooks do
11
+ after "deploy:starting", "hutch:quiet" if Rake::Task.task_defined?("hutch:quiet")
12
+ after "deploy:updated", "hutch:stop"
13
+ after "deploy:published", "hutch:start"
14
+ after "deploy:failed", "hutch:restart"
15
+ end
16
+ end
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ git_plugin = self
4
+
5
+ namespace :hutch do
6
+ standard_actions = {
7
+ start: "Start hutch",
8
+ stop: "Stop hutch (graceful shutdown within timeout)",
9
+ status: "Get hutch Status",
10
+ restart: "Restart hutch"
11
+ }
12
+ standard_actions.each do |command, description|
13
+ desc description
14
+ task command do
15
+ on roles fetch(:hutch_roles) do |role|
16
+ git_plugin.switch_user(role) do
17
+ git_plugin.config_files(role).each do |config_file|
18
+ git_plugin.execute_systemd(command, git_plugin.hutch_service_file_name(config_file))
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ desc "Quiet hutch (stop fetching new tasks from Redis)"
26
+ task :quiet do
27
+ on roles fetch(:hutch_roles) do |role|
28
+ git_plugin.switch_user(role) do
29
+ git_plugin.quiet_hutch(role)
30
+ end
31
+ end
32
+ end
33
+
34
+ desc "Install hutch systemd service"
35
+ task :install do
36
+ on roles fetch(:hutch_roles) do |role|
37
+ git_plugin.switch_user(role) do
38
+ git_plugin.create_systemd_template(role)
39
+ end
40
+ end
41
+ invoke "hutch:enable"
42
+ end
43
+
44
+ desc "Uninstall hutch systemd service"
45
+ task :uninstall do
46
+ invoke "hutch:disable"
47
+ on roles fetch(:hutch_roles) do |role|
48
+ git_plugin.switch_user(role) do
49
+ git_plugin.rm_systemd_service(role)
50
+ end
51
+ end
52
+ end
53
+
54
+ desc "Enable hutch systemd service"
55
+ task :enable do
56
+ on roles(fetch(:hutch_roles)) do |role|
57
+ git_plugin.config_files(role).each do |config_file|
58
+ git_plugin.execute_systemd("enable", git_plugin.hutch_service_file_name(config_file))
59
+ end
60
+
61
+ if fetch(:hutch_systemctl_user) && fetch(:hutch_lingering_user)
62
+ execute :loginctl, "enable-linger", fetch(:puma_lingering_user)
63
+ end
64
+ end
65
+ end
66
+
67
+ desc "Disable hutch systemd service"
68
+ task :disable do
69
+ on roles(fetch(:hutch_roles)) do |role|
70
+ git_plugin.config_files(role).each do |config_file|
71
+ git_plugin.execute_systemd("disable", git_plugin.hutch_service_file_name(config_file))
72
+ end
73
+ end
74
+ end
75
+
76
+ def fetch_systemd_unit_path
77
+ if fetch(:hutch_systemctl_user) == :system
78
+ "/etc/systemd/system/"
79
+ else
80
+ home_dir = backend.capture :pwd
81
+ File.join(home_dir, ".config", "systemd", "user")
82
+ end
83
+ end
84
+
85
+ def create_systemd_template(role)
86
+ systemd_path = fetch(:service_unit_path, fetch_systemd_unit_path)
87
+ backend.execute :mkdir, "-p", systemd_path if fetch(:hutch_systemctl_user)
88
+
89
+ config_files(role).each do |config_file|
90
+ ctemplate = compiled_template(config_file, use_config_file: fetch(:hutch_use_config_file))
91
+ temp_file_name = File.join("/tmp", "hutch.#{config_file}.service")
92
+ systemd_file_name = File.join(systemd_path, hutch_service_file_name(config_file))
93
+ backend.upload!(StringIO.new(ctemplate), temp_file_name)
94
+ if fetch(:hutch_systemctl_user)
95
+ warn "Moving #{temp_file_name} to #{systemd_file_name}"
96
+ backend.execute :mv, temp_file_name, systemd_file_name
97
+ else
98
+ warn "Installing #{systemd_file_name} as root"
99
+ backend.execute :sudo, :mv, temp_file_name, systemd_file_name
100
+ end
101
+ end
102
+ end
103
+
104
+ def rm_systemd_service(role)
105
+ systemd_path = fetch(:service_unit_path, fetch_systemd_unit_path)
106
+
107
+ config_files(role).each do |config_file|
108
+ systemd_file_name = File.join(systemd_path, hutch_service_file_name(config_file))
109
+ if fetch(:hutch_systemctl_user)
110
+ warn "Deleting #{systemd_file_name}"
111
+ backend.execute :rm, "-f", systemd_file_name
112
+ else
113
+ warn "Deleting #{systemd_file_name} as root"
114
+ backend.execute :sudo, :rm, "-f", systemd_file_name
115
+ end
116
+ end
117
+ end
118
+
119
+ def quiet_hutch(role)
120
+ config_files(role).each do |config_file|
121
+ hutch_service = hutch_service_unit_name(config_file)
122
+ warn "Quieting #{hutch_service}"
123
+ execute_systemd("kill -s TERM", hutch_service)
124
+ end
125
+ end
126
+
127
+ def hutch_service_unit_name(config_file)
128
+ if config_file != "hutch.yml"
129
+ "#{fetch(:hutch_service_unit_name)}.#{config_file.split(".")[0..-2].join(".")}"
130
+ else
131
+ fetch(:hutch_service_unit_name)
132
+ end
133
+ end
134
+
135
+ def hutch_service_file_name(config_file)
136
+ ## Remove the extension
137
+ config_file = config_file.split(".")[0..].join(".")
138
+
139
+ "#{hutch_service_unit_name(config_file)}.service"
140
+ end
141
+
142
+ def config_files(role)
143
+ role.properties.fetch(:hutch_config_files) ||
144
+ fetch(:hutch_config_files)
145
+ end
146
+ end
@@ -0,0 +1,37 @@
1
+ # This file tells systemd how to run hutch as a 24/7 long-running daemon.
2
+
3
+ # Then run:
4
+ # - systemctl enable <%= hutch_service_unit_name(@config_file) %>
5
+ # - systemctl {start,stop,restart} <%= hutch_service_unit_name(@config_file) %>
6
+ #
7
+ # Use `journalctl -u <%= hutch_service_unit_name(@config_file) %> -rn 100` to view the last 100 lines of log output.
8
+ #
9
+ [Unit]
10
+ Description=hutch for <%= "#{fetch(:application)} (#{fetch(:stage)})" %>
11
+ After=syslog.target network.target
12
+
13
+ [Service]
14
+ Type=notify
15
+ <%="User=#{hutch_user}" if fetch(:hutch_systemctl_user) == :system %>
16
+ WorkingDirectory=<%= current_path %>
17
+ ExecStart=<%= expanded_bundle_path %> exec hutch <%= hutch_config %>
18
+
19
+ <%- Array(fetch(:hutch_service_unit_env_files)).each do |file| %>
20
+ <%="EnvironmentFile=#{file}" %>
21
+ <% end -%>
22
+ <% Array(fetch(:hutch_service_unit_env_vars)).each do |environment_variable| %>
23
+ <%="Environment=\"#{environment_variable}\"" %>
24
+ <% end -%>
25
+ <%= "Environment=#{hutch_systemd_env}" %>
26
+
27
+ # if we crash, restart
28
+ RestartSec=1
29
+ Restart=on-failure
30
+
31
+ <%= "StandardOutput=append:#{fetch(:hutch_log)}" if fetch(:hutch_log) %>
32
+
33
+ <%= "StandardError=append:#{fetch(:hutch_error_log)}" if fetch(:hutch_error_log) %>
34
+
35
+ SyslogIdentifier=<%= hutch_service_unit_name(@config_file) %>
36
+ [Install]
37
+ WantedBy=<%=(fetch(:hutch_systemctl_user) == :system) ? "multi-user.target" : "default.target"%>
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-hutch-systemd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yunan Helmy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-11-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Hutch integration for Capistrano.
14
+ email:
15
+ - m.yunan.helmy@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rubocop.yml"
21
+ - CHANGELOG.md
22
+ - CODE_OF_CONDUCT.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - lib/capistrano/hutch.rb
29
+ - lib/capistrano/hutch_plugin/systemd.rb
30
+ - lib/capistrano/hutch_version/version.rb
31
+ - lib/capistrano/tasks/hutch.rake
32
+ - lib/capistrano/tasks/systemd.rake
33
+ - lib/capistrano/templates/hutch.service.capistrano.erb
34
+ homepage: https://github.com/yunanhelmy/capistrano-hutch-systemd
35
+ licenses:
36
+ - MIT
37
+ metadata:
38
+ allowed_push_host: https://rubygems.org
39
+ homepage_uri: https://github.com/yunanhelmy/capistrano-hutch-systemd
40
+ source_code_uri: https://github.com/yunanhelmy/capistrano-hutch-systemd
41
+ changelog_uri: https://github.com/yunanhelmy/capistrano-hutch-systemd/blob/master/CHANGELOG.md
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.6.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.3.7
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Hutch integration for Capistrano
61
+ test_files: []