global_error_handler 1.1.0 → 1.2.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9754eb3b73eaff7706b3f65e5c5f4a45b454d874
|
4
|
+
data.tar.gz: c45f97699e47d4e6873b17ecd788c1376316d465
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8975a6cc714719315e097adc6fcd78142b24529bb5cda52b2c2ac26dd1bc325a3132c8cbd68c855d0a39b489bc9e88d9e94782dd52dd1f7bec07a77ddf8984c8
|
7
|
+
data.tar.gz: 373dcdd22986e947b9a8ae6286e5aca4196b8f7afb6b911338e29705bf7073af1630ed0911019535589a425d406e80bfa0bccfa58ad42199f932ea3bca03f9d8
|
data/README.md
CHANGED
@@ -4,12 +4,48 @@
|
|
4
4
|
# /etc/init.d/<%= application %>_geh_subscription
|
5
5
|
|
6
6
|
start() {
|
7
|
-
|
8
|
-
|
7
|
+
pid_file=<%= shared_path %>/pids/global_error_handler_subscription.pid
|
8
|
+
if [ -e "$pid_file" ] && \
|
9
|
+
kill -0 `cat $pid_file` >/dev/null 2>&1; then
|
10
|
+
echo GEH Subscription is already running. Quiting...
|
11
|
+
else
|
12
|
+
rm -f $pid_file >/dev/null 2>&1
|
13
|
+
echo GEH Subscription is not running. Executing start command...
|
14
|
+
su - <%= user %> -c "cd <%= current_path %>; PATH=$PATH:/home/<%= user %>/.rvm/bin; \
|
15
|
+
RAILS_ENV=<%= rails_env %> nohup rvm <%= rvm_ruby_string %> do rake global_error_handler:cleanup_database_dependencies >/dev/null 2>&1 & sleep 2"
|
16
|
+
su - <%= user %> -c "cd <%= current_path %>; PATH=$PATH:/home/<%= user %>/.rvm/bin; \
|
17
|
+
RAILS_ENV=<%= rails_env %> nohup rvm <%= rvm_ruby_string %> do rake global_error_handler:subscribe_to_expired >/dev/null 2>&1 & sleep 3"
|
18
|
+
echo done
|
19
|
+
fi
|
9
20
|
}
|
10
21
|
|
11
22
|
stop() {
|
12
|
-
|
23
|
+
pid_file=<%= shared_path %>/pids/global_error_handler_subscription.pid
|
24
|
+
if [ -e "$pid_file" ] && \
|
25
|
+
kill -0 `cat $pid_file` >/dev/null 2>&1; then
|
26
|
+
echo Stopping GEH Subscription...
|
27
|
+
kill -s INT `cat $pid_file`
|
28
|
+
tries_count=8
|
29
|
+
success=0
|
30
|
+
while [ $((tries_count-=1)) -ge 0 ]; do
|
31
|
+
if [ -e "$pid_file" ] >/dev/null 2>&1; then
|
32
|
+
sleep 1
|
33
|
+
else
|
34
|
+
success=1
|
35
|
+
break
|
36
|
+
fi
|
37
|
+
done
|
38
|
+
if [ $success -eq 0 ]; then
|
39
|
+
echo "killing GEH Subscription process..."
|
40
|
+
kill -s KILL `cat $pid_file`
|
41
|
+
rm -f $pid_file >/dev/null 2>&1
|
42
|
+
else
|
43
|
+
echo GEH Subscription has been stopped successfully.
|
44
|
+
fi
|
45
|
+
else
|
46
|
+
rm -f $pid_file >/dev/null 2>&1
|
47
|
+
echo GEH Subscription is not running.
|
48
|
+
fi
|
13
49
|
}
|
14
50
|
|
15
51
|
case "$1" in
|
@@ -1,39 +1,55 @@
|
|
1
1
|
namespace :global_error_handler do
|
2
2
|
desc 'Subscribe to expired keyevent notifications'
|
3
3
|
task subscribe_to_expired: :environment do
|
4
|
-
|
4
|
+
if pid_file_exists?
|
5
|
+
begin
|
6
|
+
Process.kill 0, process_id
|
7
|
+
puts '*** already running!'
|
8
|
+
next
|
9
|
+
rescue Errno::ESRCH
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
5
13
|
File.open(pid_file, 'w') { |f| f.puts Process.pid }
|
14
|
+
|
6
15
|
begin
|
7
16
|
GlobalErrorHandler::RedisNotificationSubscriber.subscribe!
|
8
17
|
ensure
|
9
|
-
|
10
|
-
File.unlink pid_file
|
11
|
-
rescue
|
12
|
-
nil
|
13
|
-
end
|
18
|
+
File.unlink(pid_file) rescue nil
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
22
|
desc 'Unsubscribe from expired keyevent notifications'
|
18
23
|
task unsubscribe_from_expired: :environment do
|
19
|
-
puts('*** pid file does not exist!') || next unless
|
20
|
-
|
24
|
+
puts('*** pid file does not exist!') || next unless pid_file_exists?
|
25
|
+
|
21
26
|
begin
|
22
27
|
Process.kill 0, process_id
|
23
28
|
GlobalErrorHandler::RedisNotificationSubscriber.unsubscribe!
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
|
30
|
+
term_signals = [2, 3, 15, 9].to_enum
|
31
|
+
begin
|
32
|
+
puts "** Sending signal #{term_signals.peek} to ##{process_id}..."
|
33
|
+
Process.kill(term_signals.next, process_id)
|
34
|
+
|
35
|
+
i_try = 0
|
36
|
+
while i_try <= 3
|
37
|
+
Process.kill 0, process_id
|
38
|
+
i_try += 1
|
39
|
+
sleep 1
|
40
|
+
raise RetryIteration if i_try == 3
|
41
|
+
end
|
42
|
+
rescue RetryIteration
|
43
|
+
retry
|
44
|
+
rescue StopIteration
|
45
|
+
puts '*** failed to stop a process!'
|
46
|
+
rescue Errno::ESRCH, Errno::ENOENT
|
47
|
+
puts '*** successfully stopped!'
|
48
|
+
end
|
29
49
|
rescue Errno::ESRCH
|
30
50
|
puts "** No such process ##{process_id}. Exiting..."
|
31
51
|
ensure
|
32
|
-
|
33
|
-
File.unlink pid_file
|
34
|
-
rescue
|
35
|
-
nil
|
36
|
-
end
|
52
|
+
File.unlink(pid_file) rescue nil
|
37
53
|
end
|
38
54
|
end
|
39
55
|
|
@@ -44,7 +60,27 @@ namespace :global_error_handler do
|
|
44
60
|
puts '** completed CleanUp process.'
|
45
61
|
end
|
46
62
|
|
63
|
+
class RetryIteration < StandardError; end
|
64
|
+
|
65
|
+
def pid_location
|
66
|
+
pid_dir = [
|
67
|
+
File.join(Rails.root, '..', 'shared', 'pids'),
|
68
|
+
File.join(Rails.root, '..', '..', 'shared', 'pids'),
|
69
|
+
File.join(Rails.root, 'tmp', 'pids')
|
70
|
+
].detect { |dir_name| Dir.exist?(dir_name) }
|
71
|
+
|
72
|
+
File.expand_path pid_dir
|
73
|
+
end
|
74
|
+
|
47
75
|
def pid_file
|
48
|
-
@pid_file ||= File.
|
76
|
+
@pid_file ||= File.join(pid_location, 'global_error_handler_subscription.pid')
|
77
|
+
end
|
78
|
+
|
79
|
+
def process_id
|
80
|
+
File.read(pid_file).to_i
|
81
|
+
end
|
82
|
+
|
83
|
+
def pid_file_exists?
|
84
|
+
File.exist? pid_file
|
49
85
|
end
|
50
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: global_error_handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrii Rudenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|