-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_service.bat
84 lines (67 loc) · 2.92 KB
/
create_service.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
@echo off
cd /D "%~dp0"
:: Set the correct directory. Only %~dp0 does not work because of its trailing backslash
set HOME=%CD%
:: check for permissions first
:: we need admin priviliges for NSSM
goto check_Permissions
:check_Permissions
echo Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Success: Administrative permissions confirmed. Starting config tool
goto startInstallationRobots
) else (
echo Failure: Current permissions inadequate. Please right click bat and run as Administrator.
pause
exit /B 1
)
pause
:: only gets called when we have admin priviliges
:startInstallationRobots
echo Installing service
:: Set your service name and its description here
set SERVICE_NAME=AeronNfGoSchedules
set SERVICE_DESCRIPTION=AeronNfGoSchedules
:: replace with the absolute path where node.exe can be found
nssm install %SERVICE_NAME% "C:\Program Files\nodejs\node.exe"
nssm set %SERVICE_NAME% Description "%SERVICE_DESCRIPTION%"
nssm set %SERVICE_NAME% AppDirectory "%HOME%"
:: replace index.js with the name of your script
nssm set %SERVICE_NAME% AppParameters "%HOME%\dist\schedules\server.js"
:: optionally set the out.log and error.log paths which will be used for stdouts and sterr messages
:: better: use a logging framework like winston
md logs
nssm set %SERVICE_NAME% AppStdout "%HOME%\logs\out_robots.log"
nssm set %SERVICE_NAME% AppStderr "%HOME%\logs\error_robots.log"
nssm set %SERVICE_NAME% AppRotateFiles 1
nssm set %SERVICE_NAME% AppRotateSeconds 86400
nssm set %SERVICE_NAME% AppRotateBytes 10000000
:: Start the service
nssm start %SERVICE_NAME%
echo Successfully installed and started service %SERVICE_NAME%
goto startInstallationQueue
:: only gets called when we have admin priviliges
:startInstallationQueue
echo Installing service
:: Set your service name and its description here
set SERVICE_NAME=AeronNfGoQueue
set SERVICE_DESCRIPTION=AeronNfGoQueue
:: replace with the absolute path where node.exe can be found
nssm install %SERVICE_NAME% "C:\Program Files\nodejs\node.exe"
nssm set %SERVICE_NAME% Description "%SERVICE_DESCRIPTION%"
nssm set %SERVICE_NAME% AppDirectory "%HOME%"
:: replace index.js with the name of your script
nssm set %SERVICE_NAME% AppParameters "%HOME%\dist\queues\queue.js"
:: optionally set the out.log and error.log paths which will be used for stdouts and sterr messages
:: better: use a logging framework like winston
md logs
nssm set %SERVICE_NAME% AppStdout "%HOME%\logs\out_queue.log"
nssm set %SERVICE_NAME% AppStderr "%HOME%\logs\error_queue.log"
nssm set %SERVICE_NAME% AppRotateFiles 1
nssm set %SERVICE_NAME% AppRotateSeconds 86400
nssm set %SERVICE_NAME% AppRotateBytes 10000000
:: Start the service
nssm start %SERVICE_NAME%
echo Successfully installed and started service %SERVICE_NAME%
pause