Beispiel #1
0
    def _write_err_trap(cls, handle, job_conf):
        """Write error trap.

        Note that all job-file scripting must be bash- and ksh-compatible,
        hence use of "typeset" below instead of the more sensible but
        bash-specific "local".

        """
        fail_signals_string = " ".join(
            BATCH_SYS_MANAGER.get_fail_signals(job_conf))
        handle.write(r"""

# TRAP ERROR SIGNALS:
set -u # Fail when using an undefined variable
FAIL_SIGNALS='""" + fail_signals_string + """'
TRAP_FAIL_SIGNAL() {
    typeset SIGNAL=$1
    echo "Received signal $SIGNAL" >&2
    typeset S=
    for S in ${VACATION_SIGNALS:-} $FAIL_SIGNALS; do
        trap "" $S
    done
    if [[ -n ${CYLC_TASK_LOG_ROOT:-} ]]; then
        {
            echo "CYLC_JOB_EXIT=$SIGNAL"
            date -u +'CYLC_JOB_EXIT_TIME=%FT%H:%M:%SZ'
        } >>$CYLC_TASK_LOG_ROOT.status
    fi
    cylc task failed "Task job script received signal $@"
    exit 1
}
for S in $FAIL_SIGNALS; do
    trap "TRAP_FAIL_SIGNAL $S" $S
done
unset S""")

        vacation_signal = BATCH_SYS_MANAGER.get_vacation_signal(job_conf)
        if vacation_signal:
            handle.write(r"""

# TRAP VACATION SIGNALS:
VACATION_SIGNALS='""" + vacation_signal + r"""'
TRAP_VACATION_SIGNAL() {
    typeset SIGNAL=$1
    echo "Received signal $SIGNAL" >&2
    typeset S=
    for S in $VACATION_SIGNALS $FAIL_SIGNALS; do
        trap "" $S
    done
    if [[ -n ${CYLC_TASK_LOG_ROOT:-} && -f $CYLC_TASK_LOG_ROOT.status ]]; then
        rm -f $CYLC_TASK_LOG_ROOT.status
    fi
    cylc task message -p WARNING "Task job script vacated by signal $@"
    exit 1
}
S=
for S in $VACATION_SIGNALS; do
    trap "TRAP_VACATION_SIGNAL $S" $S
done
unset S""")
Beispiel #2
0
 def _write_directives(cls, handle, job_conf):
     """Job directives."""
     lines = BATCH_SYS_MANAGER.format_directives(job_conf)
     if lines:
         handle.write('\n\n# DIRECTIVES:')
         for line in lines:
             handle.write('\n' + line)
Beispiel #3
0
 def _write_prelude(cls, handle, job_conf):
     """Job script prelude."""
     # Environment variables for prelude
     handle.write("\nexport CYLC_DIR='%s'" % (os.environ['CYLC_DIR']))
     if cylc.flags.debug:
         handle.write("\nexport CYLC_DEBUG='true'")
     for key in ['CYLC_VERSION'] + cls._get_host_item(
             job_conf, 'copyable environment variables'):
         if key in os.environ:
             handle.write("\nexport %s='%s'" % (key, os.environ[key]))
     # Variables for traps
     handle.write("\nCYLC_FAIL_SIGNALS='%s'" %
                  " ".join(BATCH_SYS_MANAGER.get_fail_signals(job_conf)))
     vacation_signals_str = BATCH_SYS_MANAGER.get_vacation_signal(job_conf)
     if vacation_signals_str:
         handle.write("\nCYLC_VACATION_SIGNALS='%s'" % vacation_signals_str)
Beispiel #4
0
    def _write_err_trap(cls, handle, job_conf):
        """Write error trap.

        Note that the job script must be bash- and ksh-compatible, hence use of
        "typeset" below instead of the more sensible but bash-specific "local".

        """
        args = {
            "signals_str": " ".join(
                BATCH_SYS_MANAGER.get_fail_signals(job_conf)),
            "priority": TaskMessage.CRITICAL,
            "message1": TASK_OUTPUT_FAILED,
            "message2": TaskMessage.FAIL_MESSAGE_PREFIX}
        handle.write(r"""

# TRAP ERROR SIGNALS:
set -u # Fail when using an undefined variable
FAIL_SIGNALS='%(signals_str)s'
TRAP_FAIL_SIGNAL() {
    typeset SIGNAL=$1
    echo "Received signal $SIGNAL" >&2
    typeset S=
    for S in ${VACATION_SIGNALS:-} $FAIL_SIGNALS; do
        trap "" $S
    done
    if [[ -n "${CYLC_TASK_MESSAGE_STARTED_PID:-}" ]]; then
        wait "${CYLC_TASK_MESSAGE_STARTED_PID}" 2>/dev/null || true
    fi
    cylc task message -p '%(priority)s' "%(message2)s$SIGNAL" '%(message1)s'
    exit 1
}
for S in $FAIL_SIGNALS; do
    trap "TRAP_FAIL_SIGNAL $S" $S
done
unset S""" % args)

        vacation_signal = BATCH_SYS_MANAGER.get_vacation_signal(job_conf)
        if vacation_signal:
            args = {
                "signals_str": vacation_signal,
                "priority": TaskMessage.WARNING,
                "message": TaskMessage.VACATION_MESSAGE_PREFIX}
            handle.write(r"""

# TRAP VACATION SIGNALS:
VACATION_SIGNALS='%(signals_str)s'
TRAP_VACATION_SIGNAL() {
    typeset SIGNAL=$1
    echo "Received signal $SIGNAL" >&2
    typeset S=
    for S in $VACATION_SIGNALS $FAIL_SIGNALS; do
        trap "" $S
    done
    if [[ -n "${CYLC_TASK_MESSAGE_STARTED_PID:-}" ]]; then
        wait "${CYLC_TASK_MESSAGE_STARTED_PID}" 2>/dev/null || true
    fi
    cylc task message -p '%(priority)s' "%(message)s$SIGNAL"
    exit 1
}
S=
for S in $VACATION_SIGNALS; do
    trap "TRAP_VACATION_SIGNAL $S" $S
done
unset S""" % args)
        if 'bash' in job_conf['job script shell']:
            handle.write("\nset -o pipefail")