A runwhen example

This example maintains a mirror of code.dogmap.org. in the directory ./mirror. It runs under Laurent Bercot's s6 system.

# cd /service/mirror-dogmap

# cat run
#!/bin/sh
exec 2>&1                           \
s6-setuidgid mirroruser             \
rw-add   n d1S             now1s    \
rw-match \$now1s ,H=2,M=30 wake     \
statfile -M finished                \
rw-add \$MTAI64N d36H      latest   \
rw-min \$wake \$latest     wake     \
statfile -M started                 \
rw-add \$MTAI64N d1H       earliest \
rw-max \$wake \$earliest   wake     \
sh -c '
  echo "@$wake" | s6-tai64nlocal | sed "s/^/next run time: /"
  exec "$@"' arg0                   \
rw-sleep \$wake                     \
./doit

# cat doit
#!/bin/sh
touch started &&
ftpcopy -x '/mirror/*' code.dogmap.org / ./mirror &&
touch finished