runfile-exec 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/runfile-exec.rb +2 -2
- data/lib/runfile-exec/extensions.rb +80 -76
- data/lib/runfile-exec/version.rb +1 -1
- metadata +44 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96d6aad61ea45f52a7de8902ff6450b1edb45a45
|
4
|
+
data.tar.gz: a1ead08288b8c5724071e7cc69d27d2d8825e68e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec9e57243475700fa47ea19b435113a1e86412d1465a6ce9b576ffeace6eafe76264ec3d6e99ea658747266ae221623c84ec05ada652d883ea195239d506d730
|
7
|
+
data.tar.gz: 94ff769ef6076abdf09dc1b78225e0374e0df705313f382a0279f6e7392521d17e982da38f29e148b70b43aaa91e0ef6ab77d1b6fa02972a3709baddf8e8160c
|
data/lib/runfile-exec.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require "runfile-exec/version"
|
2
|
-
require "runfile-exec/extensions"
|
1
|
+
require "runfile-exec/version"
|
2
|
+
require "runfile-exec/extensions"
|
@@ -1,76 +1,80 @@
|
|
1
|
-
# This module provides methods for easily and politely run shell commands
|
2
|
-
# through a Runfile action.
|
3
|
-
# It is mainly a convenient wrapper around `system` and `exec` and it also
|
4
|
-
# adds functions for running background tasks with ease.
|
5
|
-
|
6
|
-
module RunfileExec
|
7
|
-
def self.pid_dir=(dir)
|
8
|
-
@@pid_dir = dir
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.pid_dir
|
12
|
-
@@pid_dir
|
13
|
-
end
|
14
|
-
|
15
|
-
# Run a command, wait until it is done and continue
|
16
|
-
def run(cmd)
|
17
|
-
cmd = @before_run_block.call(cmd) if @before_run_block
|
18
|
-
return false unless cmd
|
19
|
-
say "!txtgrn!> #{cmd}"
|
20
|
-
system cmd
|
21
|
-
@after_run_block.call(cmd) if @after_run_block
|
22
|
-
end
|
23
|
-
|
24
|
-
# Run a command, wait until it is done, then exit
|
25
|
-
def run!(cmd)
|
26
|
-
cmd = @before_run_block.call(cmd) if @before_run_block
|
27
|
-
return false unless cmd
|
28
|
-
say "!txtgrn!> #{cmd}"
|
29
|
-
exec cmd
|
30
|
-
end
|
31
|
-
|
32
|
-
# Run a command in the background, optionally log to a log file and save
|
33
|
-
# the process ID in a pid file
|
34
|
-
def run_bg(cmd, pid: nil, log: '/dev/null')
|
35
|
-
cmd = @before_run_block.call(cmd) if @before_run_block
|
36
|
-
return false unless cmd
|
37
|
-
full_cmd = "exec #{cmd} >#{log} 2>&1"
|
38
|
-
say "!txtgrn!> #{full_cmd}"
|
39
|
-
process = IO.popen "exec #{cmd} >#{log} 2>&1"
|
40
|
-
File.write pidfile(pid), process.pid if pid
|
41
|
-
@after_run_block.call(cmd) if @after_run_block
|
42
|
-
return process.pid
|
43
|
-
end
|
44
|
-
|
45
|
-
# Stop a command started with 'run_bg'. Provide the name of he pid file you
|
46
|
-
# used in 'run_bg'
|
47
|
-
def stop_bg(pid)
|
48
|
-
file = pidfile(pid)
|
49
|
-
if File.exist? file
|
50
|
-
pid = File.read file
|
51
|
-
File.delete file
|
52
|
-
run "kill -s TERM #{pid}"
|
53
|
-
else
|
54
|
-
say "!txtred!PID file not found."
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Set a block to be called before each run
|
59
|
-
def before_run(&block)
|
60
|
-
@before_run_block = block
|
61
|
-
end
|
62
|
-
|
63
|
-
# Set a block to be called after each run
|
64
|
-
def after_run(&block)
|
65
|
-
@after_run_block = block
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
def
|
71
|
-
@@pid_dir ?
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
1
|
+
# This module provides methods for easily and politely run shell commands
|
2
|
+
# through a Runfile action.
|
3
|
+
# It is mainly a convenient wrapper around `system` and `exec` and it also
|
4
|
+
# adds functions for running background tasks with ease.
|
5
|
+
|
6
|
+
module RunfileExec
|
7
|
+
def self.pid_dir=(dir)
|
8
|
+
@@pid_dir = dir
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.pid_dir
|
12
|
+
@@pid_dir
|
13
|
+
end
|
14
|
+
|
15
|
+
# Run a command, wait until it is done and continue
|
16
|
+
def run(cmd)
|
17
|
+
cmd = @before_run_block.call(cmd) if @before_run_block
|
18
|
+
return false unless cmd
|
19
|
+
say "!txtgrn!> #{cmd}"
|
20
|
+
system cmd
|
21
|
+
@after_run_block.call(cmd) if @after_run_block
|
22
|
+
end
|
23
|
+
|
24
|
+
# Run a command, wait until it is done, then exit
|
25
|
+
def run!(cmd)
|
26
|
+
cmd = @before_run_block.call(cmd) if @before_run_block
|
27
|
+
return false unless cmd
|
28
|
+
say "!txtgrn!> #{cmd}"
|
29
|
+
exec cmd
|
30
|
+
end
|
31
|
+
|
32
|
+
# Run a command in the background, optionally log to a log file and save
|
33
|
+
# the process ID in a pid file
|
34
|
+
def run_bg(cmd, pid: nil, log: '/dev/null')
|
35
|
+
cmd = @before_run_block.call(cmd) if @before_run_block
|
36
|
+
return false unless cmd
|
37
|
+
full_cmd = "exec #{cmd} >#{log} 2>&1"
|
38
|
+
say "!txtgrn!> #{full_cmd}"
|
39
|
+
process = IO.popen "exec #{cmd} >#{log} 2>&1"
|
40
|
+
File.write pidfile(pid), process.pid if pid
|
41
|
+
@after_run_block.call(cmd) if @after_run_block
|
42
|
+
return process.pid
|
43
|
+
end
|
44
|
+
|
45
|
+
# Stop a command started with 'run_bg'. Provide the name of he pid file you
|
46
|
+
# used in 'run_bg'
|
47
|
+
def stop_bg(pid)
|
48
|
+
file = pidfile(pid)
|
49
|
+
if File.exist? file
|
50
|
+
pid = File.read file
|
51
|
+
File.delete file
|
52
|
+
run "kill -s TERM #{pid}"
|
53
|
+
else
|
54
|
+
say "!txtred!PID file not found."
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Set a block to be called before each run
|
59
|
+
def before_run(&block)
|
60
|
+
@before_run_block = block
|
61
|
+
end
|
62
|
+
|
63
|
+
# Set a block to be called after each run
|
64
|
+
def after_run(&block)
|
65
|
+
@after_run_block = block
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def pid_dir
|
71
|
+
defined?(@@pid_dir) ? @@pid_dir : nil
|
72
|
+
end
|
73
|
+
|
74
|
+
def pidfile(pid)
|
75
|
+
pid_dir ? "#{pid_dir}/#{pid}.pid" : "#{pid}.pid"
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
include RunfileExec
|
data/lib/runfile-exec/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runfile-exec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -24,6 +24,48 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: run-gem-dev
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: runfile
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5'
|
27
69
|
description: A collection of utility methods to run shell commands for Runfile
|
28
70
|
email: db@dannyben.com
|
29
71
|
executables: []
|