diff --git a/.gitignore b/.gitignore index abea519..37b62a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ /.project /config.sh +/log/* +!/log/.placeholder .directory +nohup.out \ No newline at end of file diff --git a/README b/README index 5271565..a1aef73 100644 --- a/README +++ b/README @@ -4,9 +4,9 @@ run all commands from root (as superuser) install dependency packages: - you need: bash sudo uuid-runtime aufs-tools fuse genisoimage + you need: bash sudo uuid-runtime aufs-tools fuse genisoimage mutt for apt based OS use command: - apt-get install bash sudo uuid-runtime aufs-tools fuse genisoimage + apt-get install bash sudo uuid-runtime aufs-tools fuse genisoimage mutt create and edit config file: @@ -20,6 +20,15 @@ create and edit config file: $BASE_DIR/chrooter/chrooter.sh $@ } OPENTOONZ_TESTING_TAG="morevna" + export EMAIL_FAILED="e@mail.org" + export EMAIL_SUCCESS="$EMAIL_FAILED" + export EMAIL_SUBJECT="builder task finished" + + for emails configure ~/.muttrc, for example: + set smtp_url=smtps://login:password@server.org + set from=e@mail.org + set record= + see "background tasks" below download virtual environment: @@ -183,6 +192,15 @@ see also env-builder-data/build/script/common/manager.sh +Background tasks: + to call task in background use: + backgrouns.sh some_command + command will run in background and result will be sent to email (see config.sh) + if you do not want to receive emai about success result (look only errors), call: + backgrouns.sh -q some_command + logs stored in log/background.log + + Troubles: sometimes virtual environmens does not unmounted properly to clear this you need to unmount all mounts for */chrooter-* @@ -193,6 +211,10 @@ Troubles: umount "/some_path/chrooter-SOME_UUID" or with "force" option umount -f "/some_path/chrooter-SOME_UUID" + or with "lazy" option + umount -l "/some_path/chrooter-SOME_UUID" + and check againt with + mount after that remove the files you MUST do unmount before, if some dir are still mounted you can remove some system files diff --git a/background.sh b/background.sh new file mode 100755 index 0000000..c638277 --- /dev/null +++ b/background.sh @@ -0,0 +1,25 @@ +set -e + + +BASE_DIR=$(cd `dirname "$0"`; pwd) +CONFIG_FILE="$BASE_DIR/config.sh" +if [ -f "$CONFIG_FILE" ]; then + source "$CONFIG_FILE" +fi + + +LOG_FILE="$BASE_DIR/log/background.log" + +echo "-------------------------------" >> "$LOG_FILE" +date >> "$LOG_FILE" +echo background.sh "$@" >> "$LOG_FILE" +echo "-------------------------------" >> "$LOG_FILE" + +if [ "$1" == "-q" ]; then + export EMAIL_SUCCESS= + nohup "$BASE_DIR/withemail.sh" ${@:2} &>> "$LOG_FILE" & +else + nohup "$BASE_DIR/withemail.sh" $@ &>> "$LOG_FILE" & +fi + +echo "task now in backround" diff --git a/config.sh.blank b/config.sh.blank index 5c4a09e..a03a6df 100644 --- a/config.sh.blank +++ b/config.sh.blank @@ -29,3 +29,6 @@ chrooter() { # configure chrooter command # OPENTOONZ_TESTING_TAG="test" # uses in build-opentoonz-testing.sh for naming out packages # SYNFIGSTUDIO_TESTING_TAG="test" # uses in build-synfigstudio.sh for naming out packages +#export EMAIL_FAILED="e@mail.org" +#export EMAIL_SUCCESS="$EMAIL_FAILED" +#export EMAIL_SUBJECT="builder task finished" diff --git a/gen-name.sh b/gen-name.sh index 7e1d4d8..a71f78a 100644 --- a/gen-name.sh +++ b/gen-name.sh @@ -5,10 +5,10 @@ gen_name_template() { local PLATFORM="$3" local ARCH="$4" local SUFFIX="$5" - + if [ ! -z "$TAG" ]; then TAG="-$TAG" fi - + echo "$NAME-%VERSION%$TAG-%DATE%-$PLATFORM$ARCH-%COMMIT%$SUFFIX" } diff --git a/log/.placeholder b/log/.placeholder new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/log/.placeholder diff --git a/withemail.sh b/withemail.sh new file mode 100755 index 0000000..aeefa7f --- /dev/null +++ b/withemail.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +set -e +set -o pipefail + +# accepts environment vars +# EMAIL_SUCCESS +# EMAIL_FAILED +# EMAIL_QUIET +# EMAIL_SUBJECT +# EMAIL_BODY + + +if [ ! -z "$EMAIL_QUIET" ]; then + # report only errors + EMAIL_SUCCESS= +fi + +if [ -z "$EMAIL_SUBJECT" ]; then + EMAIL_SUBJECT="builder task finished" +fi + +COMMAND="$@" +LOG_FILE="/tmp/withemail-`uuidgen`.log" +touch "$LOG_FILE" + + +send_email() { + local EMAIL="$1" + local MESSAGE="$2" + + echo "$MESSAGE" + + if [ ! -z "$EMAIL" ]; then + mutt -s "$EMAIL_SUBJECT - $MESSAGE" -a "$LOG_FILE" -- "$EMAIL" << EOF +$EMAIL_BODY + +Command: + $COMMAND + +$MESSAGE +EOF + echo "email sent to $EMAIL" + fi + rm "$LOG_FILE" +} + + +("$@" 2>&1 | tee "$LOG_FILE") || (send_email "$EMAIL_FAILED" "FAILED" && false) + +send_email "$EMAIL_SUCCESS" "SUCCESS"