diff --git a/scriptbuilder/src/main/resources/functions/forget.cmd b/scriptbuilder/src/main/resources/functions/forget.cmd new file mode 100644 index 0000000000..1d8dd8575e --- /dev/null +++ b/scriptbuilder/src/main/resources/functions/forget.cmd @@ -0,0 +1,29 @@ +:forget + SETLOCAL + set FOUND_PID= + set NEXT_MINUTE= + set INSTANCE_NAME=%1 + shift + set SCRIPT=%1 + shift + set LOG_DIR=%1 + shift + CALL :findProcess %INSTANCE_NAME% + if defined FOUND_PID ( + echo %INSTANCE_NAME% already running pid [%FOUND_PID%] + ) else ( + CALL :nextMinute + set _DATE=%DATE:~4% + set CMD=schtasks /create /sd %_DATE% /tn %INSTANCE_NAME% /ru System /tr "cmd /c title %INSTANCE_NAME%&%SCRIPT% >%LOG_DIR%\stdout.log 2>%LOG_DIR%\stderr.log" /sc:once /st %NEXT_MINUTE% + echo %INSTANCE_NAME% will start at %NEXT_MINUTE% + set SECONDS=%TIME:~6,2% + set /a SECOND=60-SECONDS + %CMD% >NUL + ping -n %SECONDS% 127.0.0.1 > NUL 2>&1 + CALL :findProcess %INSTANCE_NAME% + if not defined FOUND_PID ( + set EXCEPTION=%INSTANCE_NAME% did not start + abort + ) + ) + exit /b 0 diff --git a/scriptbuilder/src/main/resources/functions/forget.sh b/scriptbuilder/src/main/resources/functions/forget.sh new file mode 100644 index 0000000000..0fe60518fc --- /dev/null +++ b/scriptbuilder/src/main/resources/functions/forget.sh @@ -0,0 +1,20 @@ +function forget { + unset FOUND_PID; + [ $# -eq 3 ] || { + abort "forget requires parameters INSTANCE_NAME SCRIPT LOG_DIR" + return 1 + } + local INSTANCE_NAME="$1"; shift + local SCRIPT="$1"; shift + local LOG_DIR="$1"; shift + mkdir -p $LOG_DIR + findPid $INSTANCE_NAME + [ -n "$FOUND_PID" ] && { + echo $INSTANCE_NAME already running pid [$FOUND_PID] + } || { + nohup $SCRIPT >$LOG_DIR/stdout.log 2>$LOG_DIR/stderr.log & + findPid $INSTANCE_NAME + [ -n "$FOUND_PID" ] || abort "$INSTANCE_NAME did not start" + } + return 0 +} diff --git a/scriptbuilder/src/main/resources/functions/nextMinute.cmd b/scriptbuilder/src/main/resources/functions/nextMinute.cmd new file mode 100644 index 0000000000..36eb107941 --- /dev/null +++ b/scriptbuilder/src/main/resources/functions/nextMinute.cmd @@ -0,0 +1,16 @@ +:nextMinute + SETLOCAL + set HOURS=%TIME:~0,2% + set MINUTES=%TIME:~3,2% + + set /a HOURS=%HOURS% + set /a MINUTES+=1 + + if %MINUTES% EQU 60 (set MINUTES=0&set /a HOURS+=1) + if %HOURS% EQU 24 (set HOURS=0) + + if %HOURS% LSS 10 set HOURS=0%HOURS% + if %MINUTES% LSS 10 set MINUTES=0%MINUTES% + + ENDLOCAL&SET NEXT_MINUTE=%HOURS%:%MINUTES%:00 + exit /b 0 diff --git a/scriptbuilder/src/main/resources/functions/stop.cmd b/scriptbuilder/src/main/resources/functions/stop.cmd new file mode 100644 index 0000000000..7647c58c84 --- /dev/null +++ b/scriptbuilder/src/main/resources/functions/stop.cmd @@ -0,0 +1,9 @@ +:abort + CALL :findProcess %INSTANCE_NAME% + if defined _pid ( + echo stopping %INSTANCE_NAME% + TASKKILL /F /T /PID %FOUND_PID% >NUL + ) + schtasks /end /tn %INSTANCE_NAME% >NUL 2>NUL + schtasks /delete /tn %INSTANCE_NAME% /F >NUL 2>NUL + exit /b 0