#!/usr/bin/sh

if test $FLUX_JOB_ID; then
    FLUX_JOB_ID=$(flux job id --to=f58plain $FLUX_JOB_ID)
fi
unitname=flux-prolog@${FLUX_JOB_ID:-unknown}

terminate() {
    systemctl stop $unitname
    exit 1
}

trap terminate INT TERM

umask 022
printenv >/run/${unitname}.env

# Run systemctl start in background and `wait` for it so that the trap
# will run immediately when signal is received:
systemctl start $unitname --quiet &
wait $!
