From 2284271c09e6bc3dfe75847c8059f0dd71556f90 Mon Sep 17 00:00:00 2001 From: colben Date: Fri, 10 Sep 2021 17:28:48 +0800 Subject: [PATCH] update --- templates/dynamic/ext/sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/templates/dynamic/ext/sh b/templates/dynamic/ext/sh index c2c5856..52c35b8 100755 --- a/templates/dynamic/ext/sh +++ b/templates/dynamic/ext/sh @@ -11,11 +11,14 @@ set -euo pipefail export LANG=en_US.UTF-8 trap Quit EXIT +PID_FILE=/tmp/\$(basename \${0%.sh}).pid + if [ -t 0 ]; then function Print { echo -e "\033[32;1m\$(date +'[%F %T]') \$*\033[0m"; } function Warn { echo -e "\033[33;1m\$(date +'[%F %T]') \$*\033[0m"; } function Error { echo -e "\033[31;1m\$(date +'[%F %T]') \$*\033[0m"; exit 1; } else + #exec &> \$(dirname \$0).out function Print { echo -e "\$(date +'[%F %T] INFO') \$*"; } function Warn { echo -e "\$(date +'[%F %T] WARN') \$*"; } function Error { echo -e "\$(date +'[%F %T] ERRRO') \$*"; exit 1; } @@ -23,6 +26,7 @@ fi function Quit { local exitCode=\$? + rm -f \$PID_FILE [ 0 -ne \$exitCode ] && Error Failed to xxxx! [ -z "\${END:-}" ] && echo && Error Interrupted manually! Print Succeeded to xxxx. @@ -37,6 +41,8 @@ function Func2 { } function Main { + [ -e "\$PID_FILE" ] && Error Pid file \$PID_FILE already exists, quit! + echo \$\$ > \$PID_FILE Print Main ... Func1 Func2