From 90047161cb1b87e62a1ccdd6e30016aca2442944 Mon Sep 17 00:00:00 2001 From: kytv Date: Thu, 13 Feb 2014 22:13:21 +0000 Subject: [PATCH] scripts: add optional support for "timeout"; allow site-updater to be called directly Sometimes the mtn syncs hang until aborted. Well, my syncing with welterde and echelon would hang periodically until I added the same timeout support I'm adding here. In short, if Montone's action has not completed within 20 minutes, forcably kill the process. /usr/bin/timeout is a part of coreutils so most (all?) Linux distributions should have it but I don't require timeout to exist. If "timeout" can be found, it'll be used. Also, set site-updater.sh to change to the directory in which the script is located. This way one can give an absolute path in a cronjob. Both of these changes should be low risk. --- etc/update.vars | 7 +++++++ site-updater.sh | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/etc/update.vars b/etc/update.vars index 5eeac2f1..4c3aa5f3 100644 --- a/etc/update.vars +++ b/etc/update.vars @@ -1,3 +1,10 @@ MTNURL=127.0.0.1:8998 MTNBRANCH=i2p.www TOUCHFILE=/tmp/2fcd2f17-c293-4f77-b4c9-9b266ba70daa +TIMEOUT="20m" + +if [ $(which timeout) ]; then + MTN="timeout $TIMEOUT mtn" +else + MTN="mtn" +fi diff --git a/site-updater.sh b/site-updater.sh index 73f77c67..02a644f7 100755 --- a/site-updater.sh +++ b/site-updater.sh @@ -1,11 +1,12 @@ -#!/bin/sh +#!/bin/sh -x +cd $(dirname $0) . ./etc/update.vars TMP=$(mktemp XXXXXXXXXX) trap 'rm -f $TMP;exit' 0 1 2 15 -mtn pull "mtn://$MTNURL?$MTNBRANCH" -mtn up 2>&1 | tee $TMP +$MTN pull "mtn://$MTNURL?$MTNBRANCH" +$MTN up 2>&1 | tee $TMP if grep "^mtn: \(add\|patch\|dropp\|updat\)\(ed\|ing\) 'i2p2www/translations/" "$TMP" >/dev/null ; then