From adc5a3476d2a8d4888410efd3dda72de4f8c39d4 Mon Sep 17 00:00:00 2001 From: kalazus Date: Tue, 13 Feb 2024 18:14:53 +0300 Subject: [PATCH] add fooocus usage check --- scripts/entrypoint.sh | 8 +++++++- scripts/vast_usage.sh | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 scripts/vast_usage.sh diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index 6e31453..31e1c3f 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -22,4 +22,10 @@ linkdir models # Start application cd $ORIGINALDIR -python entry_with_update.py --listen --port 3001 ${CMDARGS} > $DATADIR/fooocus.log 2>&1 +FOOOCUS_LOGS=$DATADIR/fooocus.log +python entry_with_update.py --listen --port 3001 ${CMDARGS} > $FOOOCUS_LOGS 2>&1 & + +# check usage +touch $FOOOCUS_LOGS +vast_usage 20 $FOOOCUS_LOGS + diff --git a/scripts/vast_usage.sh b/scripts/vast_usage.sh new file mode 100755 index 0000000..3f6bd79 --- /dev/null +++ b/scripts/vast_usage.sh @@ -0,0 +1,22 @@ +not_used_action() { + pip install vastai + vastai stop instance $CONTAINER_ID +} + +check_usage() { + if [[ ! -f $2 ]]; then + echo "File not found" + exit 1 + fi + local timeout=$(($1 * 60)) + local timeleft=$timeout + while [[ $timeleft -gt 0 ]]; do + echo $timeleft + sleep $timeleft + local timeleft=$(($timeout - ($(date +%s) - $(date -r $2 +%s)))) + done + echo "Self destruction" + not_used_action +} + +check_usage $1 $2