systemdy 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.
- checksums.yaml +7 -0
 - data/.rspec +3 -0
 - data/CHANGELOG.md +5 -0
 - data/CODE_OF_CONDUCT.md +84 -0
 - data/Gemfile +10 -0
 - data/Gemfile.lock +34 -0
 - data/LICENSE.txt +21 -0
 - data/README.md +637 -0
 - data/Rakefile +10 -0
 - data/lib/systemdy/journal.rb +115 -0
 - data/lib/systemdy/service.rb +122 -0
 - data/lib/systemdy/utility/formatter.rb +15 -0
 - data/lib/systemdy/utility/key_value_filter.rb +10 -0
 - data/lib/systemdy/utility/message_displayer.rb +10 -0
 - data/lib/systemdy/utility/validator.rb +13 -0
 - data/lib/systemdy/version.rb +5 -0
 - data/lib/systemdy.rb +23 -0
 - data/sig/systemdy.rbs +4 -0
 - metadata +63 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: abda4b02a15b8b3dcf89cc3c92fe53027b67708cf07b37b0274f51f11d1e0e07
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 94edeaca38a67b73676e7301f23bcdc25e87da29dce75d4584c36adc3a3f04d0
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 30eda44f1659af67b18de78cb20be466f0986220e4a40963b83bbbc3422dad3a3809dc2f9f94a26bca7f236890ee4e0c682c66edb548d4a280c31a3ad2090f7c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 868bac0eb61ea2bb42fe849e421fad778d3fc6605f0a43f5c054fd9ac3870674662e19895cc3cfc97980b09e0ed59a5c770551106c3f8f87295bcb43866a6295
         
     | 
    
        data/.rspec
    ADDED
    
    
    
        data/CHANGELOG.md
    ADDED
    
    
    
        data/CODE_OF_CONDUCT.md
    ADDED
    
    | 
         @@ -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 TODO: Write your email address. 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
    
    
    
        data/Gemfile.lock
    ADDED
    
    | 
         @@ -0,0 +1,34 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            PATH
         
     | 
| 
      
 2 
     | 
    
         
            +
              remote: .
         
     | 
| 
      
 3 
     | 
    
         
            +
              specs:
         
     | 
| 
      
 4 
     | 
    
         
            +
                systemdy (0.1.0)
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            GEM
         
     | 
| 
      
 7 
     | 
    
         
            +
              remote: https://rubygems.org/
         
     | 
| 
      
 8 
     | 
    
         
            +
              specs:
         
     | 
| 
      
 9 
     | 
    
         
            +
                diff-lcs (1.5.0)
         
     | 
| 
      
 10 
     | 
    
         
            +
                rake (13.0.6)
         
     | 
| 
      
 11 
     | 
    
         
            +
                rspec (3.11.0)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  rspec-core (~> 3.11.0)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  rspec-expectations (~> 3.11.0)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  rspec-mocks (~> 3.11.0)
         
     | 
| 
      
 15 
     | 
    
         
            +
                rspec-core (3.11.0)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  rspec-support (~> 3.11.0)
         
     | 
| 
      
 17 
     | 
    
         
            +
                rspec-expectations (3.11.1)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  rspec-support (~> 3.11.0)
         
     | 
| 
      
 20 
     | 
    
         
            +
                rspec-mocks (3.11.1)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  rspec-support (~> 3.11.0)
         
     | 
| 
      
 23 
     | 
    
         
            +
                rspec-support (3.11.1)
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            PLATFORMS
         
     | 
| 
      
 26 
     | 
    
         
            +
              x86_64-linux
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            DEPENDENCIES
         
     | 
| 
      
 29 
     | 
    
         
            +
              rake (~> 13.0)
         
     | 
| 
      
 30 
     | 
    
         
            +
              rspec (~> 3.0)
         
     | 
| 
      
 31 
     | 
    
         
            +
              systemdy!
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            BUNDLED WITH
         
     | 
| 
      
 34 
     | 
    
         
            +
               2.3.7
         
     | 
    
        data/LICENSE.txt
    ADDED
    
    | 
         @@ -0,0 +1,21 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            The MIT License (MIT)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Copyright (c) 2022 TODO: Write your name
         
     | 
| 
      
 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,637 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Systemd
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            <div align="center">
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            
         
     | 
