clicker 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/clicker/launch_lock.rb +30 -13
- data/lib/clicker/program.rb +6 -13
- data/lib/clicker/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb7b0b66b2bf146b1b763b91f765bea5678537a3
|
4
|
+
data.tar.gz: a5f69f12bd7e07c0d3c6036b26e67f81cd6e9555
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efaeaf6b461a72879356cba31f016ef75fb2f56fbc11dd61cd5dbd3664642385269e7da09950b6aed7f51cf7bed34d474cc5dc697fb299daf8ef6f775bb5daec
|
7
|
+
data.tar.gz: 00c984fa279a3df5c0be6c68fed7adb6b09bda147eafa754ad0ee00732828611ea3e9fad0881d83fb5e68aff45f1ee77dc6a554d6d278634a00f479bfda985e9
|
data/lib/clicker/launch_lock.rb
CHANGED
@@ -12,28 +12,45 @@ class LaunchLock
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def try_lock
|
15
|
-
File.open(@lock_file_path, '
|
16
|
-
f.
|
15
|
+
File.open(@lock_file_path, 'r+') do |f|
|
16
|
+
success = f.flock(File::LOCK_EX | File::LOCK_NB)
|
17
|
+
if success
|
18
|
+
f.puts Process.pid
|
19
|
+
f.flush
|
20
|
+
f.truncate(f.pos)
|
21
|
+
yield
|
22
|
+
return true
|
23
|
+
else
|
24
|
+
return false
|
25
|
+
end
|
17
26
|
end
|
18
|
-
yield
|
19
|
-
return true
|
20
|
-
rescue
|
21
|
-
return false
|
22
|
-
ensure
|
23
|
-
FileUtils.rm(@lock_file_path)
|
24
27
|
end
|
25
28
|
|
26
29
|
def locked?
|
27
|
-
File.
|
30
|
+
File.open(@lock_file_path, 'r') do |f|
|
31
|
+
rv = f.flock(File::LOCK_EX | File::LOCK_NB)
|
32
|
+
case rv
|
33
|
+
when 0
|
34
|
+
return false
|
35
|
+
when false
|
36
|
+
return true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
rescue Errno::ENOENT
|
40
|
+
return false
|
28
41
|
end
|
29
42
|
|
30
43
|
def owner
|
31
|
-
pid = nil
|
32
44
|
File.open(@lock_file_path) do |f|
|
33
|
-
|
45
|
+
success = f.flock(File::LOCK_EX | File::LOCK_NB)
|
46
|
+
if success
|
47
|
+
return nil # owner is not alive...
|
48
|
+
else
|
49
|
+
pid = f.gets.to_i
|
50
|
+
return pid
|
51
|
+
end
|
34
52
|
end
|
35
|
-
|
36
|
-
rescue
|
53
|
+
rescue Errno::ENOENT
|
37
54
|
return nil
|
38
55
|
end
|
39
56
|
end
|
data/lib/clicker/program.rb
CHANGED
@@ -30,26 +30,21 @@ class Program
|
|
30
30
|
|
31
31
|
unless success
|
32
32
|
STDERR.puts("Error: another instance of clicker is running. (PID #{@lock.owner})")
|
33
|
-
STDERR.puts("the lock file is at #{@lock.lock_file_path}.")
|
34
33
|
exit 1
|
35
34
|
end
|
36
35
|
when :start
|
37
|
-
if
|
36
|
+
if @lock.locked?
|
37
|
+
STDERR.puts("Error: another instance of clicker is running. (PID #{@lock.owner})")
|
38
|
+
exit 1
|
39
|
+
else
|
38
40
|
if fork == nil
|
39
41
|
if fork == nil
|
40
|
-
|
42
|
+
@lock.try_lock do
|
41
43
|
do_run
|
42
44
|
end
|
43
|
-
|
44
|
-
# ここでは端末から切り離されているので出来ることはない。
|
45
|
-
exit 1
|
46
|
-
end
|
45
|
+
# ここでは端末から切り離されているのでロックに失敗しても出来ることはない。
|
47
46
|
end
|
48
47
|
end
|
49
|
-
else
|
50
|
-
STDERR.puts("Error: another instance of clicker seems to be running. (PID #{@lock.owner})")
|
51
|
-
STDERR.puts("the lock file is at #{@lock.lock_file_path}.")
|
52
|
-
exit 1
|
53
48
|
end
|
54
49
|
when :stop
|
55
50
|
if @lock.locked?
|
@@ -59,8 +54,6 @@ class Program
|
|
59
54
|
STDERR.puts("SIGTERM has been sent to PID #{owner}.")
|
60
55
|
rescue Errno::ESRCH
|
61
56
|
STDERR.puts("Warning: Process (#{owner}) not found.")
|
62
|
-
STDERR.puts("Deleting the lock file.")
|
63
|
-
FileUtils.rm(@lock.lock_file_path)
|
64
57
|
end
|
65
58
|
else
|
66
59
|
STDERR.puts("no instance is running.")
|
data/lib/clicker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clicker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoteichi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubysdl
|