summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-07-15 12:19:18 +0200
committerErich Eckner <git@eckner.net>2019-07-15 12:19:18 +0200
commitd022cc831de17d10bd3fed46b38c3dac3cd1341f (patch)
tree40af17ae92c9ae42d8690d9d3a8922a21a0de8ff /bin
parenta80cb33621fbf37a64fe39b550ae25088588149c (diff)
downloadbuilder-d022cc831de17d10bd3fed46b38c3dac3cd1341f.tar.xz
bin/slave-build-connect: save exit_code and duration of run commands
Diffstat (limited to 'bin')
-rwxr-xr-xbin/slave-build-connect57
1 files changed, 39 insertions, 18 deletions
diff --git a/bin/slave-build-connect b/bin/slave-build-connect
index 5460b7e..13fcf18 100755
--- a/bin/slave-build-connect
+++ b/bin/slave-build-connect
@@ -44,25 +44,46 @@ if [ "x${SSH_ORIGINAL_COMMAND%% *}" = 'xget-assignment' ] || \
slave_id="${infos%% *}"
operator="${infos#* }"
- # shellcheck disable=SC2016
- {
- printf 'INSERT IGNORE INTO `ssh_log` (`build_slave`,`action`,`parameters`)'
- printf ' VALUES (%s' \
- "${slave_id}"
- printf ',from_base64("%s")' \
- "$(
- printf '%s' "${SSH_ORIGINAL_COMMAND%% *}" | \
- base64 -w0
- )" \
- "$(
- printf '%s' "${SSH_ORIGINAL_COMMAND#* }" | \
- base64 -w0
- )"
- printf ');\n'
- } | \
- mysql_run_query 'unimportant'
+ ssh_log_id=$(
+ # shellcheck disable=SC2016
+ {
+ printf 'INSERT IGNORE INTO `ssh_log` (`build_slave`,`action`,`parameters`)'
+ printf ' VALUES (%s' \
+ "${slave_id}"
+ printf ',from_base64("%s")' \
+ "$(
+ printf '%s' "${SSH_ORIGINAL_COMMAND%% *}" | \
+ base64 -w0
+ )" \
+ "$(
+ printf '%s' "${SSH_ORIGINAL_COMMAND#* }" | \
+ base64 -w0
+ )"
+ printf ');\n'
+ printf 'SELECT LAST_INSERT_ID();\n'
+ } | \
+ mysql_run_query 'unimportant'
+ )
+ exit_code=0
+
+ slave="$1" slave_id="${slave_id}" operator="${operator}" SKIP_COMMAND_LOG=1 /bin/sh -c "${base_dir}/bin/${SSH_ORIGINAL_COMMAND}" \
+ || exit_code=$?
+
+ if [ -n "${ssh_log_id}" ]; then
+ # shellcheck disable=SC2016
+ {
+ printf 'UPDATE `ssh_log`'
+ printf ' SET `ssh_log`.`duration`=TIME_TO_SEC(TIMEDIFF(NOW(),`ssh_log`.`date`)),'
+ printf '`ssh_log`.`exit_code`=%s' \
+ "${exit_code}"
+ printf ' WHERE `ssh_log`.`id`=%s' \
+ "${ssh_log_id}"
+ printf ';\n'
+ } | \
+ mysql_run_query 'unimportant'
+ fi
- slave="$1" slave_id="${slave_id}" operator="${operator}" SKIP_COMMAND_LOG=1 /bin/sh -c "${base_dir}/bin/${SSH_ORIGINAL_COMMAND}"
+ exit ${exit_code}
else