| 
      
 6 
     | 
    
         
            +
            [](https://github.com/magic4dev/systemdy/issues)
         
     | 
| 
      
 7 
     | 
    
         
            +
            [](https://github.com/magic4dev/systemdy/network)
         
     | 
| 
      
 8 
     | 
    
         
            +
            [](https://github.com/magic4dev/systemdy/blob/master/LICENSE.txt)
         
     | 
| 
      
 9 
     | 
    
         
            +
            [](https://github.com/magic4dev/systemdy/stargazers)
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            </div>
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            A lightweight gem for interact with systemd.
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            If your goal is to develop software to quickly manage systemd services or journalctl logs, this gem is for you! :grin:
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            ## Features
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            - Lightweight
         
     | 
| 
      
 21 
     | 
    
         
            +
            - Expressive classes and methods
         
     | 
| 
      
 22 
     | 
    
         
            +
            - Manage systemd's services lifecycle with minimal effort!
         
     | 
| 
      
 23 
     | 
    
         
            +
            - Extract and manipulate Journalctl logs with a single action!
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            ## Table of contents
         
     | 
| 
      
 26 
     | 
    
         
            +
            * [Installation](#installation)
         
     | 
| 
      
 27 
     | 
    
         
            +
            * [Dependencies](#dependencies)
         
     | 
| 
      
 28 
     | 
    
         
            +
            * [Usage](#usage)
         
     | 
| 
      
 29 
     | 
    
         
            +
            * [Manage services](#manage-services)
         
     | 
| 
      
 30 
     | 
    
         
            +
              * [Create a Systemdy Service object for control a service](#create-a-systemdy-service-object-for-control-a-service)
         
     | 
| 
      
 31 
     | 
    
         
            +
              * [Check if the provided service exist](#check-if-the-provided-service-exist)
         
     | 
| 
      
 32 
     | 
    
         
            +
              * [Check if the provided service is enabled](#check-if-the-provided-service-is-enabled)
         
     | 
| 
      
 33 
     | 
    
         
            +
              * [Check if the provided service is active](#check-if-the-provided-service-is-active)
         
     | 
| 
      
 34 
     | 
    
         
            +
              * [Check the current status of the provided service](#check-the-current-status-of-the-provided-service)
         
     | 
| 
      
 35 
     | 
    
         
            +
              * [Display all the properties for the provided service](#check-the-current-status-of-the-provided-service)
         
     | 
| 
      
 36 
     | 
    
         
            +
              * [Start the service](#start-the-service)
         
     | 
| 
      
 37 
     | 
    
         
            +
              * [Restart the service](#restart-the-service)
         
     | 
| 
      
 38 
     | 
    
         
            +
              * [Stop the service](#stop-the-service)
         
     | 
| 
      
 39 
     | 
    
         
            +
              * [Enable the service](#enable-the-service)
         
     | 
| 
      
 40 
     | 
    
         
            +
              * [Disable the service](#disable-the-service)
         
     | 
| 
      
 41 
     | 
    
         
            +
              * [Reload the service](#reload-the-service)
         
     | 
| 
      
 42 
     | 
    
         
            +
              * [Mask the service](#mask-the-service)
         
     | 
| 
      
 43 
     | 
    
         
            +
              * [Unmask the service](#unmask-the-service)
         
     | 
| 
      
 44 
     | 
    
         
            +
              * [Bonus tip: execute systemctl commands without prompt the password](#bonus-tip-execute-systemctl-commands-without-prompt-the-password)
         
     | 
| 
      
 45 
     | 
    
         
            +
            * [Manage Journalctl logs](#manage-journalctl-logs)
         
     | 
| 
      
 46 
     | 
    
         
            +
              * [Display kernel logs](#display-kernel-logs)
         
     | 
| 
      
 47 
     | 
    
         
            +
              * [Display boot logs](#display-boot-logs)
         
     | 
| 
      
 48 
     | 
    
         
            +
              * [Display unit logs](#display-unit-logs)
         
     | 
| 
      
 49 
     | 
    
         
            +
              * [Display group_id logs (GUID)](#display-group_id-logs-guid)
         
     | 
| 
      
 50 
     | 
    
         
            +
              * [Display user_id logs (UID)](#display-user_id-logs-uid)
         
     | 
| 
      
 51 
     | 
    
         
            +
            * [Contributing](#contributing)
         
     | 
| 
      
 52 
     | 
    
         
            +
              * [Develop a new feature](#develop-a-new-feature) 
         
     | 
| 
      
 53 
     | 
    
         
            +
              * [Fix a bug](#fix-a-bug) 
         
     | 
| 
      
 54 
     | 
    
         
            +
            * [Note for testing](#note-for-testing) 
         
     | 
| 
      
 55 
     | 
    
         
            +
            * [License](#license)
         
     | 
| 
      
 56 
     | 
    
         
            +
            * [Useful links and resources](#useful-links-and-resources)
         
     | 
| 
      
 57 
     | 
    
         
            +
            * [Acknowledgements](#acknowledgements) 
         
     | 
| 
      
 58 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
            Add this line to your application's Gemfile:
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 63 
     | 
    
         
            +
            gem 'systemdy'
         
     | 
| 
      
 64 
     | 
    
         
            +
            ```
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            And then execute:
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                $ bundle install
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            Or install it yourself as:
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                $ gem install systemdy
         
     | 
| 
      
 73 
     | 
    
         
            +
            ## Dependencies
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
            The only dependecy you need is [systemd](http://www.freedesktop.org/wiki/Software/systemdy/) installed on your system (specifically libsystemd or the older libsystemdy-journal) in order to use the gem. Currently the gem support systemd 249 or higher.
         
     | 
| 
      
 76 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
            After installing the gem, the first step is to require it:
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 81 
     | 
    
         
            +
            require 'systemdy'
         
     | 
| 
      
 82 
     | 
    
         
            +
            ```
         
     | 
| 
      
 83 
     | 
    
         
            +
            ## Manage services
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
            The first goal of this gem is to manage a systemd's service with minimal effort.
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
            This section provides an overview of the Systemdy::Service class for managing the life cycle of a systemdy's service.
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
            ### Create a Systemdy Service object for control a service
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
            The first step is to create a new instance of the systemdy::Service class for control the desired service
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 94 
     | 
    
         
            +
            my_postgresql_service = Systemdy::Service.new('postgresql')
         
     | 
| 
      
 95 
     | 
    
         
            +
            ```
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
            ### Check if the provided service exist
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
            Once our object has been instantiated, you can check if the service is installed on your system
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 102 
     | 
    
         
            +
            my_postgresql_service.exist?
         
     | 
| 
      
 103 
     | 
    
         
            +
            ```
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
            For check if a service is installed on your system without create a new instance of the Systemdy::Service class
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 108 
     | 
    
         
            +
            Systemdy::Utility::Validator.check_if_a_service_exist('postgresql')
         
     | 
| 
      
 109 
     | 
    
         
            +
            ```
         
     | 
| 
      
 110 
     | 
    
         
            +
            if the provided service is installed on your system this methods return _**true**_, otherwise return _**false**_.
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
            ### Check if the provided service is enabled
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
            For check if a service is enabled
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 117 
     | 
    
         
            +
            my_postgresql_service.is_enabled?
         
     | 
| 
      
 118 
     | 
    
         
            +
            ```
         
     | 
| 
      
 119 
     | 
    
         
            +
            if the provided service is enabled this method return _**true**_, otherwise return _**false**_.
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
            ### Check if the provided service is active
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
            For check if a service is active
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 126 
     | 
    
         
            +
            my_postgresql_service.is_active?
         
     | 
| 
      
 127 
     | 
    
         
            +
            ```
         
     | 
| 
      
 128 
     | 
    
         
            +
            if the provided service is active this method return _**true**_, otherwise return _**false**_.
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
            ### Check the current status of the provided service
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
            For check the current status of the service 
         
     | 
| 
      
 133 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 134 
     | 
    
         
            +
            my_postgresql_service.status
         
     | 
| 
      
 135 
     | 
    
         
            +
            ```
         
     | 
| 
      
 136 
     | 
    
         
            +
            Once executed, this method return an hash with all the essential service's information like this:
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 139 
     | 
    
         
            +
             { "Id"=>"postgresql.service",              
         
     | 
| 
      
 140 
     | 
    
         
            +
               "Description"=>"PostgreSQL RDBMS",          
         
     | 
| 
      
 141 
     | 
    
         
            +
               "ExecMainPID"=>"48615",
         
     | 
| 
      
 142 
     | 
    
         
            +
               "LoadState"=>"loaded",
         
     | 
| 
      
 143 
     | 
    
         
            +
               "ActiveState"=>"active",
         
     | 
| 
      
 144 
     | 
    
         
            +
               "FragmentPath"=>"/lib/systemd/system/postgresql.service",
         
     | 
| 
      
 145 
     | 
    
         
            +
               "ActiveEnterTimestamp"=>"Thu 2022-09-29 17:13:07 CEST",
         
     | 
| 
      
 146 
     | 
    
         
            +
               "InactiveEnterTimestamp"=>"Thu 2022-09-29 17:12:44 CEST",
         
     | 
| 
      
 147 
     | 
    
         
            +
               "ActiveExitTimestamp"=>"Thu 2022-09-29 17:12:44 CEST",
         
     | 
| 
      
 148 
     | 
    
         
            +
               "InactiveExitTimestamp"=>"Thu 2022-09-29 17:13:07 CEST"
         
     | 
| 
      
 149 
     | 
    
         
            +
             } 
         
     | 
| 
      
 150 
     | 
    
         
            +
            ```
         
     | 
| 
      
 151 
     | 
    
         
            +
            ### Display all the properties for the provided service
         
     | 
| 
      
 152 
     | 
    
         
            +
             
     | 
| 
      
 153 
     | 
    
         
            +
            For check all the properties of the service 
         
     | 
| 
      
 154 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 155 
     | 
    
         
            +
            my_postgresql_service.properties
         
     | 
| 
      
 156 
     | 
    
         
            +
            ```
         
     | 
| 
      
 157 
     | 
    
         
            +
            Once executed, this method return an hash with all the service's properties like this:
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 160 
     | 
    
         
            +
             { "Type"=>"oneshot",
         
     | 
| 
      
 161 
     | 
    
         
            +
                "Restart"=>"no",
         
     | 
| 
      
 162 
     | 
    
         
            +
                "NotifyAccess"=>"none",
         
     | 
| 
      
 163 
     | 
    
         
            +
                ....
         
     | 
| 
      
 164 
     | 
    
         
            +
             }
         
     | 
| 
      
 165 
     | 
    
         
            +
            ```
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
            To extract the value of a specific property
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
      
 169 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 170 
     | 
    
         
            +
            my_postgresql_service.properties["MemorySwapMax"]
         
     | 
| 
      
 171 
     | 
    
         
            +
            ```
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
            ### Start the service
         
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
      
 175 
     | 
    
         
            +
            For start the service 
         
     | 
| 
      
 176 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 177 
     | 
    
         
            +
            my_postgresql_service.start
         
     | 
| 
      
 178 
     | 
    
         
            +
            ```
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
            ### Restart the service
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
            For restart the service 
         
     | 
| 
      
 183 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 184 
     | 
    
         
            +
            my_postgresql_service.restart
         
     | 
| 
      
 185 
     | 
    
         
            +
            ```
         
     | 
| 
      
 186 
     | 
    
         
            +
             
     | 
| 
      
 187 
     | 
    
         
            +
            ### Stop the service
         
     | 
| 
      
 188 
     | 
    
         
            +
             
     | 
| 
      
 189 
     | 
    
         
            +
            For stop the service 
         
     | 
| 
      
 190 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 191 
     | 
    
         
            +
            my_postgresql_service.stop
         
     | 
| 
      
 192 
     | 
    
         
            +
            ```
         
     | 
| 
      
 193 
     | 
    
         
            +
             
     | 
| 
      
 194 
     | 
    
         
            +
            ### Enable the service
         
     | 
| 
      
 195 
     | 
    
         
            +
             
     | 
| 
      
 196 
     | 
    
         
            +
            For enable the service 
         
     | 
| 
      
 197 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 198 
     | 
    
         
            +
            my_postgresql_service.enable
         
     | 
| 
      
 199 
     | 
    
         
            +
            ```
         
     | 
| 
      
 200 
     | 
    
         
            +
             
     | 
| 
      
 201 
     | 
    
         
            +
            ### Disable the service
         
     | 
| 
      
 202 
     | 
    
         
            +
             
     | 
| 
      
 203 
     | 
    
         
            +
            For disable the service 
         
     | 
| 
      
 204 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 205 
     | 
    
         
            +
            my_postgresql_service.disable
         
     | 
| 
      
 206 
     | 
    
         
            +
            ```
         
     | 
| 
      
 207 
     | 
    
         
            +
             
     | 
| 
      
 208 
     | 
    
         
            +
            ### Reload the service
         
     | 
| 
      
 209 
     | 
    
         
            +
             
     | 
| 
      
 210 
     | 
    
         
            +
            For reload the service 
         
     | 
| 
      
 211 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 212 
     | 
    
         
            +
            my_postgresql_service.reload
         
     | 
| 
      
 213 
     | 
    
         
            +
            ```
         
     | 
| 
      
 214 
     | 
    
         
            +
             
     | 
| 
      
 215 
     | 
    
         
            +
            ### Mask the service
         
     | 
| 
      
 216 
     | 
    
         
            +
             
     | 
| 
      
 217 
     | 
    
         
            +
            For mask the service 
         
     | 
| 
      
 218 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 219 
     | 
    
         
            +
            my_postgresql_service.mask
         
     | 
| 
      
 220 
     | 
    
         
            +
            ```
         
     | 
| 
      
 221 
     | 
    
         
            +
            ### Unmask the service
         
     | 
| 
      
 222 
     | 
    
         
            +
             
     | 
| 
      
 223 
     | 
    
         
            +
            For unmask the service 
         
     | 
| 
      
 224 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 225 
     | 
    
         
            +
            my_postgresql_service.unmask
         
     | 
| 
      
 226 
     | 
    
         
            +
            ```
         
     | 
| 
      
 227 
     | 
    
         
            +
            ## Bonus tip: execute systemctl commands without prompt the password
         
     | 
| 
      
 228 
     | 
    
         
            +
             
     | 
| 
      
 229 
     | 
    
         
            +
            The methods **start**, **restart**, **stop**, **enable**, **disable**, **reload**, **mask** and **unmask** detect non-root users and automatically execute the methods with sudo.
         
     | 
| 
      
 230 
     | 
    
         
            +
             
     | 
| 
      
 231 
     | 
    
         
            +
            By default, sudo needs that a non-root user(in this case you) is authenticated using a password for complete the method execution. This is a great thing, but some times you may need to execute this methods without type the password. 
         
     | 
| 
      
 232 
     | 
    
         
            +
             
     | 
| 
      
 233 
     | 
    
         
            +
            In this case you need to configure sudo without a password.
         
     | 
| 
      
 234 
     | 
    
         
            +
             
     | 
| 
      
 235 
     | 
    
         
            +
            The first step for achieve this is gain root access:
         
     | 
| 
      
 236 
     | 
    
         
            +
             
     | 
| 
      
 237 
     | 
    
         
            +
            ```console
         
     | 
| 
      
 238 
     | 
    
         
            +
            non_root_user@my-machine:~$ sudo -i
         
     | 
| 
      
 239 
     | 
    
         
            +
            [sudo] password for non_root_user: 
         
     | 
| 
      
 240 
     | 
    
         
            +
            ```
         
     | 
| 
      
 241 
     | 
    
         
            +
             
     | 
| 
      
 242 
     | 
    
         
            +
            After provided the correct password backup your /etc/sudoers file by typing the following command:
         
     | 
| 
      
 243 
     | 
    
         
            +
             
     | 
| 
      
 244 
     | 
    
         
            +
            ```console
         
     | 
| 
      
 245 
     | 
    
         
            +
            root@my-machine:~# cp /etc/sudoers /root/sudoers.bak 
         
     | 
| 
      
 246 
     | 
    
         
            +
            ```
         
     | 
| 
      
 247 
     | 
    
         
            +
             
     | 
| 
      
 248 
     | 
    
         
            +
            Next step is edit the /etc/sudoers file by typing the visudo command:
         
     | 
| 
      
 249 
     | 
    
         
            +
             
     | 
| 
      
 250 
     | 
    
         
            +
            ```console
         
     | 
| 
      
 251 
     | 
    
         
            +
            root@my-machine:~# visudo 
         
     | 
| 
      
 252 
     | 
    
         
            +
            ```
         
     | 
| 
      
 253 
     | 
    
         
            +
             
     | 
| 
      
 254 
     | 
    
         
            +
            Append/edit the following lines in the /etc/sudoers file and substitute 'your_account_name' with your linux account name.
         
     | 
| 
      
 255 
     | 
    
         
            +
            ```console
         
     | 
| 
      
 256 
     | 
    
         
            +
            'your_account_name' ALL=(ALL) NOPASSWD: /bin/systemctl
         
     | 
| 
      
 257 
     | 
    
         
            +
            ```
         
     | 
| 
      
 258 
     | 
    
         
            +
             
     | 
| 
      
 259 
     | 
    
         
            +
            This line anable you to run ‘systemctl’ commands without a password. 
         
     | 
| 
      
 260 
     | 
    
         
            +
             
     | 
| 
      
 261 
     | 
    
         
            +
            Save with CTRL + X
         
     | 
| 
      
 262 
     | 
    
         
            +
             
     | 
| 
      
 263 
     | 
    
         
            +
            ```console
         
     | 
| 
      
 264 
     | 
    
         
            +
            root@my-machine:~# exit
         
     | 
| 
      
 265 
     | 
    
         
            +
            ```
         
     | 
| 
      
 266 
     | 
    
         
            +
            Exit from root session and you are ready to go! :sunglasses:
         
     | 
| 
      
 267 
     | 
    
         
            +
            ## Manage Journalctl logs
         
     | 
| 
      
 268 
     | 
    
         
            +
             
     | 
| 
      
 269 
     | 
    
         
            +
            The second goal of this gem is to provide a set of useful methods for retrieving journalctl log data.
         
     | 
| 
      
 270 
     | 
    
         
            +
             
     | 
| 
      
 271 
     | 
    
         
            +
            This section provides a brief overview of the Systemdy::Journal class for managing journalctl log information.
         
     | 
| 
      
 272 
     | 
    
         
            +
             
     | 
| 
      
 273 
     | 
    
         
            +
            ### Display kernel logs
         
     | 
| 
      
 274 
     | 
    
         
            +
             
     | 
| 
      
 275 
     | 
    
         
            +
            Sometimes we need to check if the kernel is working properly or if something went wrong to get useful information to help us fix the problem.
         
     | 
| 
      
 276 
     | 
    
         
            +
             
     | 
| 
      
 277 
     | 
    
         
            +
            For getting the kernel logs 
         
     | 
| 
      
 278 
     | 
    
         
            +
             
     | 
| 
      
 279 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 280 
     | 
    
         
            +
            Systemdy::Journal.display_kernel_logs
         
     | 
| 
      
 281 
     | 
    
         
            +
            ```
         
     | 
| 
      
 282 
     | 
    
         
            +
            This class method executed with no arguments return an array with: 
         
     | 
| 
      
 283 
     | 
    
         
            +
            * a default size of 10 (the last 10 lines of log)
         
     | 
| 
      
 284 
     | 
    
         
            +
            * a start period not older than '00:00 AM' o' clock (today)
         
     | 
| 
      
 285 
     | 
    
         
            +
            * an end period not newer than the method execution timenow
         
     | 
| 
      
 286 
     | 
    
         
            +
             
     | 
| 
      
 287 
     | 
    
         
            +
            Obviously this method allows you to filter the kernel logs by passing **3** positional arguments:
         
     | 
| 
      
 288 
     | 
    
         
            +
             
     | 
| 
      
 289 
     | 
    
         
            +
            * **since**: a start period not older than the specified date
         
     | 
| 
      
 290 
     | 
    
         
            +
             
     | 
| 
      
 291 
     | 
    
         
            +
            * **to**: an end period not older than the specified date
         
     | 
| 
      
 292 
     | 
    
         
            +
             
     | 
| 
      
 293 
     | 
    
         
            +
            * **lines**: the exact number of last log lines 
         
     | 
| 
      
 294 
     | 
    
         
            +
             
     | 
| 
      
 295 
     | 
    
         
            +
            For example:
         
     | 
| 
      
 296 
     | 
    
         
            +
             
     | 
| 
      
 297 
     | 
    
         
            +
            If you want to analyze the last 50 log lines ranging from a month ago to 10:00 of the current day:
         
     | 
| 
      
 298 
     | 
    
         
            +
             
     | 
| 
      
 299 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 300 
     | 
    
         
            +
            Systemdy::Journal.display_kernel_logs(since: '1 month ago', to: '10:00', lines: 50)
         
     | 
| 
      
 301 
     | 
    
         
            +
            ```
         
     | 
| 
      
 302 
     | 
    
         
            +
             
     | 
| 
      
 303 
     | 
    
         
            +
            If you want to analyze the last 20 log lines ranging from a week ago to yesterday:
         
     | 
| 
      
 304 
     | 
    
         
            +
             
     | 
| 
      
 305 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 306 
     | 
    
         
            +
            Systemdy::Journal.display_kernel_logs(since: '1 week ago', to: 'yesterday', lines: 20)
         
     | 
| 
      
 307 
     | 
    
         
            +
            ```
         
     | 
| 
      
 308 
     | 
    
         
            +
             
     | 
| 
      
 309 
     | 
    
         
            +
            You can also filter the logs by specific dates in the format YYYY-MM-DD for example:
         
     | 
| 
      
 310 
     | 
    
         
            +
             
     | 
| 
      
 311 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 312 
     | 
    
         
            +
            Systemdy::Journal.display_kernel_logs(since: '2022-08-27', lines: 200)
         
     | 
| 
      
 313 
     | 
    
         
            +
            ```
         
     | 
| 
      
 314 
     | 
    
         
            +
             
     | 
| 
      
 315 
     | 
    
         
            +
            If the passed arguments not match anything the method return an array with a message like this:
         
     | 
| 
      
 316 
     | 
    
         
            +
             
     | 
| 
      
 317 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 318 
     | 
    
         
            +
            ["-- No entries --"]
         
     | 
| 
      
 319 
     | 
    
         
            +
            ```
         
     | 
| 
      
 320 
     | 
    
         
            +
             
     | 
| 
      
 321 
     | 
    
         
            +
            ### Display boot logs
         
     | 
| 
      
 322 
     | 
    
         
            +
             
     | 
| 
      
 323 
     | 
    
         
            +
            Sometimes we need to know if our system is working properly at boot time and if something went wrong to get useful information to help us fix the problem.
         
     | 
| 
      
 324 
     | 
    
         
            +
             
     | 
| 
      
 325 
     | 
    
         
            +
            For getting the boot logs 
         
     | 
| 
      
 326 
     | 
    
         
            +
             
     | 
| 
      
 327 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 328 
     | 
    
         
            +
            Systemdy::Journal.display_boot_logs
         
     | 
| 
      
 329 
     | 
    
         
            +
            ```
         
     | 
| 
      
 330 
     | 
    
         
            +
            This class method executed with no arguments return an array with: 
         
     | 
| 
      
 331 
     | 
    
         
            +
            * a default size of 10 (the last 10 lines of log)
         
     | 
| 
      
 332 
     | 
    
         
            +
            * a start period not older than '00:00 AM' o' clock (today)
         
     | 
| 
      
 333 
     | 
    
         
            +
            * an end period not newer than the method execution timenow
         
     | 
| 
      
 334 
     | 
    
         
            +
             
     | 
| 
      
 335 
     | 
    
         
            +
            Obviously as for the previous method, you can filter the boot logs by passing **4** positional arguments:
         
     | 
| 
      
 336 
     | 
    
         
            +
             
     | 
| 
      
 337 
     | 
    
         
            +
            * **argument**: in this case the boot's number
         
     | 
| 
      
 338 
     | 
    
         
            +
             
     | 
| 
      
 339 
     | 
    
         
            +
            * **since**: a start period not older than the specified date
         
     | 
| 
      
 340 
     | 
    
         
            +
             
     | 
| 
      
 341 
     | 
    
         
            +
            * **to**: an end period not older than the specified date
         
     | 
| 
      
 342 
     | 
    
         
            +
             
     | 
| 
      
 343 
     | 
    
         
            +
            * **lines**: the exact number of last log lines 
         
     | 
| 
      
 344 
     | 
    
         
            +
             
     | 
| 
      
 345 
     | 
    
         
            +
            For example:
         
     | 
| 
      
 346 
     | 
    
         
            +
             
     | 
| 
      
 347 
     | 
    
         
            +
            If you want to analyze the last 50 log lines of the second boot ranging from a month ago to 10:00 of the current day:
         
     | 
| 
      
 348 
     | 
    
         
            +
             
     | 
| 
      
 349 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 350 
     | 
    
         
            +
            Systemdy::Journal.display_boot_logs(argument: 2, since: '1 month ago', to: '10:00', lines: 50)
         
     | 
| 
      
 351 
     | 
    
         
            +
            ```
         
     | 
| 
      
 352 
     | 
    
         
            +
             
     | 
| 
      
 353 
     | 
    
         
            +
            If you want to analyze the last 20 log of the third boot lines ranging from a week ago to yesterday:
         
     | 
| 
      
 354 
     | 
    
         
            +
             
     | 
| 
      
 355 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 356 
     | 
    
         
            +
            Systemdy::Journal.display_boot_logs(argument: 3, since: '1 week ago', to: 'yesterday', lines: 20)
         
     | 
| 
      
 357 
     | 
    
         
            +
            ```
         
     | 
| 
      
 358 
     | 
    
         
            +
             
     | 
| 
      
 359 
     | 
    
         
            +
            You can also filter the logs by specific dates in the format YYYY-MM-DD for example:
         
     | 
| 
      
 360 
     | 
    
         
            +
             
     | 
| 
      
 361 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 362 
     | 
    
         
            +
            Systemdy::Journal.display_boot_logs(since: '2022-08-27', lines: 200)
         
     | 
| 
      
 363 
     | 
    
         
            +
            ```
         
     | 
| 
      
 364 
     | 
    
         
            +
            If the passed arguments not match anything the method return an array with a message like this:
         
     | 
| 
      
 365 
     | 
    
         
            +
             
     | 
| 
      
 366 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 367 
     | 
    
         
            +
            ["-- No entries --"]
         
     | 
| 
      
 368 
     | 
    
         
            +
            ```
         
     | 
| 
      
 369 
     | 
    
         
            +
             
     | 
| 
      
 370 
     | 
    
         
            +
            ### Display unit logs
         
     | 
| 
      
 371 
     | 
    
         
            +
             
     | 
| 
      
 372 
     | 
    
         
            +
            Another common task is to filter logs based on the unit that we need information on. 
         
     | 
| 
      
 373 
     | 
    
         
            +
             
     | 
| 
      
 374 
     | 
    
         
            +
            To do this, we just simply need to pass the name of the unit as argument, for example we need to analyze postgresql unit logs:
         
     | 
| 
      
 375 
     | 
    
         
            +
             
     | 
| 
      
 376 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 377 
     | 
    
         
            +
            Systemdy::Journal.display_unit_logs(argument: 'postgresql')
         
     | 
| 
      
 378 
     | 
    
         
            +
            ```
         
     | 
| 
      
 379 
     | 
    
         
            +
             
     | 
| 
      
 380 
     | 
    
         
            +
            In this case the class method return an array with: 
         
     | 
| 
      
 381 
     | 
    
         
            +
            * a default size of 10 (the last 10 lines of log)
         
     | 
| 
      
 382 
     | 
    
         
            +
            * a start period not older than '00:00 AM' o' clock (today)
         
     | 
| 
      
 383 
     | 
    
         
            +
            * an end period not newer than the method execution timenow
         
     | 
| 
      
 384 
     | 
    
         
            +
             
     | 
| 
      
 385 
     | 
    
         
            +
            Obviously this method require the unit's name as argument, if executed with no arguments return a message like this:
         
     | 
| 
      
 386 
     | 
    
         
            +
             
     | 
| 
      
 387 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 388 
     | 
    
         
            +
            "display_unit_logs require an argument!"
         
     | 
| 
      
 389 
     | 
    
         
            +
            ```
         
     | 
| 
      
 390 
     | 
    
         
            +
             
     | 
| 
      
 391 
     | 
    
         
            +
            Obviously as for the previous method, you can filter the unit logs by passing **4** positional arguments:
         
     | 
| 
      
 392 
     | 
    
         
            +
             
     | 
| 
      
 393 
     | 
    
         
            +
            * **argument**: in this case the unit's name
         
     | 
| 
      
 394 
     | 
    
         
            +
             
     | 
| 
      
 395 
     | 
    
         
            +
            * **since**: a start period not older than the specified date
         
     | 
| 
      
 396 
     | 
    
         
            +
             
     | 
| 
      
 397 
     | 
    
         
            +
            * **to**: an end period not older than the specified date
         
     | 
| 
      
 398 
     | 
    
         
            +
             
     | 
| 
      
 399 
     | 
    
         
            +
            * **lines**: the exact number of last log lines 
         
     | 
| 
      
 400 
     | 
    
         
            +
             
     | 
| 
      
 401 
     | 
    
         
            +
            For example:
         
     | 
| 
      
 402 
     | 
    
         
            +
             
     | 
| 
      
 403 
     | 
    
         
            +
            If you want to analyze the last 50 log lines of the potsgresql service ranging from a month ago to 10:00 of the current day:
         
     | 
| 
      
 404 
     | 
    
         
            +
             
     | 
| 
      
 405 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 406 
     | 
    
         
            +
            Systemdy::Journal.display_unit_logs(argument: 'postgresql', since: '1 month ago', to: '10:00', lines: 50)
         
     | 
| 
      
 407 
     | 
    
         
            +
            ```
         
     | 
| 
      
 408 
     | 
    
         
            +
             
     | 
| 
      
 409 
     | 
    
         
            +
            If you want to analyze the last 20 log lines of the potsgresql service ranging from a week ago to yesterday:
         
     | 
| 
      
 410 
     | 
    
         
            +
             
     | 
| 
      
 411 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 412 
     | 
    
         
            +
            Systemdy::Journal.display_unit_logs(argument: 'postgresql', since: '1 week ago', to: 'yesterday', lines: 20)
         
     | 
| 
      
 413 
     | 
    
         
            +
            ```
         
     | 
| 
      
 414 
     | 
    
         
            +
             
     | 
| 
      
 415 
     | 
    
         
            +
            You can also filter the logs by specific dates in the format YYYY-MM-DD for example:
         
     | 
| 
      
 416 
     | 
    
         
            +
             
     | 
| 
      
 417 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 418 
     | 
    
         
            +
            Systemdy::Journal.display_unit_logs(argument: 'postgresql', since: '2022-08-27', lines: 200)
         
     | 
| 
      
 419 
     | 
    
         
            +
            ```
         
     | 
| 
      
 420 
     | 
    
         
            +
             
     | 
| 
      
 421 
     | 
    
         
            +
            If the passed arguments not match anything the method return an array with a message like this:
         
     | 
| 
      
 422 
     | 
    
         
            +
             
     | 
| 
      
 423 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 424 
     | 
    
         
            +
            ["-- No entries --"]
         
     | 
| 
      
 425 
     | 
    
         
            +
            ```
         
     | 
| 
      
 426 
     | 
    
         
            +
             
     | 
| 
      
 427 
     | 
    
         
            +
            ### Display group_id logs (GUID)
         
     | 
| 
      
 428 
     | 
    
         
            +
             
     | 
| 
      
 429 
     | 
    
         
            +
            To find all messages related to a particular group, we just simply need to pass the GUID of the group as argument, for example:
         
     | 
| 
      
 430 
     | 
    
         
            +
             
     | 
| 
      
 431 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 432 
     | 
    
         
            +
            Systemdy::Journal.display_group_id_logs(argument: 1000)
         
     | 
| 
      
 433 
     | 
    
         
            +
            ```
         
     | 
| 
      
 434 
     | 
    
         
            +
             
     | 
| 
      
 435 
     | 
    
         
            +
            In this case the class method return an array with: 
         
     | 
| 
      
 436 
     | 
    
         
            +
            * a default size of 10 (the last 10 lines of log)
         
     | 
| 
      
 437 
     | 
    
         
            +
            * a start period not older than '00:00 AM' o' clock (today)
         
     | 
| 
      
 438 
     | 
    
         
            +
            * an end period not newer than the method execution timenow
         
     | 
| 
      
 439 
     | 
    
         
            +
             
     | 
| 
      
 440 
     | 
    
         
            +
            Obviously this method require the GUID as argument, if executed with no arguments return a message like this:
         
     | 
| 
      
 441 
     | 
    
         
            +
             
     | 
| 
      
 442 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 443 
     | 
    
         
            +
            "display_group_id_logs require an argument!"
         
     | 
| 
      
 444 
     | 
    
         
            +
            ```
         
     | 
| 
      
 445 
     | 
    
         
            +
             
     | 
| 
      
 446 
     | 
    
         
            +
            Obviously as for the previous method, you can filter the GUID logs by passing **4** positional arguments:
         
     | 
| 
      
 447 
     | 
    
         
            +
             
     | 
| 
      
 448 
     | 
    
         
            +
            * **argument**: in this case the GUID
         
     | 
| 
      
 449 
     | 
    
         
            +
             
     | 
| 
      
 450 
     | 
    
         
            +
            * **since**: a start period not older than the specified date
         
     | 
| 
      
 451 
     | 
    
         
            +
             
     | 
| 
      
 452 
     | 
    
         
            +
            * **to**: an end period not older than the specified date
         
     | 
| 
      
 453 
     | 
    
         
            +
             
     | 
| 
      
 454 
     | 
    
         
            +
            * **lines**: the exact number of last log lines 
         
     | 
| 
      
 455 
     | 
    
         
            +
             
     | 
| 
      
 456 
     | 
    
         
            +
            For example:
         
     | 
| 
      
 457 
     | 
    
         
            +
             
     | 
| 
      
 458 
     | 
    
         
            +
            If you want to analyze the last 50 log lines of the GUID 1000 ranging from a month ago to 10:00 of the current day:
         
     | 
| 
      
 459 
     | 
    
         
            +
             
     | 
| 
      
 460 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 461 
     | 
    
         
            +
            Systemdy::Journal.display_group_id_logs(argument: 1000, since: '1 month ago', to: '10:00', lines: 50)
         
     | 
| 
      
 462 
     | 
    
         
            +
            ```
         
     | 
| 
      
 463 
     | 
    
         
            +
             
     | 
| 
      
 464 
     | 
    
         
            +
            If you want to analyze the last 20 log lines of the GUID 1000 ranging from a week ago to yesterday:
         
     | 
| 
      
 465 
     | 
    
         
            +
             
     | 
| 
      
 466 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 467 
     | 
    
         
            +
            Systemdy::Journal.display_group_id_logs(argument: 1000, since: '1 week ago', to: 'yesterday', lines: 20)
         
     | 
| 
      
 468 
     | 
    
         
            +
            ```
         
     | 
| 
      
 469 
     | 
    
         
            +
             
     | 
| 
      
 470 
     | 
    
         
            +
            You can also filter the logs by specific dates in the format YYYY-MM-DD for example:
         
     | 
| 
      
 471 
     | 
    
         
            +
             
     | 
| 
      
 472 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 473 
     | 
    
         
            +
            Systemdy::Journal.display_group_id_logs(argument: 1000, since: '2022-08-27', lines: 200)
         
     | 
| 
      
 474 
     | 
    
         
            +
            ```
         
     | 
| 
      
 475 
     | 
    
         
            +
             
     | 
| 
      
 476 
     | 
    
         
            +
            If the passed arguments not match anything the method return an array with a message like this:
         
     | 
| 
      
 477 
     | 
    
         
            +
             
     | 
| 
      
 478 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 479 
     | 
    
         
            +
            ["-- No entries --"]
         
     | 
| 
      
 480 
     | 
    
         
            +
            ```
         
     | 
| 
      
 481 
     | 
    
         
            +
             
     | 
| 
      
 482 
     | 
    
         
            +
            ### Display user_id logs (UID)
         
     | 
| 
      
 483 
     | 
    
         
            +
             
     | 
| 
      
 484 
     | 
    
         
            +
            To find all messages related to a particular user, we just simply need to pass the UID of the user as argument, for example:
         
     | 
| 
      
 485 
     | 
    
         
            +
             
     | 
| 
      
 486 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 487 
     | 
    
         
            +
            Systemdy::Journal.display_user_id_logs(argument: 1000)
         
     | 
| 
      
 488 
     | 
    
         
            +
            ```
         
     | 
| 
      
 489 
     | 
    
         
            +
             
     | 
| 
      
 490 
     | 
    
         
            +
            In this case the class method return an array with: 
         
     | 
| 
      
 491 
     | 
    
         
            +
            * a default size of 10 (the last 10 lines of log)
         
     | 
| 
      
 492 
     | 
    
         
            +
            * a start period not older than '00:00 AM' o' clock (today)
         
     | 
| 
      
 493 
     | 
    
         
            +
            * an end period not newer than the method execution timenow
         
     | 
| 
      
 494 
     | 
    
         
            +
             
     | 
| 
      
 495 
     | 
    
         
            +
            Obviously this method require the UID as argument, if executed with no arguments return a message like this:
         
     | 
| 
      
 496 
     | 
    
         
            +
             
     | 
| 
      
 497 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 498 
     | 
    
         
            +
            "display_user_id_logs require an argument!"
         
     | 
| 
      
 499 
     | 
    
         
            +
            ```
         
     | 
| 
      
 500 
     | 
    
         
            +
             
     | 
| 
      
 501 
     | 
    
         
            +
            Obviously as for the previous method, you can filter the UID logs by passing **4** positional arguments:
         
     | 
| 
      
 502 
     | 
    
         
            +
             
     | 
| 
      
 503 
     | 
    
         
            +
            * **argument**: in this case the UID
         
     | 
| 
      
 504 
     | 
    
         
            +
             
     | 
| 
      
 505 
     | 
    
         
            +
            * **since**: a start period not older than the specified date
         
     | 
| 
      
 506 
     | 
    
         
            +
             
     | 
| 
      
 507 
     | 
    
         
            +
            * **to**: an end period not older than the specified date
         
     | 
| 
      
 508 
     | 
    
         
            +
             
     | 
| 
      
 509 
     | 
    
         
            +
            * **lines**: the exact number of last log lines 
         
     | 
| 
      
 510 
     | 
    
         
            +
             
     | 
| 
      
 511 
     | 
    
         
            +
            For example:
         
     | 
| 
      
 512 
     | 
    
         
            +
             
     | 
| 
      
 513 
     | 
    
         
            +
            If you want to analyze the last 50 log lines of the UID 1000 ranging from a month ago to 10:00 of the current day:
         
     | 
| 
      
 514 
     | 
    
         
            +
             
     | 
| 
      
 515 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 516 
     | 
    
         
            +
            Systemdy::Journal.display_user_id_logs(argument: 1000, since: '1 month ago', to: '10:00', lines: 50)
         
     | 
| 
      
 517 
     | 
    
         
            +
            ```
         
     | 
| 
      
 518 
     | 
    
         
            +
             
     | 
| 
      
 519 
     | 
    
         
            +
            If you want to analyze the last 20 log lines of the UID 1000 ranging from a week ago to yesterday:
         
     | 
| 
      
 520 
     | 
    
         
            +
             
     | 
| 
      
 521 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 522 
     | 
    
         
            +
            Systemdy::Journal.display_user_id_logs(argument: 1000, since: '1 week ago', to: 'yesterday', lines: 20)
         
     | 
| 
      
 523 
     | 
    
         
            +
            ```
         
     | 
| 
      
 524 
     | 
    
         
            +
             
     | 
| 
      
 525 
     | 
    
         
            +
            You can also filter the logs by specific dates in the format YYYY-MM-DD for example:
         
     | 
| 
      
 526 
     | 
    
         
            +
             
     | 
| 
      
 527 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 528 
     | 
    
         
            +
            Systemdy::Journal.display_user_id_logs(argument: 1000, since: '2022-08-27', lines: 200)
         
     | 
| 
      
 529 
     | 
    
         
            +
            ```
         
     | 
| 
      
 530 
     | 
    
         
            +
             
     | 
| 
      
 531 
     | 
    
         
            +
            If the passed arguments not match anything the method return an array with a message like this:
         
     | 
| 
      
 532 
     | 
    
         
            +
             
     | 
| 
      
 533 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 534 
     | 
    
         
            +
            ["-- No entries --"]
         
     | 
| 
      
 535 
     | 
    
         
            +
            ```
         
     | 
| 
      
 536 
     | 
    
         
            +
            ## Contributing
         
     | 
| 
      
 537 
     | 
    
         
            +
             
     | 
| 
      
 538 
     | 
    
         
            +
            We :heart: pull requests from everyone. 
         
     | 
| 
      
 539 
     | 
    
         
            +
             
     | 
| 
      
 540 
     | 
    
         
            +
            Everyone interacting in the systemdy project's codebases is expected to follow the [code of conduct](https://github.com/magic4dev/systemdy/blob/master/CODE_OF_CONDUCT.md).
         
     | 
| 
      
 541 
     | 
    
         
            +
             
     | 
| 
      
 542 
     | 
    
         
            +
            ### Develop a new feature
         
     | 
| 
      
 543 
     | 
    
         
            +
             
     | 
| 
      
 544 
     | 
    
         
            +
            If you wanna develop a new feature:
         
     | 
| 
      
 545 
     | 
    
         
            +
             
     | 
| 
      
 546 
     | 
    
         
            +
            * Fork this project
         
     | 
| 
      
 547 
     | 
    
         
            +
             
     | 
| 
      
 548 
     | 
    
         
            +
            * Clone the repo with the following command:
         
     | 
| 
      
 549 
     | 
    
         
            +
             
     | 
| 
      
 550 
     | 
    
         
            +
                  git clone git@github.com:your-username/systemdy.git
         
     | 
| 
      
 551 
     | 
    
         
            +
             
     | 
| 
      
 552 
     | 
    
         
            +
            * Install dependencies with:
         
     | 
| 
      
 553 
     | 
    
         
            +
             
     | 
| 
      
 554 
     | 
    
         
            +
                  bin/setup
         
     | 
| 
      
 555 
     | 
    
         
            +
             
     | 
| 
      
 556 
     | 
    
         
            +
            * Make your changes
         
     | 
| 
      
 557 
     | 
    
         
            +
            * Write tests. 
         
     | 
| 
      
 558 
     | 
    
         
            +
             
     | 
| 
      
 559 
     | 
    
         
            +
                **NOTE**: For a correct testing procedure read our [Note for testing](#note-for-testing)
         
     | 
| 
      
 560 
     | 
    
         
            +
            * Make the tests pass with the following command:
         
     | 
| 
      
 561 
     | 
    
         
            +
             
     | 
| 
      
 562 
     | 
    
         
            +
                  rake spec
         
     | 
| 
      
 563 
     | 
    
         
            +
             
     | 
| 
      
 564 
     | 
    
         
            +
            * Add notes about your changes to the `CHANGELOG.md` file
         
     | 
| 
      
 565 
     | 
    
         
            +
             
     | 
| 
      
 566 
     | 
    
         
            +
            * Write a good commit message
         
     | 
| 
      
 567 
     | 
    
         
            +
            * Push to your fork
         
     | 
| 
      
 568 
     | 
    
         
            +
            * [Submit a pull request](https://github.com/magic4dev/systemdy/compare)
         
     | 
| 
      
 569 
     | 
    
         
            +
            * Wait for us, we will reply as soon as possible
         
     | 
| 
      
 570 
     | 
    
         
            +
            * We may suggest changes for better code quality
         
     | 
| 
      
 571 
     | 
    
         
            +
            * Please, if you push more than mone commit let's keep the history clean :stuck_out_tongue_winking_eye:
         
     | 
| 
      
 572 
     | 
    
         
            +
             
     | 
| 
      
 573 
     | 
    
         
            +
            Thank you for your contribution! :handshake:
         
     | 
| 
      
 574 
     | 
    
         
            +
             
     | 
| 
      
 575 
     | 
    
         
            +
            ### Fix a bug
         
     | 
| 
      
 576 
     | 
    
         
            +
             
     | 
| 
      
 577 
     | 
    
         
            +
            If you wanna fix a bug:
         
     | 
| 
      
 578 
     | 
    
         
            +
             
     | 
| 
      
 579 
     | 
    
         
            +
            * Fork this project
         
     | 
| 
      
 580 
     | 
    
         
            +
             
     | 
| 
      
 581 
     | 
    
         
            +
            * Clone the repo with the following command:
         
     | 
| 
      
 582 
     | 
    
         
            +
             
     | 
| 
      
 583 
     | 
    
         
            +
                  git clone git@github.com:your-username/systemdy.git
         
     | 
| 
      
 584 
     | 
    
         
            +
             
     | 
| 
      
 585 
     | 
    
         
            +
            * Install dependencies with:
         
     | 
| 
      
 586 
     | 
    
         
            +
             
     | 
| 
      
 587 
     | 
    
         
            +
                  bin/setup
         
     | 
| 
      
 588 
     | 
    
         
            +
             
     | 
| 
      
 589 
     | 
    
         
            +
            * Make your changes
         
     | 
| 
      
 590 
     | 
    
         
            +
            * Write tests. 
         
     | 
| 
      
 591 
     | 
    
         
            +
             
     | 
| 
      
 592 
     | 
    
         
            +
                **NOTE**: For a correct testing procedure read our [Note for testing](#note-for-testing)
         
     | 
| 
      
 593 
     | 
    
         
            +
            * Make the tests pass with the following command:
         
     | 
| 
      
 594 
     | 
    
         
            +
             
     | 
| 
      
 595 
     | 
    
         
            +
                  rake spec
         
     | 
| 
      
 596 
     | 
    
         
            +
             
     | 
| 
      
 597 
     | 
    
         
            +
            * Add notes about your changes to the `CHANGELOG.md` file
         
     | 
| 
      
 598 
     | 
    
         
            +
             
     | 
| 
      
 599 
     | 
    
         
            +
            * Write a good commit message
         
     | 
| 
      
 600 
     | 
    
         
            +
            * Push to your fork
         
     | 
| 
      
 601 
     | 
    
         
            +
            * [Submit a pull request](https://github.com/magic4dev/systemdy/compare)
         
     | 
| 
      
 602 
     | 
    
         
            +
            * Wait for us, we will reply as soon as possible
         
     | 
| 
      
 603 
     | 
    
         
            +
            * We may suggest changes for better code quality
         
     | 
| 
      
 604 
     | 
    
         
            +
            * Please, if you push more than mone commit let's keep the history clean :stuck_out_tongue_winking_eye:
         
     | 
| 
      
 605 
     | 
    
         
            +
             
     | 
| 
      
 606 
     | 
    
         
            +
            Thank you for your contribution! :handshake:
         
     | 
| 
      
 607 
     | 
    
         
            +
             
     | 
| 
      
 608 
     | 
    
         
            +
            ## Note for testing
         
     | 
| 
      
 609 
     | 
    
         
            +
             
     | 
| 
      
 610 
     | 
    
         
            +
            This gem was tested on a __postgresql__ service. 
         
     | 
| 
      
 611 
     | 
    
         
            +
                
         
     | 
| 
      
 612 
     | 
    
         
            +
            For better testing install __postgresql__ service on your system.
         
     | 
| 
      
 613 
     | 
    
         
            +
                
         
     | 
| 
      
 614 
     | 
    
         
            +
            If you don't want to install it:
         
     | 
| 
      
 615 
     | 
    
         
            +
                
         
     | 
| 
      
 616 
     | 
    
         
            +
            * go to _spec/setup/test_variables.rb_ 
         
     | 
| 
      
 617 
     | 
    
         
            +
             
     | 
| 
      
 618 
     | 
    
         
            +
            and replace: 
         
     | 
| 
      
 619 
     | 
    
         
            +
             
     | 
| 
      
 620 
     | 
    
         
            +
            * let (:real_service_name) { 'postgresql' }
         
     | 
| 
      
 621 
     | 
    
         
            +
             
     | 
| 
      
 622 
     | 
    
         
            +
            with:
         
     | 
| 
      
 623 
     | 
    
         
            +
             
     | 
| 
      
 624 
     | 
    
         
            +
            * let (:real_service_name) { 'a_installed_service_on_your_system' }
         
     | 
| 
      
 625 
     | 
    
         
            +
             
     | 
| 
      
 626 
     | 
    
         
            +
            ## License
         
     | 
| 
      
 627 
     | 
    
         
            +
             
     | 
| 
      
 628 
     | 
    
         
            +
            The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
         
     | 
| 
      
 629 
     | 
    
         
            +
             
     | 
| 
      
 630 
     | 
    
         
            +
            ## Useful links and resources
         
     | 
| 
      
 631 
     | 
    
         
            +
             
     | 
| 
      
 632 
     | 
    
         
            +
             - An interesting article on [how to run sudo commands without password](https://www.linuxshelltips.com/run-sudo-commands-without-password/)
         
     | 
| 
      
 633 
     | 
    
         
            +
             - The official systemdy documentation for [time specification](https://www.freedesktop.org/software/systemd/man/systemd.time.html)
         
     | 
| 
      
 634 
     | 
    
         
            +
             
         
     | 
| 
      
 635 
     | 
    
         
            +
            ## Acknowledgements
         
     | 
| 
      
 636 
     | 
    
         
            +
             
     | 
| 
      
 637 
     | 
    
         
            +
             - Thanks to [@colstrom](https://github.com/colstrom) and his [systemized](https://github.com/colstrom/systemized) for the great inspiration 
         
     | 
    
        data/Rakefile
    ADDED
    
    
| 
         @@ -0,0 +1,115 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Systemdy
         
     | 
| 
      
 2 
     | 
    
         
            +
                class Journal 
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
                    # extend SingleForwardableForwardable standard's library module for delegate a specified method to a designated object
         
     | 
| 
      
 5 
     | 
    
         
            +
                    extend SingleForwardable
         
     | 
| 
      
 6 
     | 
    
         
            +
                           
         
     | 
| 
      
 7 
     | 
    
         
            +
                    # list of options for execute journalctl command that not accept arguments
         
     | 
| 
      
 8 
     | 
    
         
            +
                    # Example command: journalctl -k
         
     | 
| 
      
 9 
     | 
    
         
            +
                    # the '-k' option not accept arguments
         
     | 
| 
      
 10 
     | 
    
         
            +
                    # journalctl -k [argument] return
         
     | 
| 
      
 11 
     | 
    
         
            +
                    # Failed to add match [argument]: Invalid argument
         
     | 
| 
      
 12 
     | 
    
         
            +
                    LIST_OF_OPTIONS_THAT_NOT_ACCEPT_ARGUMENTS = { kernel: '-k' }
         
     | 
| 
      
 13 
     | 
    
         
            +
                    
         
     | 
| 
      
 14 
     | 
    
         
            +
                    # list of options for execute journalctl command that accept arguments
         
     | 
| 
      
 15 
     | 
    
         
            +
                    # Example command: journalctl -b
         
     | 
| 
      
 16 
     | 
    
         
            +
                    # the '-b' option accept an argument (the number of the boot)
         
     | 
| 
      
 17 
     | 
    
         
            +
                    # journalctl -b postgresql return the boots's logs
         
     | 
| 
      
 18 
     | 
    
         
            +
                    # journalctl -b 3 return the third of the availables boot logs
         
     | 
| 
      
 19 
     | 
    
         
            +
                    LIST_OF_OPTIONS_THAT_ACCEPT_AN_ARGUMENT   = { boot: '-b' }
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    # list of options for execute journalctl command that require arguments
         
     | 
| 
      
 22 
     | 
    
         
            +
                    # Example command: journalctl -u
         
     | 
| 
      
 23 
     | 
    
         
            +
                    # the '-u' option require an argument (the name of the unit)
         
     | 
| 
      
 24 
     | 
    
         
            +
                    # journalctl -u postgresql return the postgresql's logs
         
     | 
| 
      
 25 
     | 
    
         
            +
                    # journalctl -u without an argument return
         
     | 
| 
      
 26 
     | 
    
         
            +
                    # journalctl: option requires an argument -- 'u' 
         
     | 
| 
      
 27 
     | 
    
         
            +
                    LIST_OF_OPTIONS_THAT_REQUIRE_AN_ARGUMENT  = { unit: '-u', group_id: '_GID', user_id: '_UID' }
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                    # we delegate return_an_array_from_system_command method to Systemdy::Utility::Formatter class contained in Systemdy/utility/formatter.rb
         
     | 
| 
      
 30 
     | 
    
         
            +
                    def_delegator Systemdy::Utility::Formatter,        :return_an_array_from_system_command
         
     | 
| 
      
 31 
     | 
    
         
            +
                    # we delegate render_message method to Systemdy::Utility::MessageDisplayer class contained in Systemdy/utility/message_displayer.rb
         
     | 
| 
      
 32 
     | 
    
         
            +
                    def_delegator Systemdy::Utility::MessageDisplayer, :render_message 
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                    # create dynamically class methods based on LIST_OF_OPTIONS_THAT_NOT_ACCEPT_ARGUMENTS constant
         
     | 
| 
      
 35 
     | 
    
         
            +
                    # we can call the methods:
         
     | 
| 
      
 36 
     | 
    
         
            +
                    # Systemdy::Journal.display_kernel_logs
         
     | 
| 
      
 37 
     | 
    
         
            +
                    # this method accept 3 keyword arguments:
         
     | 
| 
      
 38 
     | 
    
         
            +
                    # 1. since ('the log's initial period')  - String  - default 'yesterday' 
         
     | 
| 
      
 39 
     | 
    
         
            +
                    # 2. to    ('the log's end period')      - String  - default Time.now.strftime('%H:%M')
         
     | 
| 
      
 40 
     | 
    
         
            +
                    # 3. lines ('the log's number of lines') - Integer - default 10 .display_kernel_logs
         
     | 
| 
      
 41 
     | 
    
         
            +
                    # Example:
         
     | 
| 
      
 42 
     | 
    
         
            +
                    # Systemdy::Journal.display_kernel_logs(since: '1 month ago', lines: 50)
         
     | 
| 
      
 43 
     | 
    
         
            +
                    # if you call this method without arguments
         
     | 
| 
      
 44 
     | 
    
         
            +
                    # - it return an array with 10 lines of logs
         
     | 
| 
      
 45 
     | 
    
         
            +
                    LIST_OF_OPTIONS_THAT_NOT_ACCEPT_ARGUMENTS.each do |message_from, option|
         
     | 
| 
      
 46 
     | 
    
         
            +
                        define_singleton_method "display_#{message_from}_logs" do |since: 'today', to: Time.now.strftime('%H:%M'), lines: 10|
         
     | 
| 
      
 47 
     | 
    
         
            +
                            # logs from system call
         
     | 
| 
      
 48 
     | 
    
         
            +
                            logs = `#{JOURNALCTL_COMMAND} #{option} -S '#{since}' -U '#{to}' -n #{lines} | tail -n #{lines} 2>&1`
         
     | 
| 
      
 49 
     | 
    
         
            +
                            # logs from system call converted into array
         
     | 
| 
      
 50 
     | 
    
         
            +
                            return_an_array_from_system_command(logs) # class method contained in Systemdy/utility/formatter.rb
         
     | 
| 
      
 51 
     | 
    
         
            +
                        end
         
     | 
| 
      
 52 
     | 
    
         
            +
                    end
         
     | 
| 
      
 53 
     | 
    
         
            +
                    
         
     | 
| 
      
 54 
     | 
    
         
            +
                    # create dynamically class methods based on LIST_OF_OPTIONS_THAT_ACCEPT_AN_ARGUMENT constant
         
     | 
| 
      
 55 
     | 
    
         
            +
                    # we can call the methods:
         
     | 
| 
      
 56 
     | 
    
         
            +
                    # Systemdy::Journal.display_boot_logs
         
     | 
| 
      
 57 
     | 
    
         
            +
                    # this method accept 4 keyword arguments:
         
     | 
| 
      
 58 
     | 
    
         
            +
                    # 1. argument ('the boot's number')      - Integer - optional
         
     | 
| 
      
 59 
     | 
    
         
            +
                    # 2. since ('the log's initial period')  - String  - default 'yesterday' 
         
     | 
| 
      
 60 
     | 
    
         
            +
                    # 3. to    ('the log's end period')      - String  - default Time.now.strftime('%H:%M')
         
     | 
| 
      
 61 
     | 
    
         
            +
                    # 4. lines ('the log's number of lines') - Integer - default 10 
         
     | 
| 
      
 62 
     | 
    
         
            +
                    # Example:
         
     | 
| 
      
 63 
     | 
    
         
            +
                    # Systemdy::Journal.display_boot_logs(argument: 3, since: '1 month ago', lines: 50)
         
     | 
| 
      
 64 
     | 
    
         
            +
                    # if you call this method without arguments
         
     | 
| 
      
 65 
     | 
    
         
            +
                    # - it return an array with 10 lines of logs
         
     | 
| 
      
 66 
     | 
    
         
            +
                    LIST_OF_OPTIONS_THAT_ACCEPT_AN_ARGUMENT.each do |message_from, option|
         
     | 
| 
      
 67 
     | 
    
         
            +
                        define_singleton_method "display_#{message_from}_logs" do |argument: '', since: 'today', to: Time.now.strftime('%H:%M'), lines: 10|
         
     | 
| 
      
 68 
     | 
    
         
            +
                            # logs from system call
         
     | 
| 
      
 69 
     | 
    
         
            +
                            logs = `#{JOURNALCTL_COMMAND} #{option} #{argument} -S '#{since}' -U '#{to}' -n #{lines} | tail -n #{lines} 2>&1`
         
     | 
| 
      
 70 
     | 
    
         
            +
                            # logs from system call converted into array
         
     | 
| 
      
 71 
     | 
    
         
            +
                            return_an_array_from_system_command(logs) # class method contained in Systemdy/utility/formatter.rb
         
     | 
| 
      
 72 
     | 
    
         
            +
                        end
         
     | 
| 
      
 73 
     | 
    
         
            +
                    end
         
     | 
| 
      
 74 
     | 
    
         
            +
                    
         
     | 
| 
      
 75 
     | 
    
         
            +
                    # create dynamically class methods based on LIST_OF_OPTIONS_THAT_REQUIRE_AN_ARGUMENT constant
         
     | 
| 
      
 76 
     | 
    
         
            +
                    # we can call the methods:
         
     | 
| 
      
 77 
     | 
    
         
            +
                    # Systemdy::Journal.display_unit_logs
         
     | 
| 
      
 78 
     | 
    
         
            +
                    # Systemdy::Journal.display_group_id_logs
         
     | 
| 
      
 79 
     | 
    
         
            +
                    # Systemdy::Journal.display_user_id_logs
         
     | 
| 
      
 80 
     | 
    
         
            +
                    # this method accept 4 keyword arguments:
         
     | 
| 
      
 81 
     | 
    
         
            +
                    # 1. argument ('the unit, the group_id or user_id) - String  - required
         
     | 
| 
      
 82 
     | 
    
         
            +
                    # 2. since ('the log's initial period')  - String  - default 'yesterday' 
         
     | 
| 
      
 83 
     | 
    
         
            +
                    # 3. to    ('the log's end period')      - String  - default Time.now.strftime('%H:%M')
         
     | 
| 
      
 84 
     | 
    
         
            +
                    # 4. lines ('the log's number of lines') - Integer - default 10 
         
     | 
| 
      
 85 
     | 
    
         
            +
                    # Example:
         
     | 
| 
      
 86 
     | 
    
         
            +
                    # Systemdy::Journal.display_unit_logs(argument: 'postgresql', since: '1 month ago', lines: 50)
         
     | 
| 
      
 87 
     | 
    
         
            +
                    # Systemdy::Journal.display_user_id_logs(argument: 1000, since: '1 month ago', lines: 50)
         
     | 
| 
      
 88 
     | 
    
         
            +
                    # Systemdy::Journal.display_group_id_logs(argument: 1000, since: '1 month ago', lines: 50)
         
     | 
| 
      
 89 
     | 
    
         
            +
                    LIST_OF_OPTIONS_THAT_REQUIRE_AN_ARGUMENT.each do |message_from, option|
         
     | 
| 
      
 90 
     | 
    
         
            +
                        define_singleton_method "display_#{message_from}_logs" do |argument: '', since: 'today', to: Time.now.strftime('%H:%M'), lines: 10|
         
     | 
| 
      
 91 
     | 
    
         
            +
                            # return an error message if the required argument is not provided
         
     | 
| 
      
 92 
     | 
    
         
            +
                            # render_message class method contained in Systemdy/utility/message_displayer.rb
         
     | 
| 
      
 93 
     | 
    
         
            +
                            return render_message("display_#{message_from}_logs require an argument!") if argument.to_s.empty?
         
     | 
| 
      
 94 
     | 
    
         
            +
                            # combination of option and argument based on typology
         
     | 
| 
      
 95 
     | 
    
         
            +
                            # '-u postgresql' or '_GUID=1000' or '_UID=1000'
         
     | 
| 
      
 96 
     | 
    
         
            +
                            option_with_argument = merge_option_with_argument_based_on_option_typology(message_from, option, argument)
         
     | 
| 
      
 97 
     | 
    
         
            +
                            # logs from system call
         
     | 
| 
      
 98 
     | 
    
         
            +
                            logs                 = `#{JOURNALCTL_COMMAND} #{option_with_argument} -S '#{since}' -U '#{to}' | tail -n #{lines} 2>&1`
         
     | 
| 
      
 99 
     | 
    
         
            +
                            # logs from system call converted into array
         
     | 
| 
      
 100 
     | 
    
         
            +
                            return_an_array_from_system_command(logs) # class method contained in Systemdy/utility/formatter.rb
         
     | 
| 
      
 101 
     | 
    
         
            +
                        end
         
     | 
| 
      
 102 
     | 
    
         
            +
                    end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                    # method for return formatted option
         
     | 
| 
      
 105 
     | 
    
         
            +
                    # Example
         
     | 
| 
      
 106 
     | 
    
         
            +
                    # merge_option_with_argument_based_on_option_typology(:unit, '-u', 'postgresql') return '-u postgresql'
         
     | 
| 
      
 107 
     | 
    
         
            +
                    # merge_option_with_argument_based_on_option_typology(:group_id, '_GUID', 1234566) return '_GUID=1000'
         
     | 
| 
      
 108 
     | 
    
         
            +
                    def self.merge_option_with_argument_based_on_option_typology(message_from, option, argument)
         
     | 
| 
      
 109 
     | 
    
         
            +
                        message_from == :unit ? "#{option} #{argument}" : "#{option}=#{argument}"
         
     | 
| 
      
 110 
     | 
    
         
            +
                    end
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                    # make the methods below as private
         
     | 
| 
      
 113 
     | 
    
         
            +
                    private_class_method :return_an_array_from_system_command, :render_message, :merge_option_with_argument_based_on_option_typology
         
     | 
| 
      
 114 
     | 
    
         
            +
                end 
         
     | 
| 
      
 115 
     | 
    
         
            +
            end    
         
     | 
| 
         @@ -0,0 +1,122 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Systemdy
         
     | 
| 
      
 2 
     | 
    
         
            +
                class Service 
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
                    # extend Forwardable standard's library module for delegate a specified method to a designated object
         
     | 
| 
      
 5 
     | 
    
         
            +
                    extend Forwardable
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                    # list of supported actions on a provided service
         
     | 
| 
      
 8 
     | 
    
         
            +
                    LIST_OF_ACTIONS           = %w( start restart stop enable disable reload mask unmask )
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                    # list of supported statuses on a provided service
         
     | 
| 
      
 11 
     | 
    
         
            +
                    LIST_OF_STATUSES          = %w( enabled active )
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                    # list of status properties on a provided service when status command is called
         
     | 
| 
      
 14 
     | 
    
         
            +
                    LIST_OF_STATUS_PROPERTIES = %w( Id Description ExecMainPID LoadState ActiveState FragmentPath 
         
     | 
| 
      
 15 
     | 
    
         
            +
                                                    ActiveEnterTimestamp InactiveEnterTimestamp ActiveExitTimestamp 
         
     | 
| 
      
 16 
     | 
    
         
            +
                                                    InactiveExitTimestamp 
         
     | 
| 
      
 17 
     | 
    
         
            +
                                                )
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                    attr_reader :command, :name
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    # we create a new object that accept 1 argument:
         
     | 
| 
      
 22 
     | 
    
         
            +
                    # 1. the name of the Systemdy service to control (postgresql, redis etc..)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    # Example:
         
     | 
| 
      
 24 
     | 
    
         
            +
                    # my_postgresql_service = Systemdy::Service.new('postgresql')
         
     | 
| 
      
 25 
     | 
    
         
            +
                    def initialize(name)
         
     | 
| 
      
 26 
     | 
    
         
            +
                        @command   = SYSTEMCTL_COMMAND # constant contained in Systemdy.rb
         
     | 
| 
      
 27 
     | 
    
         
            +
                        @name      = name 
         
     | 
| 
      
 28 
     | 
    
         
            +
                    end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                    # we delegate return_an_array_from_system_command method to Systemdy::Utility::Formatter class contained in Systemdy/utility/formatter.rb
         
     | 
| 
      
 31 
     | 
    
         
            +
                    def_delegator Systemdy::Utility::Formatter,        :return_an_array_from_system_command
         
     | 
| 
      
 32 
     | 
    
         
            +
                    # we delegate render_message method to Systemdy::Utility::MessageDisplayer class contained in Systemdy/utility/message_displayer.rb
         
     | 
| 
      
 33 
     | 
    
         
            +
                    def_delegator Systemdy::Utility::MessageDisplayer, :render_message 
         
     | 
| 
      
 34 
     | 
    
         
            +
                    # we delegate check_if_a_service_exist method to Systemdy::Utility::Validator class contained in Systemdy/utility/validator.rb
         
     | 
| 
      
 35 
     | 
    
         
            +
                    def_delegator Systemdy::Utility::Validator,        :check_if_a_service_exist 
         
     | 
| 
      
 36 
     | 
    
         
            +
                    # we delegate filter_by_keys method to Systemdy::Utility::KeyValueFilter class contained in Systemdy/utility/key_value.rb
         
     | 
| 
      
 37 
     | 
    
         
            +
                    def_delegator Systemdy::Utility::KeyValueFilter,   :filter_by_keys 
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                    # method for check if a created service exist
         
     | 
| 
      
 40 
     | 
    
         
            +
                    # Example:
         
     | 
| 
      
 41 
     | 
    
         
            +
                    # my_postgresql_service.exist?
         
     | 
| 
      
 42 
     | 
    
         
            +
                    # if the provided service exist this method return
         
     | 
| 
      
 43 
     | 
    
         
            +
                    # - true
         
     | 
| 
      
 44 
     | 
    
         
            +
                    # otherwise return
         
     | 
| 
      
 45 
     | 
    
         
            +
                    # - false
         
     | 
| 
      
 46 
     | 
    
         
            +
                    def exist? 
         
     | 
| 
      
 47 
     | 
    
         
            +
                        check_if_a_service_exist(name) # class method contained in Systemdy/utility/validator.rb
         
     | 
| 
      
 48 
     | 
    
         
            +
                    end
         
     | 
| 
      
 49 
     | 
    
         
            +
                    
         
     | 
| 
      
 50 
     | 
    
         
            +
                    # create dynamically methods based on LIST_OF_ACTIONS constant
         
     | 
| 
      
 51 
     | 
    
         
            +
                    # after created a new object we can call the methods:
         
     | 
| 
      
 52 
     | 
    
         
            +
                    # my_postgresql_service.start
         
     | 
| 
      
 53 
     | 
    
         
            +
                    # my_postgresql_service.restart
         
     | 
| 
      
 54 
     | 
    
         
            +
                    # my_postgresql_service.stop
         
     | 
| 
      
 55 
     | 
    
         
            +
                    # my_postgresql_service.enable
         
     | 
| 
      
 56 
     | 
    
         
            +
                    # my_postgresql_service.disable
         
     | 
| 
      
 57 
     | 
    
         
            +
                    # my_postgresql_service.reload
         
     | 
| 
      
 58 
     | 
    
         
            +
                    # my_postgresql_service.mask
         
     | 
| 
      
 59 
     | 
    
         
            +
                    # my_postgresql_service.unmask
         
     | 
| 
      
 60 
     | 
    
         
            +
                    LIST_OF_ACTIONS.each do |action|
         
     | 
| 
      
 61 
     | 
    
         
            +
                        define_method action do 
         
     | 
| 
      
 62 
     | 
    
         
            +
                            sudo_command = Etc.getpwuid(Process.uid).name != 'root' ? 'sudo' : ''
         
     | 
| 
      
 63 
     | 
    
         
            +
                            exist? ? `#{sudo_command} #{command} #{action} #{name}` : default_error_message()
         
     | 
| 
      
 64 
     | 
    
         
            +
                        end
         
     | 
| 
      
 65 
     | 
    
         
            +
                    end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                    # method for return a key/value pair of the provided service's properties
         
     | 
| 
      
 68 
     | 
    
         
            +
                    # Example:
         
     | 
| 
      
 69 
     | 
    
         
            +
                    # my_postgresql_service.properties
         
     | 
| 
      
 70 
     | 
    
         
            +
                    # return a key/value pair of the provided service's properties
         
     | 
| 
      
 71 
     | 
    
         
            +
                    # { "Type"=>"oneshot",
         
     | 
| 
      
 72 
     | 
    
         
            +
                    #   "Restart"=>"no",
         
     | 
| 
      
 73 
     | 
    
         
            +
                    #   "NotifyAccess"=>"none",
         
     | 
| 
      
 74 
     | 
    
         
            +
                    #   ....
         
     | 
| 
      
 75 
     | 
    
         
            +
                    # }
         
     | 
| 
      
 76 
     | 
    
         
            +
                    def properties
         
     | 
| 
      
 77 
     | 
    
         
            +
                        array_of_properties = return_an_array_from_system_command(`#{command} show #{name}`)
         
     | 
| 
      
 78 
     | 
    
         
            +
                        array_of_properties.collect { |property| { property.split('=')[0] => property.split('=')[1] } }.reduce({}, :merge)
         
     | 
| 
      
 79 
     | 
    
         
            +
                    end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                    # method for return the current status of the provided service
         
     | 
| 
      
 82 
     | 
    
         
            +
                    # Example:
         
     | 
| 
      
 83 
     | 
    
         
            +
                    # my_postgresql_service.status
         
     | 
| 
      
 84 
     | 
    
         
            +
                    # return a key/value pair of the provided service's status
         
     | 
| 
      
 85 
     | 
    
         
            +
                    # { "Id"=>"postgresql.service",              
         
     | 
| 
      
 86 
     | 
    
         
            +
                    #   "Description"=>"PostgreSQL RDBMS",          
         
     | 
| 
      
 87 
     | 
    
         
            +
                    #   "ExecMainPID"=>"48615",
         
     | 
| 
      
 88 
     | 
    
         
            +
                    #   "LoadState"=>"loaded",
         
     | 
| 
      
 89 
     | 
    
         
            +
                    #   "ActiveState"=>"active",
         
     | 
| 
      
 90 
     | 
    
         
            +
                    #   "FragmentPath"=>"/lib/Systemdy/system/postgresql.service",
         
     | 
| 
      
 91 
     | 
    
         
            +
                    #   "ActiveEnterTimestamp"=>"Thu 2022-09-29 17:13:07 CEST",
         
     | 
| 
      
 92 
     | 
    
         
            +
                    #   "InactiveEnterTimestamp"=>"Thu 2022-09-29 17:12:44 CEST",
         
     | 
| 
      
 93 
     | 
    
         
            +
                    #   "ActiveExitTimestamp"=>"Thu 2022-09-29 17:12:44 CEST",
         
     | 
| 
      
 94 
     | 
    
         
            +
                    #   "InactiveExitTimestamp"=>"Thu 2022-09-29 17:13:07 CEST"
         
     | 
| 
      
 95 
     | 
    
         
            +
                    # } 
         
     | 
| 
      
 96 
     | 
    
         
            +
                    def status 
         
     | 
| 
      
 97 
     | 
    
         
            +
                        exist? ? filter_by_keys(properties, LIST_OF_STATUS_PROPERTIES) : default_error_message()
         
     | 
| 
      
 98 
     | 
    
         
            +
                    end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                    # create dynamically methods based on LIST_OF_STATUSES constant
         
     | 
| 
      
 101 
     | 
    
         
            +
                    # after created a new object we can call the methods:
         
     | 
| 
      
 102 
     | 
    
         
            +
                    # my_postgresql_service.is_enabled?
         
     | 
| 
      
 103 
     | 
    
         
            +
                    # my_postgresql_service.is_active?
         
     | 
| 
      
 104 
     | 
    
         
            +
                    # if the provided service is active or enabled this method return
         
     | 
| 
      
 105 
     | 
    
         
            +
                    # - true
         
     | 
| 
      
 106 
     | 
    
         
            +
                    # otherwise return
         
     | 
| 
      
 107 
     | 
    
         
            +
                    # - false
         
     | 
| 
      
 108 
     | 
    
         
            +
                    LIST_OF_STATUSES.each do |status|
         
     | 
| 
      
 109 
     | 
    
         
            +
                        define_method "is_#{status}?" do 
         
     | 
| 
      
 110 
     | 
    
         
            +
                            exist? ? return_an_array_from_system_command(`#{command} is-#{status} #{name}`).include?(status) : default_error_message()
         
     | 
| 
      
 111 
     | 
    
         
            +
                        end
         
     | 
| 
      
 112 
     | 
    
         
            +
                    end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                    # method for display error when a service or unit not exist
         
     | 
| 
      
 115 
     | 
    
         
            +
                    def default_error_message
         
     | 
| 
      
 116 
     | 
    
         
            +
                        render_message("Unit #{name}.service could not be found.") # class method contained in Systemdy/utility/message_displayer.rb
         
     | 
| 
      
 117 
     | 
    
         
            +
                    end
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                    # make the methods below as private
         
     | 
| 
      
 120 
     | 
    
         
            +
                    private :render_message, :default_error_message, :return_an_array_from_system_command, :filter_by_keys 
         
     | 
| 
      
 121 
     | 
    
         
            +
                end
         
     | 
| 
      
 122 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Systemdy
         
     | 
| 
      
 2 
     | 
    
         
            +
                module Utility 
         
     | 
| 
      
 3 
     | 
    
         
            +
                    class Formatter
         
     | 
| 
      
 4 
     | 
    
         
            +
                        # method for convert `` system call to array based list
         
     | 
| 
      
 5 
     | 
    
         
            +
                        def self.return_an_array_from_system_command(system_call)
         
     | 
| 
      
 6 
     | 
    
         
            +
                            # remove \n from system call returned value
         
     | 
| 
      
 7 
     | 
    
         
            +
                            system_call_without_new_line = system_call.chomp!
         
     | 
| 
      
 8 
     | 
    
         
            +
                            # return system error message 
         
     | 
| 
      
 9 
     | 
    
         
            +
                            return(system_call_without_new_line) if !$?.success?
         
     | 
| 
      
 10 
     | 
    
         
            +
                            # convert `` system call to array based list
         
     | 
| 
      
 11 
     | 
    
         
            +
                            system_call_without_new_line.split(/\n/)
         
     | 
| 
      
 12 
     | 
    
         
            +
                        end
         
     | 
| 
      
 13 
     | 
    
         
            +
                    end
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,13 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Systemdy
         
     | 
| 
      
 2 
     | 
    
         
            +
                module Utility 
         
     | 
| 
      
 3 
     | 
    
         
            +
                    class Validator
         
     | 
| 
      
 4 
     | 
    
         
            +
                        # method for check if a service exist
         
     | 
| 
      
 5 
     | 
    
         
            +
                        def self.check_if_a_service_exist(service)
         
     | 
| 
      
 6 
     | 
    
         
            +
                            `#{SYSTEMCTL_COMMAND} list-unit-files #{service}.service | wc -l`.to_i > 3
         
     | 
| 
      
 7 
     | 
    
         
            +
                            # 'systemctl list-unit-files name_of_service.service | wc -l' command output:
         
     | 
| 
      
 8 
     | 
    
         
            +
                            #  3  when there are not matching units
         
     | 
| 
      
 9 
     | 
    
         
            +
                            #  >3 when there are matching units
         
     | 
| 
      
 10 
     | 
    
         
            +
                        end
         
     | 
| 
      
 11 
     | 
    
         
            +
                    end
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/systemdy.rb
    ADDED
    
    | 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            # external gems or standard's library modules
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "forwardable"
         
     | 
| 
      
 5 
     | 
    
         
            +
            require "etc"
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            # systemdy's class and modules
         
     | 
| 
      
 8 
     | 
    
         
            +
            require_relative "systemdy/version"
         
     | 
| 
      
 9 
     | 
    
         
            +
            require_relative "systemdy/utility/validator"
         
     | 
| 
      
 10 
     | 
    
         
            +
            require_relative "systemdy/utility/formatter"
         
     | 
| 
      
 11 
     | 
    
         
            +
            require_relative "systemdy/utility/message_displayer"
         
     | 
| 
      
 12 
     | 
    
         
            +
            require_relative "systemdy/utility/key_value_filter"
         
     | 
| 
      
 13 
     | 
    
         
            +
            require_relative "systemdy/service"
         
     | 
| 
      
 14 
     | 
    
         
            +
            require_relative "systemdy/journal"
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            module Systemdy
         
     | 
| 
      
 17 
     | 
    
         
            +
              class Error < StandardError; end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              # systemctl command
         
     | 
| 
      
 20 
     | 
    
         
            +
              SYSTEMCTL_COMMAND  = 'systemctl'
         
     | 
| 
      
 21 
     | 
    
         
            +
              # journalctl command
         
     | 
| 
      
 22 
     | 
    
         
            +
              JOURNALCTL_COMMAND = 'journalctl'
         
     | 
| 
      
 23 
     | 
    
         
            +
            end
         
     | 
    
        data/sig/systemdy.rbs
    ADDED
    
    
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,63 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: systemdy
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.0
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - magic4dev
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: exe
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2022-10-03 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: 
         
     | 
| 
      
 14 
     | 
    
         
            +
            email: magic4dev@gmail.com
         
     | 
| 
      
 15 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 16 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 17 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            files:
         
     | 
| 
      
 19 
     | 
    
         
            +
            - ".rspec"
         
     | 
| 
      
 20 
     | 
    
         
            +
            - CHANGELOG.md
         
     | 
| 
      
 21 
     | 
    
         
            +
            - CODE_OF_CONDUCT.md
         
     | 
| 
      
 22 
     | 
    
         
            +
            - Gemfile
         
     | 
| 
      
 23 
     | 
    
         
            +
            - Gemfile.lock
         
     | 
| 
      
 24 
     | 
    
         
            +
            - LICENSE.txt
         
     | 
| 
      
 25 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 26 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 27 
     | 
    
         
            +
            - lib/systemdy.rb
         
     | 
| 
      
 28 
     | 
    
         
            +
            - lib/systemdy/journal.rb
         
     | 
| 
      
 29 
     | 
    
         
            +
            - lib/systemdy/service.rb
         
     | 
| 
      
 30 
     | 
    
         
            +
            - lib/systemdy/utility/formatter.rb
         
     | 
| 
      
 31 
     | 
    
         
            +
            - lib/systemdy/utility/key_value_filter.rb
         
     | 
| 
      
 32 
     | 
    
         
            +
            - lib/systemdy/utility/message_displayer.rb
         
     | 
| 
      
 33 
     | 
    
         
            +
            - lib/systemdy/utility/validator.rb
         
     | 
| 
      
 34 
     | 
    
         
            +
            - lib/systemdy/version.rb
         
     | 
| 
      
 35 
     | 
    
         
            +
            - sig/systemdy.rbs
         
     | 
| 
      
 36 
     | 
    
         
            +
            homepage: https://github.com/magic4dev/systemd
         
     | 
| 
      
 37 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 38 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 39 
     | 
    
         
            +
            metadata:
         
     | 
| 
      
 40 
     | 
    
         
            +
              homepage_uri: https://github.com/magic4dev/systemd
         
     | 
| 
      
 41 
     | 
    
         
            +
              source_code_uri: https://github.com/magic4dev/systemd
         
     | 
| 
      
 42 
     | 
    
         
            +
              changelog_uri: https://github.com/magic4dev/systemd/blob/master/CHANGELOG.md
         
     | 
| 
      
 43 
     | 
    
         
            +
              code_of_conduct_uri: https://github.com/magic4dev/systemd/blob/master/CODE_OF_CONDUCT.md
         
     | 
| 
      
 44 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 45 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 46 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 47 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 48 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 49 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 50 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 51 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 52 
     | 
    
         
            +
                  version: 2.6.0
         
     | 
| 
      
 53 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 54 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 55 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 56 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 57 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 58 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 59 
     | 
    
         
            +
            rubygems_version: 3.3.7
         
     | 
| 
      
 60 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 61 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 62 
     | 
    
         
            +
            summary: A lightweight gem for interact with systemd
         
     | 
| 
      
 63 
     | 
    
         
            +
            test_files: []
         
     |