sys_watchdog 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c65f4287817a6e1f2172b9e469d0fb32a189b068
4
- data.tar.gz: 46f817b7f6ff8f51dc10cdaa802917edaacd7848
3
+ metadata.gz: 38d49b5c78ca9aede0efaf95fecb8c848ca29dbf
4
+ data.tar.gz: 661379cb8e89a88f7bfa1fae44b8105d309b87d7
5
5
  SHA512:
6
- metadata.gz: 42693ebbb818cd1549d84a64a49fafff8c0ad68f040312207b6746b41be5a26b3be81b43332dea14ab8d49b47119ffa87849382f12a6b7b0b24184969e38d3a9
7
- data.tar.gz: 53258664dc476766e42f8320f597da4df72390b7ce9e6bd1a16839b7ba53634374134728140dd3cfa12a3d54a696dd0696bfe1530a51dd4e431e48792d30155e
6
+ metadata.gz: 3e85c879f9473c5c70fdf3c297142f09190b7a13750e52bf7bbc2f4429d9077149da91313644e27afb6c6a8ae8920a8ef792c453227547f674a8d52935e98835
7
+ data.tar.gz: 940353576406de5755b14be0688e9d7d300afa01b5ede1601e18f8b641cf854d613c677a4a53a4b2cc06a49eecfe5112a299b0637f9792eefa9f770ac6d74e18
@@ -4,11 +4,8 @@ require 'sys_watchdog'
4
4
 
5
5
  case ARGV[0]
6
6
 
7
- when 'setup_with_systemd'
8
- Setup.new.with_systemd
9
-
10
- when 'setup_with_cron'
11
- Setup.new.with_cron
7
+ when %w(setup start stop uninstall)
8
+ Setup.new.send ARGV[0].to_sym
12
9
 
13
10
  when 'test'
14
11
  sw = SysWatchdog.new log_file: STDOUT
@@ -1,6 +1,9 @@
1
1
  class SysWatchdog
2
2
  DEFAULT_CONF_FILE = '/etc/sys_watchdog.yml'
3
3
  DEFAULT_LOG_FILE = '/var/log/sys_watchdog.log'
4
+ WORKING_DIR = '/var/local/sys_watchdog'
5
+ CRONJOB_PATH = '/etc/cron.d/sys_watchdog'
6
+ INSTALL_TYPE_PATH = "#{WORKING_DIR}/install_type"
4
7
 
5
8
  def initialize conf_file: nil, log_file: nil
6
9
  log_file ||= DEFAULT_LOG_FILE
@@ -1,52 +1,127 @@
1
1
 
2
2
  class Setup
3
+ SYSTEMD_SERVICES_DIR = "/lib/systemd/system/"
4
+ SYSTEMD_SERVICE_FILE = "#{SYSTEMD_SERVICES_DIR}/sys-watchdog.service"
5
+
3
6
  def initialize
4
7
  @thisdir = File.join File.dirname(__FILE__)
5
8
  end
6
9
 
7
- def with_systemd
10
+ def setup
11
+ check_root
8
12
  copy_sample_conf
9
- install_systemd_service
13
+ create_working_dir
14
+ install_type = get_install_type
15
+ save_install_type install_type
16
+ case install_type
17
+ when 'systemd'
18
+ install_systemd_service
19
+ when 'cron'
20
+ install_cronjob
21
+ end
22
+ setup_finished_msg
23
+ end
10
24
 
11
- puts "Installed."
25
+ def start
26
+ case read_install_type
27
+ when 'systemd'
28
+ run 'systemctl start sys-watchdog'
29
+ when 'cron'
30
+ rewrite_cronjob true
31
+ end
32
+ end
12
33
 
13
- puts "\nEdit #{SysWatchdog::DEFAULT_CONF_FILE} and start:"
14
- puts "systemctl start sys-watchdog"
34
+ def stop
35
+ case read_install_type
36
+ when 'systemd'
37
+ run 'systemctl stop sys-watchdog'
38
+ when 'cron'
39
+ rewrite_cronjob false
40
+ end
41
+ end
15
42
 
16
- puts "\nTo check daemon status:"
17
- puts "systemctl status sys-watchdog"
43
+ def uninstall
44
+ stop
45
+ File.delete SysWatchdog::DEFAULT_CONF_FILE
46
+ if File.exist?(SYSTEMD_SERVICE_FILE)
47
+ run 'systemctl disable sys-watchdog'
48
+ File.delete SYSTEMD_SERVICE_FILE
49
+ end
50
+ if File.exist?(SysWatchdog::CRONJOB_PATH)
51
+ File.delete SysWatchdog::CRONJOB_PATH
52
+ end
53
+ FileUtils.rm_rf SysWatchdog::WORKING_DIR
54
+ puts "Uninstall complete."
18
55
  end
19
56
 
20
- def with_cron
21
- copy_sample_conf
22
- add_cron_line
57
+ private
23
58
 
24
- puts "Installed."
59
+ def setup_finished_msg
60
+ puts "Installed.\n"
61
+ puts "Now:"
62
+ puts "1) Edit #{SysWatchdog::DEFAULT_CONF_FILE} to customize your system tests. You can run 'sys_watchdog test' to adjust your system tests and get a grasp of the sys_watchdog operation."
63
+ puts "2) After have your system tests configured run 'sys_watchdog start'"
64
+ end
25
65
 
