@inkeep/impulse-compute 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -118,9 +118,25 @@ detach() {
118
118
  perl -e '
119
119
  use POSIX qw(setsid);
120
120
  $SIG{HUP} = "IGNORE";
121
- my $log = shift @ARGV;
121
+ my ($log, $pid_file) = splice @ARGV, 0, 2;
122
+ pipe(my $read_start, my $send_start) or die "pipe: $!\n";
122
123
  defined(my $pid = fork()) or die "fork: $!\n";
123
- if ($pid) { print "$pid\n"; exit 0 }
124
+ if ($pid) {
125
+ close $read_start;
126
+ if (length $pid_file) {
127
+ unless (print("$pid\n") && close(STDOUT) && system("mv", "$pid_file.tmp", $pid_file) == 0) {
128
+ close $send_start;
129
+ waitpid($pid, 0);
130
+ exit 1;
131
+ }
132
+ }
133
+ print {$send_start} "start\n" or die "release runner: $!\n";
134
+ close $send_start or die "release runner: $!\n";
135
+ exit 0;
136
+ }
137
+ close $send_start;
138
+ <$read_start> or exit 1;
139
+ close $read_start;
124
140
  setsid() or die "setsid: $!\n";
125
141
  open(STDIN, "<", "/dev/null") or die "stdin: $!\n";
126
142
  open(STDOUT, ">>", $log) or die "log: $!\n";
@@ -192,7 +208,7 @@ if ! printf '%s\n' "$pubkey" > "$HOME/.lume/$vm/.ot-team-mac-owner"; then
192
208
  fi
193
209
  rm -f "$intent"
194
210
  mkdir -p "$dir"
195
- detach "$control/deadline-$owner_hash.log" /bin/bash -c "$(declare -f emit present remove_clone wait_runner_exit owns_vm reap_vm); reap_vm \"\$@\"" bash \
211
+ detach "$control/deadline-$owner_hash.log" "" /bin/bash -c "$(declare -f emit present remove_clone wait_runner_exit owns_vm reap_vm); reap_vm \"\$@\"" bash \
196
212
  "$vm" "$expires" "$pubkey" "$lume" "$control" "$dir" "$poll" "$owner_hash" >/dev/null
197
213
  while [ ! -f "$lease" ]; do
198
214
  [ ! -f "$cancel" ] || cancel_start
@@ -203,7 +219,12 @@ while [ ! -f "$lease" ]; do
203
219
  fi
204
220
  sleep "$poll"
205
221
  done
206
- detach "$dir/runner.log" /bin/sh -c 'NSUnbufferedIO=YES "$1" run "$2" --no-display; code=$?; printf "%s\n" "$code" > "$3/exit.tmp" && mv "$3/exit.tmp" "$3/exit"' sh "$lume" "$vm" "$dir" > "$dir/pid"
222
+ if ! detach "$dir/runner.log" "$dir/pid" /bin/sh -c 'NSUnbufferedIO=YES "$1" run "$2" --no-display; code=$?; printf "%s\n" "$code" > "$3/exit.tmp" && mv "$3/exit.tmp" "$3/exit"' sh "$lume" "$vm" "$dir" > "$dir/pid.tmp"; then
223
+ remove_clone
224
+ emit outcome not-established vm "$vm" boundSeconds "$bound" reason "could not publish the VM runner PID" \
225
+ presentBeforeDelete "$before" absent "$absent" log ""
226
+ exit 4
227
+ fi
207
228
 
208
229
  while :; do
209
230
  if [ -f "$cancel" ]; then