-
Notifications
You must be signed in to change notification settings - Fork 5
/
control.cmd
75 lines (61 loc) · 1.76 KB
/
control.cmd
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
71
72
73
74
75
@ECHO OFF
IF "%1%"=="" GOTO FAIL
IF "%1%"=="install" GOTO INSTALL
IF "%1%"=="uninstall" GOTO UNINSTALL
IF "%1%"=="start" GOTO START
IF "%1%"=="build" GOTO BUILD
IF "%1%"=="restart" GOTO RESTART
IF "%1%"=="stop" GOTO STOP
IF "%1%"=="status" GOTO STATUS
IF "%1%"=="clearapp" GOTO CLEARAPPS
IF "%1%"=="version" GOTO VERSION
:BUILD
::go build -o %~dp0/bin/elves-agent.exe -ldflags "-H windowsgui" %~dp0/src/agent.go
go build -o %~dp0/bin/elves-agent.exe %~dp0/src/agent.go
%~dp0/bin/elves-agent.exe -v
GOTO EXIT
:START
net start|find /i "elves-agent"
if %errorlevel% == 0 (echo "elves-agent already started..") else (net start elves-agent)
echo "elves-agent started.."
GOTO EXIT
:INSTALL
@set username=
@set /p username=administrator username:
@set pwd=
@set /p pwd=administrator password:
%~dp0\\bin\\nssm.exe install elves-agent %~dp0\\bin\\elves-agent.exe
%~dp0\\bin\\nssm.exe set elves-agent AppParameters "-r %~dp0"
%~dp0\\bin\\nssm.exe set elves-agent Description "elves-agent"
%~dp0\\bin\\nssm.exe set elves-agent Start SERVICE_DELAYED_AUTO_START
%~dp0\\bin\\nssm.exe set elves-agent ObjectName .\%username% %pwd%
GOTO EXIT
:UNINSTALL
sc delete elves-agent
GOTO EXIT
:STARTFAIL
echo "elves-agent start fail.."
GOTO EXIT
:STOP
net start|find /i "elves-agent"
if %errorlevel% == 0 (net stop elves-agent)
echo "elves-agent stoped.."
GOTO EXIT
:STATUS
net start|find /i "elves-agent"
if %errorlevel% == 0 (echo "elves-agent started..") else (echo "elves-agent stoped..")
GOTO EXIT
:RESTART
net start|find /i "elves-agent"
if %errorlevel% == 0 (net stop elves-agent)
net start elves-agent
GOTO START
:CLEARAPPS
%~dp0/bin/elves-agent.exe -clear
GOTO EXIT
:VERSION
%~dp0/bin/elves-agent.exe -v
GOTO EXIT
:FAIL
echo "build|install|start|stop|restart|status|uninstall|cleanapp|version"
:EXIT