项目作者: k-ta-yamada

项目描述 :
This gem provide `ssc` command to check multiple `systemd service` etc on multiple remote servers using net-ssh.
高级语言: Ruby
项目地址: git://github.com/k-ta-yamada/systemd_service_check.git
创建时间: 2018-01-23T04:55:07Z
项目社区:https://github.com/k-ta-yamada/systemd_service_check

开源协议:MIT License

下载


Gem Version
Build Status
Downloads
Inline docs
Code Climate
Test Coverage

SystemdServiceCheck

This gem provide ssc command to check multiple systemd service
etc on multiple remote servers using net-ssh.

Installation

Add this line to your application’s Gemfile:

  1. gem 'systemd_service_check'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install systemd_service_check

Usage

configure yaml

sample file: ./systemd_service_check.sample.yml

usage at require: SystemdServiceCheck::Base.new(yaml: './path/to/setting.yml')

usage as CLI: ssc check -y ./path/to/setting.yml

Usage at require 'systemd_service_check'

  1. require 'systemd_service_check'
  2. envs = ['dev', 'stg']
  3. yaml = './your_settings.yml'
  4. role = 'app'
  5. ssc = SystemdServiceCheck::Base.new(envs, yaml, role)
  6. puts ssc.to_json

Usage as CLI ssc

  1. $ ssc help
  2. Commands:
  3. ssc check ENV [ENV...] [options] # check target ENV Servers.
  4. ssc help [COMMAND] # Describe available commands or one specific command
  5. ssc version # return SystemdServiceCheck::VERSION
  1. $ ssc help check
  2. Usage:
  3. ssc check [ENV [ENV...]] [options]
  4. Options:
  5. -y, [--yaml=YAML] # setting yaml file
  6. # Default: ./systemd_service_check.sample.yml
  7. -r, [--role=ROLE] # Target the specified role
  8. -f, [--format=FORMAT] # [t]able, [j]son, [a]wesome_print
  9. # Default: table
  10. check target ENV Servers.
  11. If `ENV` is omitted, the value of the first env of servers described in yaml is used.
  12. If `all` is specified for `ENV`, all ENVs are targeted.
  1. $ ssc check
  2. ENV | ROLE | IP | HOSTNAME | USER | SERVICE_NAME | LOAD_STATE | ACTIVE_STATE | SUB_STATE | UNIT_FILE_STATE | TYPE
  3. ----|------|---------------|----------|------|--------------------------------|------------|--------------|-----------|-----------------|--------
  4. dev | | 192.168.1.101 | centos7 | root | sshd.service | loaded | active | running | enabled | notify
  5. dev | | 192.168.1.101 | centos7 | root | firewalld.service | loaded | inactive | dead | disabled | dbus
  6. dev | | 192.168.1.101 | centos7 | root | rsyslog.service | loaded | active | running | enabled | notify
  7. dev | | 192.168.1.101 | centos7 | root | network.service | loaded | active | exited | bad | forking
  8. dev | | 192.168.1.101 | centos7 | root | systemd-tmpfiles-clean.timer | loaded | active | waiting | static |
  9. dev | | 192.168.1.101 | centos7 | root | dummy_long_name_size_30_______ | not-found | inactive | dead | |
  10. ENV | ROLE | IP | HOSTNAME | USER | SERVICE_NAME | LOAD_STATE | ACTIVE_STATE | SUB_STATE | UNIT_FILE_STATE | TYPE
  11. ----|------|---------------|----------|------|---------------|------------|--------------|-----------|-----------------|-------
  12. dev | ap | 192.168.1.101 | centos7 | root | sshd.service | loaded | active | running | enabled | notify
  13. dev | ap | 192.168.1.101 | centos7 | root | nginx.service | not-found | inactive | dead | |
  14. ENV | ROLE | IP | HOSTNAME | USER | SERVICE_NAME | LOAD_STATE | ACTIVE_STATE | SUB_STATE | UNIT_FILE_STATE | TYPE
  15. ----|------|---------------|----------|------|--------------------|------------|--------------|-----------|-----------------|-------
  16. dev | db | 192.168.1.101 | centos7 | root | sshd.service | loaded | active | running | enabled | notify
  17. dev | db | 192.168.1.101 | centos7 | root | postgresql.service | not-found | inactive | dead | |
  18. dev | db | 192.168.1.101 | centos7 | root | pgpool.service | not-found | inactive | dead | |

