sys_watchdog 0.1.8 → 0.1.9
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 +4 -4
- data/bin/sys_watchdog +2 -5
- data/lib/sys_watchdog/main.rb +3 -0
- data/lib/sys_watchdog/setup.rb +95 -20
- data/sys_watchdog.gemspec +2 -2
- data/util/sys-watchdog.service +1 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38d49b5c78ca9aede0efaf95fecb8c848ca29dbf
|
4
|
+
data.tar.gz: 661379cb8e89a88f7bfa1fae44b8105d309b87d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e85c879f9473c5c70fdf3c297142f09190b7a13750e52bf7bbc2f4429d9077149da91313644e27afb6c6a8ae8920a8ef792c453227547f674a8d52935e98835
|
7
|
+
data.tar.gz: 940353576406de5755b14be0688e9d7d300afa01b5ede1601e18f8b641cf854d613c677a4a53a4b2cc06a49eecfe5112a299b0637f9792eefa9f770ac6d74e18
|
data/bin/sys_watchdog
CHANGED
@@ -4,11 +4,8 @@ require 'sys_watchdog'
|
|
4
4
|
|
5
5
|
case ARGV[0]
|
6
6
|
|
7
|
-
when
|
8
|
-
Setup.new.
|
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
|
data/lib/sys_watchdog/main.rb
CHANGED
@@ -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
|
data/lib/sys_watchdog/setup.rb
CHANGED
@@ -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
|
10
|
+
def setup
|
11
|
+
check_root
|
8
12
|
copy_sample_conf
|
9
|
-
|
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
|
-
|
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
|
-
|
14
|
-
|
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
|
-
|
17
|
-
|
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
|
-
|
21
|
-
copy_sample_conf
|
22
|
-
add_cron_line
|
57
|
+
private
|
23
58
|
|
24
|
-
|
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
|
-
|
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
|
-
|
82
|
+
def save_install_type install_type
|
83
|
+
File.write SysWatchdog::INSTALL_TYPE_PATH,
|
84
|
+
install_type
|
85
|
+
end
|
30
86
|
|
31
|
-
def
|
32
|
-
|
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
|
36
|
-
|
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?
|
44
|
-
STDERR.puts "SysWatchdog install requires dir #{
|
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
|
-
|
124
|
+
SYSTEMD_SERVICE_FILE
|
50
125
|
|
51
126
|
run 'systemctl enable sys-watchdog'
|
52
127
|
end
|
data/sys_watchdog.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "sys_watchdog"
|
3
|
-
s.version = "0.1.
|
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 = "
|
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
|
data/util/sys-watchdog.service
CHANGED
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.
|
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:
|
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:
|
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
|