#!/bin/sh

#
# This file is part of tej
# https://github.com/remram44/tej
#
# Job starting wrapper
# Started on the server, detached, by the submit script
#
# Arguments:
#   1. script filename
#

(date; echo "start $@"; pwd) >> "$(dirname "$0")/../tej.log"

job_dir="$(pwd)"
script="$1"


# Starts program
chmod +x "$script" 2>&1
script="$(dirname "$script")/$(basename "$script")"
"$script" &
pid=$!

# Writes status file
(echo "running"; echo $pid) > ../status

wait $pid
exitcode=$?

(date; echo "finished $@"; echo $exitcode) >> "$(dirname "$0")/../tej.log"

# Updates status file
(echo "finished"; echo $exitcode) > ../status

exit 0