role

  1. $ ssc check --role ap
  2. ENV | ROLE | IP | HOSTNAME | USER | SERVICE_NAME | LOAD_STATE | ACTIVE_STATE | SUB_STATE | UNIT_FILE_STATE | TYPE
  3. ----|------|---------------|----------|------|---------------|------------|--------------|-----------|-----------------|-------
  4. dev | ap | 192.168.1.101 | centos7 | root | sshd.service | loaded | active | running | enabled | notify
  5. dev | ap | 192.168.1.101 | centos7 | root | nginx.service | not-found | inactive | dead | |
  1. $ ssc check --role db
  2. ENV | ROLE | IP | HOSTNAME | USER | SERVICE_NAME | LOAD_STATE | ACTIVE_STATE | SUB_STATE | UNIT_FILE_STATE | TYPE
  3. ----|------|---------------|----------|------|--------------------|------------|--------------|-----------|-----------------|-------
  4. dev | db | 192.168.1.101 | centos7 | root | sshd.service | loaded | active | running | enabled | notify
  5. dev | db | 192.168.1.101 | centos7 | root | postgresql.service | not-found | inactive | dead | |
  6. dev | db | 192.168.1.101 | centos7 | root | pgpool.service | not-found | inactive | dead | |
  1. $ ssc check all --role db
  2. ENV | ROLE | IP | HOSTNAME | USER | SERVICE_NAME | LOAD_STATE | ACTIVE_STATE | SUB_STATE | UNIT_FILE_STATE | TYPE
  3. ----|------|---------------|----------|------|--------------------|------------|--------------|-----------|-----------------|-------
  4. dev | db | 192.168.1.101 | centos7 | root | sshd.service | loaded | active | running | enabled | notify
  5. dev | db | 192.168.1.101 | centos7 | root | postgresql.service | not-found | inactive | dead | |
  6. dev | db | 192.168.1.101 | centos7 | root | pgpool.service | not-found | inactive | dead | |
  7. ENV | ROLE | IP | HOSTNAME | USER | SERVICE_NAME | LOAD_STATE | ACTIVE_STATE | SUB_STATE | UNIT_FILE_STATE | TYPE
  8. ----|------|---------------|----------|------|--------------------|------------|--------------|-----------|-----------------|-------
  9. stg | db | 192.168.1.101 | centos7 | root | sshd.service | loaded | active | running | enabled | notify
  10. stg | db | 192.168.1.101 | centos7 | root | postgresql.service | not-found | inactive | dead | |
  11. stg | db | 192.168.1.101 | centos7 | root | pgpool.service | not-found | inactive | dead | |
  12. ENV | ROLE | IP | HOSTNAME | USER | SERVICE_NAME | LOAD_STATE | ACTIVE_STATE | SUB_STATE | UNIT_FILE_STATE | TYPE
  13. ----|------|---------------|----------|------|--------------------|------------|--------------|-----------|-----------------|-------
  14. prd | db | 192.168.1.101 | centos7 | root | sshd.service | loaded | active | running | enabled | notify
  15. prd | db | 192.168.1.101 | centos7 | root | postgresql.service | not-found | inactive | dead | |
  16. prd | db | 192.168.1.101 | centos7 | root | pgpool.service | not-found | inactive | dead | |

