[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [bridgedb/master] Add script for killing the the server after N seconds; avoid running forever in CI.



commit 93ed9cc97060a6e70af0478984c2aa5d7b51c7b3
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Tue Oct 15 14:22:49 2013 +0000

    Add script for killing the the server after N seconds; avoid running forever in CI.
---
 scripts/executioner |   35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/scripts/executioner b/scripts/executioner
new file mode 100755
index 0000000..085b74d
--- /dev/null
+++ b/scripts/executioner
@@ -0,0 +1,35 @@
+#!/bin/bash
+##############################################################################
+#
+# executioner
+# -----------
+# Run $@ for $1 seconds and then kill the process.
+#
+# :authors: Isis Agora Lovecruft, 0x2cdb8b35
+# :date: 21 April 2013
+# :version: 0.0.1
+##############################################################################
+
+set -vx --
+
+function killitwithfire () {
+    trap - ALRM
+    kill -ALRM $prog 2>/dev/null
+    kill -9 $! 2>/dev/null && exit 0
+}
+
+function waitforit () {
+    trap "killitwithfire" ALRM
+    sleep $1& wait
+    kill -ALRM $$
+}
+
+waitforit $1& prog=$! ; shift ;
+trap "killitwithfire" ALRM INT
+"$@"& wait $!
+RET=$?
+if [[ "$(ps -ef | awk -v pid=$prog '$2==pid{print}{}')" != "" ]]; then
+    kill -ALRM $prog
+    wait $prog
+fi
+exit $RET



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits