pid_file_block 1.0.0 → 1.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 +4 -4
- data/README.md +9 -0
- data/lib/pid_file_block.rb +18 -3
- data/lib/pid_file_block/application.rb +2 -2
- data/lib/pid_file_block/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5885d32d680d374bd4307efe76b8aee57099c03a1cad205a042ca7c11c431083
|
4
|
+
data.tar.gz: 78ae4392a9f29617c450adae8ec9a415f1b278df186354834ec31f4e845bb9bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12c63f614d2956def64ebe8f001d3394ae9c01d0fb1b0ff1ab4115b83f4b115efc4dbff74ab9ff9304eebac9b3ddf71233adb74a0cf698f49a887b9ac6e80936
|
7
|
+
data.tar.gz: 07dec6aa8656c4f594a3aefa526e119debc06ad1afcfe5ee87cd44064506637bef150abaf221d71cd04598ab3beea02f13009c72da2221ca29d647efc2e716d5
|
data/README.md
CHANGED
@@ -85,8 +85,17 @@ require 'pid_file_block/application'
|
|
85
85
|
PidFileBlock::Application.run(piddir: '/run', pidfile: 'example.pid')
|
86
86
|
# Put your code here
|
87
87
|
end
|
88
|
+
```
|
89
|
+
|
90
|
+
### Kill a process with pid file from another
|
88
91
|
|
92
|
+
```ruby
|
93
|
+
#!/usr/bin/env ruby
|
89
94
|
|
95
|
+
require 'pid_file_block'
|
96
|
+
|
97
|
+
pid_file_block = PidFileBlock.new(piddir: '/run', pidfile: 'example.pid')
|
98
|
+
pid_flie_block.kill
|
90
99
|
```
|
91
100
|
|
92
101
|
## Contributing
|
data/lib/pid_file_block.rb
CHANGED
@@ -28,11 +28,11 @@ class PidFileBlock
|
|
28
28
|
File::Constants::RDWR|File::Constants::CREAT|File::Constants::EXCL) do |f|
|
29
29
|
f.flock(File::LOCK_EX)
|
30
30
|
if process_running?(f)
|
31
|
-
|
31
|
+
f.flock(File::LOCK_UN)
|
32
32
|
raise PidFileBlock::ProcessExistsError
|
33
33
|
end
|
34
34
|
write_pid(f)
|
35
|
-
|
35
|
+
f.flock(File::LOCK_UN)
|
36
36
|
end
|
37
37
|
break
|
38
38
|
rescue Errno::EEXIST
|
@@ -45,7 +45,7 @@ class PidFileBlock
|
|
45
45
|
def release
|
46
46
|
our_pid = $$
|
47
47
|
File.open(@pid_file_full_name, 'r') do |f|
|
48
|
-
f.flock(File::
|
48
|
+
f.flock(File::LOCK_SH)
|
49
49
|
file_pid_str = f.read
|
50
50
|
begin
|
51
51
|
file_pid = Integer(file_pid_str)
|
@@ -61,6 +61,21 @@ class PidFileBlock
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
def kill(signal: "TERM")
|
65
|
+
pid = nil
|
66
|
+
File.open(@pid_file_full_name, 'r') do |f|
|
67
|
+
f.flock(File::LOCK_SH)
|
68
|
+
pid_str = f.read
|
69
|
+
begin
|
70
|
+
pid = Integer(pid_str)
|
71
|
+
rescue ArgumentError
|
72
|
+
return false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
Process.kill(signal, pid)
|
76
|
+
return pid
|
77
|
+
end
|
78
|
+
|
64
79
|
private
|
65
80
|
|
66
81
|
def unlink_pid_file_if_exists
|
@@ -20,10 +20,10 @@ class PidFileBlock
|
|
20
20
|
exit_code_process_exists_error: 1,
|
21
21
|
exit_code_interrupt: 2)
|
22
22
|
pid_file_block = nil
|
23
|
-
|
23
|
+
Signal.trap('TERM') do
|
24
24
|
do_exit(pid_file_block, exit_code_interrupt)
|
25
25
|
end
|
26
|
-
|
26
|
+
Signal.trap('INT') do
|
27
27
|
do_exit(pid_file_block, exit_code_interrupt)
|
28
28
|
end
|
29
29
|
pid_file_block = PidFileBlock.new(piddir: piddir, pidfile: pidfile)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pid_file_block
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kharitonov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|