pups 1.0.1 → 1.0.2

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
- SHA1:
3
- metadata.gz: cf30e6638af5d5e6618c872c48c916485a8d75f2
4
- data.tar.gz: 28da8c64dc283ad29a17cfd02cdb92703c91e296
2
+ SHA256:
3
+ metadata.gz: 981fde4b2d6a70bad81c500abd0f9a11c8ec8161601f919765fbe8ac55fec3ab
4
+ data.tar.gz: fc29d1fdecf62a137f37f32f570e7ce635ec95c6fa817e166c022b701052cce7
5
5
  SHA512:
6
- metadata.gz: b6f37ce6dff5423dcae7b9e92816d6618693d6bb9fdd4e8af70e6e052f6ef31bc4c8397920b183ff985b1a4b0ee42150c812f0a4f5a48c922f9cc818b1ff885c
7
- data.tar.gz: b3bdbd36b7a2cb327c27f7fc691296ded3a9e63044665939845b0165727259eee49a5664ea5de4674c68ca1f9024bdb16ce7b686397e51522b7eac1d83900a9e
6
+ metadata.gz: 9fb37fb5c1e2f88d18a1d8a2f307cae341b0d4a7780363c7338acd8f891b3b0d21c9ba47333be3cf06760073d40aa30cb988c262649ad88d373cb54a1027beb4
7
+ data.tar.gz: 6f71a5c0684e80623eb7d10612fd0aa6b93950d31d42fa018d3db6c0689f1109077fbd89797f0d0ce9b88608a667aeae0bad48dde51b27976d2518a67b580095
data/README.md CHANGED
@@ -28,7 +28,7 @@ params:
28
28
  hello: hello world
29
29
 
30
30
  run:
31
- - exec: /bin/bash -c 'echo $hello >>> hello'
31
+ - exec: /bin/bash -c 'echo $hello >> hello'
32
32
  ```
33
33
 
34
34
  Running: `pups somefile.yaml` will execute the shell script resulting in a file called "hello" with the contents "hello world".
@@ -12,6 +12,10 @@ require "pups/file_command"
12
12
  require "pups/runit"
13
13
 
14
14
  module Pups
15
+ class ExecError < RuntimeError
16
+ attr_accessor :exit_code
17
+ end
18
+
15
19
  def self.log
16
20
  # at the moment docker likes this
17
21
  @logger ||= Logger.new(STDERR)
@@ -29,7 +29,6 @@ class Pups::Cli
29
29
  config = Pups::Config.load_file(args[0])
30
30
  end
31
31
  config.run
32
-
33
32
  ensure
34
33
  Pups::ExecCommand.terminate_async
35
34
  end
@@ -3,7 +3,14 @@ class Pups::Config
3
3
  attr_reader :config, :params
4
4
 
5
5
  def self.load_file(config_file)
6
- new YAML.load_file(config_file)
6
+ begin
7
+ new YAML.load_file(config_file)
8
+ rescue Exception
9
+ STDERR.puts "Failed to parse #{config_file}"
10
+ STDERR.puts "This is probably a formatting error in #{config_file}"
11
+ STDERR.puts "Cannot continue. Edit #{config_file} and try again."
12
+ raise
13
+ end
7
14
  end
8
15
 
9
16
  def self.load_config(config)
@@ -70,16 +77,22 @@ class Pups::Config
70
77
  def run
71
78
  run_commands
72
79
  rescue => e
73
- puts
74
- puts
75
- puts "FAILED"
76
- puts "-" * 20
77
- puts "#{e.class}: #{e}"
78
- puts "Location of failure: #{e.backtrace[0]}"
79
- if @last_command
80
- puts "#{@last_command[:command]} failed with the params #{@last_command[:params].inspect}"
80
+ exit_code = 1
81
+ if Pups::ExecError === e
82
+ exit_code = e.exit_code
83
+ end
84
+ unless exit_code == 77
85
+ puts
86
+ puts
87
+ puts "FAILED"
88
+ puts "-" * 20
89
+ puts "#{e.class}: #{e}"
90
+ puts "Location of failure: #{e.backtrace[0]}"
91
+ if @last_command
92
+ puts "#{@last_command[:command]} failed with the params #{@last_command[:params].inspect}"
93
+ end
81
94
  end
82
- exit 1
95
+ exit exit_code
83
96
  end
84
97
 
85
98
  def run_commands
@@ -85,7 +85,11 @@ class Pups::ExecCommand < Pups::Command
85
85
  pid = Process.spawn(command)
86
86
  (@@asyncs ||= []) << {pid: pid, command: command, stop_signal: (stop_signal || "TERM")}
87
87
  Thread.new do
88
- Process.wait(pid)
88
+ begin
89
+ Process.wait(pid)
90
+ rescue Errno::ECHILD
91
+ # already exited so skip
92
+ end
89
93
  @@asyncs.delete_if{|async| async[:pid] == pid}
90
94
  end
91
95
  return pid
@@ -102,7 +106,11 @@ class Pups::ExecCommand < Pups::Command
102
106
  end
103
107
  end
104
108
 
105
- raise RuntimeError.new("#{command} failed with return #{$?.inspect}") unless $? == 0
109
+ unless $? == 0
110
+ err = Pups::ExecError.new("#{command} failed with return #{$?.inspect}")
111
+ err.exit_code = $?.exitstatus
112
+ raise err
113
+ end
106
114
 
107
115
  nil
108
116
 
@@ -1,3 +1,3 @@
1
1
  module Pups
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -78,7 +78,7 @@ module Pups
78
78
  end
79
79
 
80
80
  def test_fails_for_non_zero_exit
81
- assert_raises(RuntimeError) do
81
+ assert_raises(Pups::ExecError) do
82
82
  ExecCommand.from_str("chgrp -a",{}).run
83
83
  end
84
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pups
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-26 00:00:00.000000000 Z
11
+ date: 2018-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.5.1
135
+ rubygems_version: 2.7.6
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: Process orchestrator