forked from gazbert/bxbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bxbot.bat
70 lines (61 loc) · 1.89 KB
/
bxbot.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
@echo off
REM
REM Bare bones script for starting BX-bot on Windows systems.
REM
REM Could be made better, but will do for now...
REM
REM You need the Java 11 JDK installed.
REM
REM This script expects all the jar files to live in the lib_dir.
REM
REM You can change the bxbot_jar var to the version you want to run; it has been defaulted to the current release.
REM
REM You can start, stop, and query the bot's status: bxbot.bat [start|stop|status]
REM
SET lib_dir=.\libs
REM log4j2 config file location
SET log4j2_config=.\config\log4j2.xml
REM The BX-bot 'fat' jar (Spring Boot app containing all the dependencies)
SET bxbot_jar=bxbot-app-1.0.1.jar
REM PID file for checking if bot is running
SET pid_file=.\.bxbot.pid
REM Process args passed to script. Ouch. Is there a Windows equivalent of a Bash 'case' ?
IF %1.==. GOTO:invalidArgs
IF "%1"=="start" GOTO:start
IF "%1"=="stop" GOTO:stop
IF "%1"=="status" GOTO:status
IF NOT "%1"=="status" GOTO:invalidArgs
:start
REM TODO: Check if bot is already running before trying to start it!
SET START_TIME=%time%
ECHO Starting BX-bot...
START "BX-bot - %START_TIME%" java -Xmx64m -Xss256k -Dlog4j.configurationFile=%log4j2_config% --illegal-access=deny -jar %lib_dir%\%bxbot_jar%
FOR /F "tokens=2" %%i in ('TASKLIST /NH /FI "WINDOWTITLE eq BX-bot - %START_TIME%"' ) DO (SET PID=%%i)
ECHO %PID% > %pid_file%
ECHO BX-bot started with PID: %PID%
GOTO:EOF
:stop
IF NOT EXIST %pid_file% (
ECHO BX-bot is not running. Nothing to stop.
) ELSE (
FOR /f %%a IN (%pid_file%) DO (
ECHO Stopping BX-bot instance running with PID: %%a ...
taskkill /F /PID %%a
DEL %pid_file%
EXIT /b
)
)
GOTO:EOF
:status
IF EXIST %pid_file% (
FOR /f %%a IN (%pid_file%) DO (
ECHO BX-bot is running with PID: %%a
EXIT /b
)
) ELSE (
ECHO BX-bot is not running.
)
GOTO:EOF
:invalidArgs
ECHO Invalid args. Usage: bxbot.bat [start^|stop^|status]
GOTO:EOF