summaryrefslogtreecommitdiffstats
path: root/src/ceph/qa/nightlies/cron_wrapper
diff options
context:
space:
mode:
authorQiaowei Ren <qiaowei.ren@intel.com>2018-01-04 13:43:33 +0800
committerQiaowei Ren <qiaowei.ren@intel.com>2018-01-05 11:59:39 +0800
commit812ff6ca9fcd3e629e49d4328905f33eee8ca3f5 (patch)
tree04ece7b4da00d9d2f98093774594f4057ae561d4 /src/ceph/qa/nightlies/cron_wrapper
parent15280273faafb77777eab341909a3f495cf248d9 (diff)
initial code repo
This patch creates initial code repo. For ceph, luminous stable release will be used for base code, and next changes and optimization for ceph will be added to it. For opensds, currently any changes can be upstreamed into original opensds repo (https://github.com/opensds/opensds), and so stor4nfv will directly clone opensds code to deploy stor4nfv environment. And the scripts for deployment based on ceph and opensds will be put into 'ci' directory. Change-Id: I46a32218884c75dda2936337604ff03c554648e4 Signed-off-by: Qiaowei Ren <qiaowei.ren@intel.com>
Diffstat (limited to 'src/ceph/qa/nightlies/cron_wrapper')
-rwxr-xr-xsrc/ceph/qa/nightlies/cron_wrapper53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/ceph/qa/nightlies/cron_wrapper b/src/ceph/qa/nightlies/cron_wrapper
new file mode 100755
index 0000000..ced5a32
--- /dev/null
+++ b/src/ceph/qa/nightlies/cron_wrapper
@@ -0,0 +1,53 @@
+#!/bin/bash
+# /nightlies/cron_wrapper.sh
+
+# check for no argument case and stop
+if [ -z $1 ]; then
+ echo "need argument"
+ exit 1
+fi
+
+# set permanent $LOG file var
+LOG="/var/log/crontab-nightlies-log/crontab.log"
+# set $LOG_LOCKED_ERR in case locking failed
+LOG_LOCK_ERR="/var/log/crontab-nightlies-log/crontab_lock_problem.$$"
+
+# temp files to store stdout and stderr
+# named with the PID of this script in their name so they'll be unique
+STDERR="/var/tmp/stderr.$$"
+STDOUT="/var/tmp/stdout.$$"
+
+# $STDOUT and $STDERR are removed when the script exits for any reason
+trap "rm -f $STDOUT $STDERR" 0
+
+# run a command from this script's argument
+# redirect stdout to $STDOUT file and redirect stderr to $STDERR file
+
+DATE=$(date)
+echo -n "$DATE: " >> $STDOUT
+echo "Running command: $@" >> $STDOUT
+"$@" > $STDOUT 2> $STDERR
+
+# get return code from the command run
+code=$?
+
+if [ $code != 0 ] ; then
+ # echoing to stdout/stderr makes cron send email
+ echo "stdout:"
+ cat $STDOUT
+ echo "stderr:"
+ cat $STDERR
+else
+ # normal exit: just log stdout
+
+ # lock $LOG with file descriptor 200
+ exec 200>>$LOG
+ # if $LOG is locked by other process - wait for 20 sec
+ flock -w 20 200 || LOG=$LOG_LOCK_ERR
+ echo "stdout:" >> $LOG
+ cat $STDOUT >> $LOG
+ echo "stderr:" >> $LOG
+ cat $STDERR >> $LOG
+ # unlock
+ flock -u 200
+fi