capistrano-simple_systemd 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4ad107438dc47d0e0e3d7836a650c9e01872de82ba39779f446376d8389f7829
4
+ data.tar.gz: 102cd883ec4fcb1532a738aa6bafd0462d96a76ece0e28f66f545818a152500a
5
+ SHA512:
6
+ metadata.gz: d98c57cbfb516d45fe82c7b8e977acea67aaf61a9e43cdab2b9fbc1a76ae3114573587d7fca708c65e6369ded23b3231a643a36f14c86ec04bef108f6325219a
7
+ data.tar.gz: ac10230dc31e647bbf19c835ba58ba9a2a6bb0bb5dc7b0a3d55051a5ffa91b73b8ab998ad7c9a0e7b3415f0f93e28f0750d0527b18a70634d80d2d24af658df1
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,4 @@
1
+ # Changelog
2
+
3
+ ### v0.1.0, 2019-09-20 (Feature Release)
4
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in capistrano-simple_systemd.gemspec
4
+ gemspec
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano-simple_systemd (0.1.0)
5
+ capistrano (~> 3.7)
6
+ sshkit (~> 1.2)
7
+ sshkit-sudo (~> 0.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ airbrussh (1.3.4)
13
+ sshkit (>= 1.6.1, != 1.7.0)
14
+ capistrano (3.11.1)
15
+ airbrussh (>= 1.0.0)
16
+ i18n
17
+ rake (>= 10.0.0)
18
+ sshkit (>= 1.9.0)
19
+ concurrent-ruby (1.1.5)
20
+ i18n (1.6.0)
21
+ concurrent-ruby (~> 1.0)
22
+ net-scp (2.0.0)
23
+ net-ssh (>= 2.6.5, < 6.0.0)
24
+ net-ssh (5.2.0)
25
+ rake (10.5.0)
26
+ sshkit (1.20.0)
27
+ net-scp (>= 1.1.2)
28
+ net-ssh (>= 2.8.0)
29
+ sshkit-sudo (0.1.0)
30
+ sshkit (~> 1.8)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 2.0)
37
+ capistrano-simple_systemd!
38
+ rake (~> 10.0)
39
+
40
+ BUNDLED WITH
41
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 DarkWasp
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.
@@ -0,0 +1,93 @@
1
+ # capistrano-simple_systemd
2
+
3
+ Capistrano tasks to control mutiple services with systemd
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'capistrano-simple_systemd'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install capistrano-simple_systemd
20
+
21
+ ## Usage
22
+
23
+ Add this line to your Capfile:
24
+
25
+ ```ruby
26
+ require "capistrano/simple_systemd"
27
+ ```
28
+
29
+ Service files are defined as ERB templates ending with `.service.erb` in `config/systemd`. <br>
30
+ PLEASE NOTE: Currently only files with the `.service.erb` extension are considered as service file templates. Others like `.target.erb` aren't supported yet
31
+
32
+ The following tasks are provided out of the box
33
+ ```ruby
34
+ cap systemd:reload-daemons
35
+ cap systemd:upload
36
+ ```
37
+
38
+ The following tasks will be created for each service template detected in the `config/systemd` directory
39
+
40
+ ```ruby
41
+ cap systemd:{service}:disable
42
+ cap systemd:{service}:enable
43
+ cap systemd:{service}:reload
44
+ cap systemd:{service}:reload-or-restart
45
+ cap systemd:{service}:restart
46
+ cap systemd:{service}:start
47
+ cap systemd:{service}:stop
48
+ ```
49
+ Where `service` is the base name of the service template. <br>
50
+ For example, placing `puma.service.erb` in the template directory will yield the following tasks
51
+ ```ruby
52
+ cap systemd:puma:disable
53
+ cap systemd:puma:enable
54
+ cap systemd:puma:reload
55
+ cap systemd:puma:reload-or-restart
56
+ cap systemd:puma:restart
57
+ cap systemd:puma:start
58
+ cap systemd:puma:stop
59
+ ```
60
+
61
+ Run
62
+ ```ruby
63
+ cap {stage} systemd:upload
64
+ ```
65
+ Or
66
+ ```ruby
67
+ cap {stage} setup
68
+ ```
69
+
70
+ to compile and upload the service files. Service files will be prefixed with whichever value is in `service_file_prefix` and uploaded to `/etc/systemd/system`. The variable `service_file_prefix` by default is set to whatever is in the `application` configuration variable. <br>So if `application` is set to `paypoint` then `puma.service.erb` will be uploaded to `/etc/systemd/system/paypoint-puma.service`. <br>
71
+ `service_file_prefix` can be configured. E.g.
72
+ ```ruby
73
+ set :service_file_prefix, 'paypoint-app'
74
+ ```
75
+
76
+ Services are enabled after upload by invoking `systemd:{service}:enable`. This behaviour can be disabled by setting `enable_services_after_upload` to false.
77
+ ```ruby
78
+ set :enable_services_after_upload, false
79
+ ```
80
+
81
+ ## Development
82
+
83
+ After checking out the repo, run `bundle`
84
+
85
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
86
+
87
+ ## Contributing
88
+
89
+ Bug reports and pull requests are welcome on GitHub at https://github.com/darkwasp99/capistrano-simple_systemd.
90
+
91
+ ## License
92
+
93
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,36 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "capistrano/simple_systemd/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "capistrano-simple_systemd"
7
+ spec.version = Capistrano::SimpleSystemd::VERSION
8
+ spec.authors = ["DarkWasp"]
9
+ spec.email = ["coderwasp@gmail.com"]
10
+
11
+ spec.summary = "Simple systemd integration for Capistrano."
12
+ spec.description = "Simple systemd integration for Capistrano. Uploads service files"
13
+ spec.homepage = "https://github.com/darkwasp99/capistrano-simple_systemd"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/darkwasp99/capistrano-simple_systemd"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency "capistrano", "~> 3.7"
31
+ spec.add_runtime_dependency "sshkit", "~> 1.2"
32
+ spec.add_runtime_dependency "sshkit-sudo", "~> 0.1"
33
+
34
+ spec.add_development_dependency "bundler", "~> 2.0"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ end
File without changes
@@ -0,0 +1,4 @@
1
+ require 'capistrano/simple_systemd/paths'
2
+ require 'capistrano/simple_systemd/helpers'
3
+ load File.expand_path('../tasks/simple_systemd/global_tasks.rake', __FILE__)
4
+ load File.expand_path('../tasks/simple_systemd/specific_tasks.rake', __FILE__)
@@ -0,0 +1,25 @@
1
+ module Capistrano
2
+ module SimpleSystemd
3
+ module Helpers
4
+ def each_service_template(&block)
5
+ service_file_local_dir = Capistrano::SimpleSystemd::Paths.service_file_local_dir
6
+
7
+ Dir
8
+ .glob(File.join(service_file_local_dir, '*.service.erb'))
9
+ .each do |template_file|
10
+ block.call(template_file)
11
+ end
12
+ end
13
+
14
+ def compile(template_file_path)
15
+ ERB.new(File.new(template_file_path).read).result(binding)
16
+ end
17
+
18
+ def upload_service_file(file_content, file_name, destination_dir)
19
+ tmp_path = "#{fetch(:tmp_dir)}/#{file_name}"
20
+ upload! StringIO.new(file_content), tmp_path
21
+ sudo :mv, tmp_path, "#{destination_dir}/#{file_name}"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ module Capistrano
2
+ module SimpleSystemd
3
+ module Paths
4
+ def self.service_file_local_dir
5
+ 'config/systemd'
6
+ end
7
+
8
+ def self.service_file_remote_dir
9
+ '/etc/systemd/system'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module SimpleSystemd
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,45 @@
1
+ include Capistrano::SimpleSystemd::Helpers
2
+ load "#{File.dirname(__FILE__)}/task_defaults.rake"
3
+
4
+ namespace :systemd do
5
+ task :upload do
6
+ original_pty_value = fetch(:pty)
7
+ set :pty, true
8
+
9
+ each_service_template do |template|
10
+ template_basename = File.basename(template, '.service.erb')
11
+
12
+ service_basename = [
13
+ fetch(:service_file_prefix),
14
+ template_basename
15
+ ].join('-')
16
+
17
+ service_filename = "#{service_basename}.service"
18
+ enable_services_after_upload = fetch(:enable_services_after_upload)
19
+
20
+ on release_roles :all do
21
+ upload_service_file(
22
+ compile(File.absolute_path(template)),
23
+ service_filename,
24
+ fetch(:service_file_remote_dir)
25
+ )
26
+
27
+ invoke "systemd:#{template_basename}:enable" if enable_services_after_upload
28
+ end
29
+ end
30
+
31
+ set :pty, original_pty_value
32
+ end
33
+
34
+ task :'reload-daemons' do
35
+ on release_roles :all do
36
+ sudo :systemctl, :'daemon-reload'
37
+ # puts fetch(:service_file_local_dir)
38
+ end
39
+ end
40
+ end
41
+
42
+ task :setup do
43
+ invoke 'systemd:upload'
44
+ invoke 'systemd:reload-daemons'
45
+ end
@@ -0,0 +1,32 @@
1
+ include Capistrano::SimpleSystemd::Helpers
2
+ load "#{File.dirname(__FILE__)}/task_defaults.rake"
3
+
4
+ namespace :systemd do
5
+ each_service_template do |template|
6
+ template_basename = File.basename(template, '.service.erb')
7
+
8
+ namespace template_basename do
9
+ {
10
+ start: "Run systemctl %{task_name} for %{service} service",
11
+ stop: "Run systemctl %{task_name} for %{service} service",
12
+ reload: "Run systemctl %{task_name} for %{service} service",
13
+ restart: "Run systemctl %{task_name} for %{service} service",
14
+ "reload-or-restart": "Run systemctl %{task_name} for %{service} service",
15
+ enable: "Run systemctl %{task_name} for %{service} service",
16
+ disable: "Run systemctl %{task_name} for %{service} service",
17
+ }.each do |task_name, desc_template|
18
+ desc(desc_template % { service: template_basename, task_name: task_name})
19
+ task task_name do
20
+ on release_roles :all do
21
+ service_basename = [
22
+ fetch(:service_file_prefix),
23
+ template_basename
24
+ ].join('-')
25
+
26
+ sudo :systemctl, task_name, "#{service_basename}.service"
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,8 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ set :service_file_local_dir, Capistrano::SimpleSystemd::Paths.service_file_local_dir
4
+ set :service_file_remote_dir, Capistrano::SimpleSystemd::Paths.service_file_remote_dir
5
+ set :service_file_prefix, -> { fetch(:application) }
6
+ set :enable_services_after_upload, true
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-simple_systemd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - DarkWasp
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-09-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sshkit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sshkit-sudo
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: Simple systemd integration for Capistrano. Uploads service files
84
+ email:
85
+ - coderwasp@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - CHANGELOG.md
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - capistrano-simple_systemd.gemspec
98
+ - lib/capistrano-simple_systemd.rb
99
+ - lib/capistrano/simple_systemd.rb
100
+ - lib/capistrano/simple_systemd/helpers.rb
101
+ - lib/capistrano/simple_systemd/paths.rb
102
+ - lib/capistrano/simple_systemd/version.rb
103
+ - lib/capistrano/tasks/simple_systemd/global_tasks.rake
104
+ - lib/capistrano/tasks/simple_systemd/specific_tasks.rake
105
+ - lib/capistrano/tasks/simple_systemd/task_defaults.rake
106
+ homepage: https://github.com/darkwasp99/capistrano-simple_systemd
107
+ licenses:
108
+ - MIT
109
+ metadata:
110
+ allowed_push_host: https://rubygems.org
111
+ homepage_uri: https://github.com/darkwasp99/capistrano-simple_systemd
112
+ source_code_uri: https://github.com/darkwasp99/capistrano-simple_systemd
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.0.3
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Simple systemd integration for Capistrano.
132
+ test_files: []