runfile-exec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 90779b05a4e99841b74174a7749ee877f5128c3e
4
+ data.tar.gz: bdba048aedc64945d67f6a7a5de4df31e2641011
5
+ SHA512:
6
+ metadata.gz: e43cb9139fd411d5d79df41a71cabdecbc2e4ac124b831d5dc1235a9238e9e6c6aeee895d6cd27f5304ee0279e7af1e08c0db07c7cc664b9f3ab9de5c842c7d7
7
+ data.tar.gz: e6489265df4b6d22b6ff1c85095f10b340b26e7098d70a90c67170749257afe027064a369e0070d35a1b1771d0fc7f66ee2c14e3e7c46135b4b8fb20e9885e47
@@ -0,0 +1,49 @@
1
+ Runfile Exec
2
+ ============
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/runfile-exec.svg)](http://badge.fury.io/rb/runfile-exec)
5
+
6
+ [Runfile](https://github.com/DannyBen/runfile) extensions for executing shell commands.
7
+
8
+ ## Install
9
+
10
+ $ gem install runfile-exec
11
+
12
+ ## Usage
13
+
14
+ Put this in your Runfile
15
+
16
+ ```ruby
17
+ require "runfile-exec"
18
+ include RunfileExec
19
+ ```
20
+
21
+ And then you can use any of these commands in your Runfile actions:
22
+
23
+ ```ruby
24
+ # Print and run a command. Wait until it is done and continue.
25
+ run 'pwd'
26
+
27
+ # Print and run a command. Wait until it is done and exit.
28
+ run! 'pwd'
29
+
30
+ # Run a command in the background
31
+ run_bg 'some-long-running --daemon'
32
+
33
+ # Run a command in the background, log to a log file and save the process
34
+ # ID in a pid file for later reference
35
+ run_bg 'some-long-running --daemon', log: 'my.log', pid: 'daemon'
36
+
37
+ # Stop a command started with 'run_bg'. Provide the name of he pid file you
38
+ # used in 'run_bg'
39
+ stop_bg 'daemon'
40
+ ```
41
+
42
+ ## About PID files ##
43
+
44
+ PID files are stored in the working directory by default.
45
+ To change the location, add this at the beginning of your Runfile:
46
+
47
+ ```ruby
48
+ RunfileExec.pid_dir = './tmp'
49
+ ```
@@ -0,0 +1,2 @@
1
+ require "runfile-exec/version"
2
+ require "runfile-exec/extensions"
@@ -0,0 +1,60 @@
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
+ @@pid_dir = nil
8
+
9
+ def self.pid_dir=(dir)
10
+ @@pid_dir = dir
11
+ end
12
+
13
+ def self.pid_dir
14
+ @@pid_dir
15
+ end
16
+
17
+ # Run a command, wait until it is done and continue
18
+ def run(cmd)
19
+ say "!txtgrn!> #{cmd}"
20
+ system cmd
21
+ end
22
+ module_function :run
23
+
24
+ # Run a command, wait until it is done, then exit
25
+ def run!(cmd)
26
+ say "!txtgrn!> #{cmd}"
27
+ exec cmd
28
+ end
29
+ module_function :run!
30
+
31
+ # Run a command in the background, optionally log to a log file and save
32
+ # the process ID in a pid file
33
+ def run_bg(cmd, pid: nil, log: '/dev/null')
34
+ full_cmd = "exec #{cmd} >#{log} 2>&1"
35
+ say "!txtgrn!> #{full_cmd}"
36
+ process = IO.popen "exec #{cmd} >#{log} 2>&1"
37
+ File.write pidfile(pid), process.pid if pid
38
+ return process.pid
39
+ end
40
+
41
+ # Stop a command started with 'run_bg'. Provide the name of he pid file you
42
+ # used in 'run_bg'
43
+ def stop_bg(pid)
44
+ file = pidfile(pid)
45
+ if File.exist? file
46
+ pid = File.read file
47
+ File.delete file
48
+ run "kill -s TERM #{pid}"
49
+ else
50
+ say "!txtred!PID file not found."
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def pidfile(pid)
57
+ @@pid_dir ? "#{@@pid_dir}/#{pid}.pid" : "#{pid}.pid"
58
+ end
59
+
60
+ end
@@ -0,0 +1,5 @@
1
+ module RunfileExec
2
+
3
+ # Version constant, used by gemspec
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: runfile-exec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Danny Ben Shitrit
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colsole
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ description: A collection of utility methods to run shell commands for Runfile
28
+ email: db@dannyben.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - lib/runfile-exec.rb
35
+ - lib/runfile-exec/extensions.rb
36
+ - lib/runfile-exec/version.rb
37
+ homepage: https://github.com/DannyBen/runfile-exec
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.4.6
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Runfile methods for executing shell commands
61
+ test_files: []
62
+ has_rdoc: