ruby-cli-daemon 0.3.0 → 0.4.0

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
2
  SHA256:
3
- metadata.gz: f8c5509e29395a1de3c0f720971cb4a645cd6c4d5801cb876eaaf224c40a699a
4
- data.tar.gz: '0659e79f4e92b56d5a27832321d2ac7b9f40fb5c59a84391689a340661f67900'
3
+ metadata.gz: bdc9d0158a4c5bda15cffc7fd840f9fb19a78be1d808a7972f86526b99048ac6
4
+ data.tar.gz: 80fd1f70317d0f821cfd000debbd165c180b8308e8fb55c84bbc2eaeed0bb714
5
5
  SHA512:
6
- metadata.gz: aa4a1dbf9d6ba2eb48bf9778d05dafebe699b2304b4a218d4dd935f814dd4b8a16c66256e818b0f16efa45ddb0a91a0f57865d637f990d2c30fcf17baef4683e
7
- data.tar.gz: 97c2e4082bc8f967810738ca4790a828dec80c1c1247ebfc2012ded362d5f3332491d027db27a6ef3e917d3c13514ac46dcd76858d3a86478bded5cd688b55d6
6
+ metadata.gz: 84e6f69005593546caee47feafb734c73781c74a690c233f3287b686f5adc1c29d10a517079cd735c00551351b4f8e4d42e54bb068eb3cb8501ca443f7044ff8
7
+ data.tar.gz: 814b27d01d61f5620846e7b52eb00f6d54bd1d9ce9a1d1cd66aa7e11eedb18e5c89543ca807f9a3def8a2f6ddb12b854a140a5cd2d72edace868a523ac175f8c
@@ -35,7 +35,7 @@ executable=$1
35
35
  shift
36
36
 
37
37
  # matching the `stop` pattern so everything can be killed quickly
38
- socket=${TMPDIR}ruby_cli_daemon/$(basename $PWD)/${executable}
38
+ socket=${TMPDIR}ruby_cli_daemon/$(pwd | md5 | cut -c1-7)/${executable}
39
39
  log=${TMPDIR}ruby_cli_daemon.log
40
40
 
41
41
  # spawn new daemon if none exists
@@ -44,7 +44,7 @@ if [[ ! -e $socket ]]; then
44
44
  nohup ruby -r$lib/ruby_cli_daemon.rb -e RubyCliDaemon.start\ \"$socket\",\ \"$executable\" 0<&- &>$log &
45
45
  while [ ! -e $socket ]; do
46
46
  sleep 0.1
47
- kill -0 $(jobs -p) &>/dev/null || (cat $log && false) # fail fast when worker failed
47
+ kill -0 $(jobs -p) &>/dev/null || (cat $log && rm -f $log && false) # fail fast when worker failed
48
48
  done
49
49
  fi
50
50
 
@@ -55,8 +55,8 @@ stderr="${socket}.err"
55
55
  rm -f $status $stdout $stderr # clear previous
56
56
  touch $stdout $stderr
57
57
 
58
- # send the command to the daemon
59
- echo $@ | nc -U $socket
58
+ # send the command and parsable env vars to the daemon
59
+ { echo $@; awk 'BEGIN{for(v in ENVIRON) printf "--RCD-- %s %s", v, ENVIRON[v] }';} | nc -U $socket
60
60
 
61
61
  # stream output
62
62
  tail -f $stdout &
@@ -9,7 +9,7 @@ module RubyCliDaemon
9
9
  class << self
10
10
  def install(path)
11
11
  File.unlink(path) if File.exist?(path)
12
- File.symlink(File.expand_path("../bin/ruby-sli-daemon.sh", __dir__), path)
12
+ File.symlink(File.expand_path("../bin/ruby-cli-daemon.sh", __dir__), path)
13
13
  end
14
14
 
15
15
  def start(socket, executable)
@@ -18,11 +18,12 @@ module RubyCliDaemon
18
18
 
19
19
  loop do
20
20
  return unless (command = wait_for_command(server))
21
-
21
+ command, env = command
22
22
  # execute the command in a fork
23
23
  capture :STDOUT, "#{socket}.out" do
24
24
  capture :STDERR, "#{socket}.err" do
25
25
  _, status = Process.wait2(fork do
26
+ ENV.replace env
26
27
  ARGV.replace(command) # uncovered
27
28
  load path # uncovered
28
29
  end)
@@ -83,8 +84,9 @@ module RubyCliDaemon
83
84
  return unless IO.select([server], nil, nil, TIMEOUT)
84
85
  connection = server.accept
85
86
  command = connection.gets.shellsplit
87
+ env = Hash[connection.read.split("--RCD-- ")[1..-1].map { |s| s.split(/ /, 2) }]
86
88
  connection.close
87
- command
89
+ [command, env]
88
90
  end
89
91
 
90
92
  def create_socket(socket)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module RubyCliDaemon
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-cli-daemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-02 00:00:00.000000000 Z
11
+ date: 2019-06-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael@grosser.it
@@ -17,14 +17,16 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - MIT-LICENSE
20
- - bin/ruby-sli-daemon.sh
20
+ - bin/ruby-cli-daemon.sh
21
21
  - lib/ruby_cli_daemon.rb
22
22
  - lib/ruby_cli_daemon/version.rb
23
23
  homepage: https://github.com/grosser/ruby-cli-daemon
24
24
  licenses:
25
25
  - MIT
26
26
  metadata: {}
27
- post_install_message:
27
+ post_install_message: |-
28
+ To finish the update, run:
29
+ ruby -rruby_cli_daemon -e "RubyCliDaemon.install '/usr/local/bin/ruby-cli-daemon'"
28
30
  rdoc_options: []
29
31
  require_paths:
30
32
  - lib