s6 "really up" event hack

From: Patrick Mahoney <pat_at_polycrystal.org>
Date: Fri, 09 Jan 2015 12:52:29 -0600

Hi,

This is a small hack I'm experimenting with to allow an unmodified
service to notify s6 when it is "really up". It does this by grepping
the service's output for a certain pattern, then writing the U event.

Is this a reasonable approach, or too hackish and silly?

I feel like there could be a better implementation, one that doesn't
leave a "cat >/dev/null" process hanging around forever.

########################################
$ cat ./service
#! /usr/bin/env bash

for i in {1..3}; do
   echo preparing
   s6-sleep -m 250
done

echo ready

for i in {1..3}; do
   echo working
   s6-sleep -m 250
done

########################################
$ cat ./notifywhenmatch
#! /usr/bin/env execlineb -S0

pipeline -r { $_at_ }
pipeline -r { tee /dev/stderr }
pipeline -r
{
   if { grep -q ready }
   if { s6-ftrig-notify ./event U }
   redirfd -w 1 /dev/null
   cat
}
fdmove 2 1
wait { }
exit

########################################
$ s6-mkfifodir ./event
$ (s6-ftrig-wait ./event U && echo -e "\nReally UP") & ./notifywhenmatch
./service
preparing
preparing
preparing
ready
working
U
Really UP
working
working

Thanks,
-- 
Patrick Mahoney <pat_at_polycrystal.org>
Received on Fri Jan 09 2015 - 18:52:29 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC