systemized 0.2.3

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
+ SHA1:
3
+ metadata.gz: f3bda9a94dd8f222e63692cde70c8135f70f9d81
4
+ data.tar.gz: 82f5bcbd039dc0a132d62bb75d6c0c4bcc8cb667
5
+ SHA512:
6
+ metadata.gz: 6b34da0d40b60340b28c6f31b3532b88cb395df79fa2feefc1d3a3951213f8bc113f3528af5a6443266ed635ffbf30f1dd2e3fbd4c9e9f8883a0f7b496ba5103
7
+ data.tar.gz: e29962cd22bd373064fffe7b3bff48429bd3f39eb52f28c15bb187ab056365509c6d8bc87dbf69f2c5b703ded86007b998984f72b0c888296c0e8623b81c1ab4
data/.gitignore ADDED
@@ -0,0 +1,54 @@
1
+
2
+ # Created by https://www.gitignore.io/api/ruby
3
+
4
+ ### Ruby ###
5
+ *.gem
6
+ *.rbc
7
+ /.config
8
+ /coverage/
9
+ /InstalledFiles
10
+ /pkg/
11
+ /spec/reports/
12
+ /spec/examples.txt
13
+ /test/tmp/
14
+ /test/version_tmp/
15
+ /tmp/
16
+
17
+ # Used by dotenv library to load environment variables.
18
+ # .env
19
+
20
+ ## Specific to RubyMotion:
21
+ .dat*
22
+ .repl_history
23
+ build/
24
+ *.bridgesupport
25
+ build-iPhoneOS/
26
+ build-iPhoneSimulator/
27
+
28
+ ## Specific to RubyMotion (use of CocoaPods):
29
+ #
30
+ # We recommend against adding the Pods directory to your .gitignore. However
31
+ # you should judge for yourself, the pros and cons are mentioned at:
32
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
33
+ #
34
+ # vendor/Pods/
35
+
36
+ ## Documentation cache and generated files:
37
+ /.yardoc/
38
+ /_yardoc/
39
+ /doc/
40
+ /rdoc/
41
+
42
+ ## Environment normalization:
43
+ /.bundle/
44
+ /vendor/bundle
45
+ /lib/bundler/man/
46
+
47
+ # for a library or gem, you might want to ignore these files since the code is
48
+ # intended to run in multiple environments; otherwise, check them in:
49
+ # Gemfile.lock
50
+ # .ruby-version
51
+ # .ruby-gemset
52
+
53
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
54
+ .rvmrc
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+
2
+ The MIT License (MIT)
3
+ Copyright © 2016 Chris Olstrom <chris@olstrom.com>
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.org ADDED
@@ -0,0 +1,47 @@
1
+ #+TITLE: Systemized
2
+
3
+ * Overview
4
+
5
+ =Systemized= exposes systemd components as Ruby Objects.
6
+
7
+ * Why does this exist?
8
+
9
+ As an attempt to tame some of the complexity of =systemd=.
10
+
11
+ * Installation
12
+
13
+ #+BEGIN_SRC shell
14
+ gem install systemized
15
+ #+END_SRC
16
+
17
+ * Usage
18
+
19
+ The following will read the last ten log entries for the =concourse-worker= service.
20
+
21
+ #+BEGIN_SRC ruby
22
+ require 'systemized'
23
+
24
+ service = Systemized::Service.new 'concourse-worker'
25
+
26
+ service.journal.read(10)
27
+ #+END_SRC
28
+
29
+ This will stop the =concourse-worker= service if it is current active, then start it.
30
+
31
+ #+BEGIN_SRC ruby
32
+ require 'systemized'
33
+
34
+ service = Systemized::Service.new 'concourse-worker'
35
+
36
+ service.stop if service.active?
37
+
38
+ service.start
39
+ #+END_SRC
40
+
41
+ * License
42
+
43
+ ~hyperdock~ is available under the [[https://tldrlegal.com/license/mit-license][MIT License]]. See ~LICENSE.txt~ for the full text.
44
+
45
+ * Contributors
46
+
47
+ - [[https://colstrom.github.io/][Chris Olstrom]] | [[mailto:chris@olstrom.com][e-mail]] | [[https://twitter.com/ChrisOlstrom][Twitter]]
data/lib/systemized.rb ADDED
@@ -0,0 +1,2 @@
1
+ require_relative 'systemized/journal'
2
+ require_relative 'systemized/service'
@@ -0,0 +1,44 @@
1
+ module Systemized
2
+ class Journal
3
+ attr_reader :unit, :options
4
+
5
+ def initialize(unit, **options)
6
+ @unit = unit
7
+ @options = options
8
+ self
9
+ end
10
+
11
+ def quiet?
12
+ @quiet ||= options.fetch(:quiet) { true }
13
+ end
14
+
15
+ def output
16
+ @output ||= options.fetch(:output) { 'short-iso' }
17
+ end
18
+
19
+ def utc?
20
+ @utc ||= options.fetch(:utc) { true }
21
+ end
22
+
23
+ def lines
24
+ @lines ||= options.fetch(:lines) { 10 }
25
+ end
26
+
27
+ def command
28
+ @command ||= options.fetch(:command) { 'journalctl' }
29
+ end
30
+
31
+ def arguments
32
+ @arguments ||= [
33
+ "--unit #{unit}",
34
+ ('--quiet' if quiet?),
35
+ "--output #{output}",
36
+ ('--utc' if utc?)
37
+ ].compact.join(' ')
38
+ end
39
+
40
+ def read(entries = lines)
41
+ `#{command} #{arguments} --lines #{entries}`.lines
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,51 @@
1
+ require_relative 'journal'
2
+
3
+ module Systemized
4
+ class Service
5
+ attr_reader :service, :options
6
+
7
+ def initialize(service, **options)
8
+ @service = service
9
+ @options = options
10
+ self
11
+ end
12
+
13
+ def journal
14
+ @journal ||= Journal.new service
15
+ end
16
+
17
+ def command
18
+ @options.fetch(:command) { 'systemctl' }
19
+ end
20
+
21
+ def quiet?
22
+ @options.fetch(:quiet) { true }
23
+ end
24
+
25
+ def arguments
26
+ @arguments ||= [
27
+ ('--quiet' if quiet?)
28
+ ].compact.join(' ')
29
+ end
30
+
31
+ def enabled?
32
+ system("#{command} #{arguments} is-enabled #{service}")
33
+ end
34
+
35
+ def active?
36
+ system("#{command} #{arguments} is-active #{service}")
37
+ end
38
+
39
+ def failed?
40
+ system("#{command} #{arguments} is-failed #{service}")
41
+ end
42
+
43
+ def stop
44
+ `#{command} #{arguments} stop #{service}`
45
+ end
46
+
47
+ def start
48
+ `#{command} #{arguments} start #{service}`
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'systemized'
3
+ gem.version = `git describe --tags --abbrev=0`.chomp
4
+ gem.licenses = 'MIT'
5
+ gem.authors = ['Chris Olstrom']
6
+ gem.email = 'chris@olstrom.com'
7
+ gem.homepage = 'https://github.com/colstrom/systemized'
8
+ gem.summary = 'Exposes systemd components to Ruby'
9
+
10
+ gem.files = `git ls-files`.split("\n")
11
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
13
+ gem.require_paths = ['lib']
14
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: systemized
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
5
+ platform: ruby
6
+ authors:
7
+ - Chris Olstrom
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: chris@olstrom.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".gitignore"
20
+ - LICENSE.txt
21
+ - README.org
22
+ - lib/systemized.rb
23
+ - lib/systemized/journal.rb
24
+ - lib/systemized/service.rb
25
+ - systemized.gemspec
26
+ homepage: https://github.com/colstrom/systemized
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.5.1
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Exposes systemd components to Ruby
50
+ test_files: []