26
- puts "\nEdit #{SysWatchdog::DEFAULT_CONF_FILE} and uncomment the cron line added."
66
+ def is_setup?
67
+ File.exist?(SysWatchdog::DEFAULT_CONF_FILE) &&
68
+ (File.exist?(SysWatchdog::CRONJOB_PATH) || File.exist?(SYSTEMD_SERVICE_FILE))
69
+ end
70
+
71
+ def has_systemd?
72
+ File.exist?(`which systemctl`) &&
73
+ File.writable?('/lib/systemd/system')
74
+ end
75
+
76
+ def rewrite_cronjob enable
77
+ c = File.read SysWatchdog::CRONJOB_PATH
78
+ c.gsub! /^\s*#\s*/, (enable ? '' : '#')
79
+ File.write SysWatchdog::CRONJOB_PATH, c
27
80
  end
28
81
 
29
- private
82
+ def save_install_type install_type
83
+ File.write SysWatchdog::INSTALL_TYPE_PATH,
84
+ install_type
85
+ end
30
86
 
31
- def add_cron_line
32
- run "echo '#* * * * * root /bin/bash -lc \'sys_watchdog once\' >> /etc/crontab"
87
+ def read_install_type
88
+ return unless File.exists? SysWatchdog::INSTALL_TYPE_PATH
89
+ File.read SysWatchdog::INSTALL_TYPE_PATH
33
90
  end
34
91
 
35
- def install_systemd_service
36
- services_dir = "/lib/systemd/system/"
92
+ def get_install_type
93
+ has_systemd? ? 'systemd' : 'cron'
94
+ end
95
+
96
+ def check_root
97
+ unless Process.uid == 0
98
+ STDERR.puts "Install requires root privileges. Run with sudo or login as root. Aborting."
99
+ exit 1
100
+ end
101
+ end
102
+
103
+ def create_working_dir
104
+ FileUtils.mkdir_p SysWatchdog::WORKING_DIR
105
+ end
37
106
 
107
+ def install_cronjob
108
+ File.write SysWatchdog::CRONJOB_PATH,
109
+ "#* * * * * root /bin/bash -lc 'sys_watchdog once' >> /etc/crontab"
110
+ end
111
+
112
+ def install_systemd_service
38
113
  if `which systemctl`.empty?
39
114
  STDERR.puts "SysWatchdog install requires systemctl. Aborting."
40
115
  exit 1
41
116
  end
42
117
 
43
- unless File.exist? services_dir
44
- STDERR.puts "SysWatchdog install requires dir #{services_dir}. Aborting."
118
+ unless File.exist? SYSTEMD_SERVICES_DIR
119
+ STDERR.puts "SysWatchdog install requires dir #{SYSTEMD_SERVICES_DIR}. Aborting."
45
120
  exit 1
46
121
  end
47
122
 
48
123
  copy "#{@thisdir}/../../util/sys-watchdog.service",
49
- services_dir
124
+ SYSTEMD_SERVICE_FILE
50
125
 
51
126
  run 'systemctl enable sys-watchdog'
52
127
  end
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "sys_watchdog"
3
- s.version = "0.1.8"
3
+ s.version = "0.1.9"
4
4
  s.authors = ["Tom Lobato"]
5
5
  s.email = "lobato@bettercall.io"
6
6
  s.homepage = "http://sys-watchdog.bettercall.io/"
7
- s.summary = "SysWatchdog keeps your *NIX servers green by performing periodic checks and optionally actions like service restarts and notifications."
7
+ s.summary = "sys_watchdog keeps your *NIX servers green by performing periodic checks and optionally actions like service restarts and notifications."
8
8
  s.description = "#{s.summary} https://github.com/tomlobato/sys_watchdog http://sys-watchdog.bettercall.io."
9
9
  s.licenses = ["MIT"]
10
10
  s.platform = Gem::Platform::RUBY
@@ -6,6 +6,7 @@ Description=sys_watchdog supervisor
6
6
  User=root
7
7
  Group=root
8
8
  Restart=on-failure
9
+ WorkingDirectory=/var/local/sys_watchdog
9
10
  ExecStart=/bin/bash -lc 'sys_watchdog'
10
11
  StandardOutput=syslog
11
12
  StandardError=syslog
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys_watchdog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lobato
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.8.1
41
- description: SysWatchdog keeps your *NIX servers green by performing periodic checks
41
+ description: sys_watchdog keeps your *NIX servers green by performing periodic checks
42
42
  and optionally actions like service restarts and notifications. https://github.com/tomlobato/sys_watchdog
43
43
  http://sys-watchdog.bettercall.io.
44
44
  email: lobato@bettercall.io
@@ -93,8 +93,8 @@ rubyforge_project:
93
93
  rubygems_version: 2.5.1
94
94
  signing_key:
95
95
  specification_version: 4
96
- summary: SysWatchdog keeps your *NIX servers green by performing periodic checks and
97
- optionally actions like service restarts and notifications.
96
+ summary: sys_watchdog keeps your *NIX servers green by performing periodic checks
97
+ and optionally actions like service restarts and notifications.
98
98
  test_files:
99
99
  - test/sys_watchdog_test.yml
100
100
  - test/test_sys_watchdog.rb