formatting sample

  1. $ ssc check --format=json | jq
  2. [
  3. {
  4. "server": {
  5. "env": "dev",
  6. "role": null,
  7. "ip": "192.168.1.101",
  8. "user": "root",
  9. "options": {
  10. "password": "vagrant",
  11. "keys": [
  12. ""
  13. ],
  14. "logger": "#<Logger:0x00007fba5bb2d730>",
  15. "password_prompt": "#<Net::SSH::Prompt:0x00007fba5bb2d5a0>",
  16. "user": "root"
  17. },
  18. "services": [
  19. "sshd.service",
  20. ...,
  21. "dummy_long_name_size_30_______"
  22. ],
  23. "hostname": "centos7"
  24. },
  25. "services": [
  26. {
  27. "service_name": "sshd.service",
  28. "load_state": "loaded",
  29. "active_state": "active",
  30. "sub_state": "running",
  31. "unit_file_state": "enabled",
  32. "type": "notify"
  33. },
  34. ...,
  35. {
  36. "service_name": "dummy_long_name_size_30_______",
  37. "load_state": "not-found",
  38. "active_state": "inactive",
  39. "sub_state": "dead",
  40. "unit_file_state": null,
  41. "type": null
  42. }
  43. ]
  44. },
  45. ...,
  46. {
  47. "server": {
  48. "env": "dev",
  49. "role": "db",
  50. "ip": "192.168.1.101",
  51. "user": "root",
  52. "options": {
  53. "password": "vagrant",
  54. "keys": [
  55. ""
  56. ],
  57. "logger": "#<Logger:0x00007fba5bad2c90>",
  58. "password_prompt": "#<Net::SSH::Prompt:0x00007fba5bb2d5a0>",
  59. "user": "root"
  60. },
  61. "services": [
  62. "sshd.service",
  63. "postgresql.service",
  64. "pgpool.service"
  65. ],
  66. "hostname": "centos7"
  67. },
  68. "services": [
  69. {
  70. "service_name": "sshd.service",
  71. "load_state": "loaded",
  72. "active_state": "active",
  73. "sub_state": "running",
  74. "unit_file_state": "enabled",
  75. "type": "notify"
  76. },
  77. ...,
  78. {
  79. "service_name": "pgpool.service",
  80. "load_state": "not-found",
  81. "active_state": "inactive",
  82. "sub_state": "dead",
  83. "unit_file_state": null,
  84. "type": null
  85. }
  86. ]
  87. }
  88. ]
  1. $ ssc check --format=awesome_print
  2. [
  3. [0] #<Struct:SystemdServiceCheck::SSH::Result:0x7fb39db78678
  4. server = #<Struct:SystemdServiceCheck::Base::Server:0x7fb39dac6ec8
  5. env = "dev",
  6. hostname = "centos7",
  7. ip = "192.168.1.101",
  8. options = {
  9. :password => "vagrant",
  10. :keys => [
  11. [0] ""
  12. ],
  13. :logger => #<Logger:0x00007fb39dac5d98 @level=4, @progname=nil, @default_formatter=#<Logger::Formatter:0x00007fb39dac5cf8 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0x00007fb39dac5ca8 @shift_period_suffix=nil, @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDERR>>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x00007fb39dac5c30>>>,
  14. :password_prompt => #<Net::SSH::Prompt:0x00007fb39dac5bb8>,
  15. :user => "root"
  16. },
  17. role = nil,
  18. services = [
  19. [0] "sshd.service",
  20. ...,
  21. [5] "dummy_long_name_size_30_______"
  22. ],
  23. user = "root"
  24. >,
  25. services = [
  26. [0] #<Struct:SystemdServiceCheck::SSH::Service:0x7fb39da6bc08
  27. active_state = "active",
  28. load_state = "loaded",
  29. service_name = "sshd.service",
  30. sub_state = "running",
  31. type = "notify",
  32. unit_file_state = "enabled"
  33. >,
  34. ...,
  35. [5] #<Struct:SystemdServiceCheck::SSH::Service:0x7fb39db78bc8
  36. active_state = "inactive",
  37. load_state = "not-found",
  38. service_name = "dummy_long_name_size_30_______",
  39. sub_state = "dead",
  40. type = nil,
  41. unit_file_state = nil
  42. >
  43. ]
  44. >,
  45. ...,
  46. [2] #<Struct:SystemdServiceCheck::SSH::Result:0x7fb39e044cd8
  47. server = #<Struct:SystemdServiceCheck::Base::Server:0x7fb39dac6888
  48. env = "dev",
  49. hostname = "centos7",
  50. ip = "192.168.1.101",
  51. options = {
  52. :password => "vagrant",
  53. :keys => [
  54. [0] ""
  55. ],
  56. :logger => #<Logger:0x00007fb39e9c9858 @level=4, @progname=nil, @default_formatter=#<Logger::Formatter:0x00007fb39e9c9808 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0x00007fb39e9c9790 @shift_period_suffix=nil, @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDERR>>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x00007fb39e9c96f0>>>,
  57. :password_prompt => #<Net::SSH::Prompt:0x00007fb39dac5bb8>,
  58. :user => "root"
  59. },
  60. role = "db",
  61. services = [
  62. [0] "sshd.service",
  63. [1] "postgresql.service",
  64. [2] "pgpool.service"
  65. ],
  66. user = "root"
  67. >,
  68. services = [
  69. [0] #<Struct:SystemdServiceCheck::SSH::Service:0x7fb39dbd5b98
  70. active_state = "active",
  71. load_state = "loaded",
  72. service_name = "sshd.service",
  73. sub_state = "running",
  74. type = "notify",
  75. unit_file_state = "enabled"
  76. >,
  77. ...,
  78. [2] #<Struct:SystemdServiceCheck::SSH::Service:0x7fb39e045048
  79. active_state = "inactive",
  80. load_state = "not-found",
  81. service_name = "pgpool.service",
  82. sub_state = "dead",
  83. type = nil,
  84. unit_file_state = nil
  85. >
  86. ]
  87. >
  88. ]

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/k-ta-yamada/systemd_service_check. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the SystemdServiceCheck project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.