    [[OUTPUT]]
        script = """
            cylc__job__wait_cylc_message_started
            # Handle db locks.
            for i in {0..10}; do
                ctb-select-task-states \
                    "${CYLC_WORKFLOW_RUN_DIR}" "${CYLC_TASK_NAME}" \
                    > "${CYLC_WORKFLOW_RUN_DIR}/$OUTPUT_SUFFIX-db" && break
                sleep 1
            done
        """
    [[shutdown]]
        inherit = OUTPUT
        post-script = cylc shutdown "${CYLC_WORKFLOW_ID}"
        [[[meta]]]
            description = "Force a shutdown of the workflow"
        [[[environment]]]
            OUTPUT_SUFFIX=pre-restart
    [[output_states]]
        inherit = OUTPUT
        pre-script = cylc__job__wait_cylc_message_started
        [[[meta]]]
            description = "Wait for the restart to complete, then output states"
        [[[environment]]]
            OUTPUT_SUFFIX=post-restart
    [[finish]]
        script = true
