Local web service for calling scripts for DUST (amongst others if you wish).
- Add IIS to a Windows 2012/2016/2019 server
- Install nodejs
- Install URL Rewrite to IIS
- Install Application Request Routing to IIS
- Configure Reverse Proxy in IIS
git clone https://github.com/vtfk/dust-webservice.git
cd dust-webservice
npm i
Create a .env
file in the cloned repo:
EXPRESS_PORT=3000
MAX_BUFFER=10240000
ACCEPTED_PATH_ROOT=<local-full-path-to-folder>
SERVICE_PATH=<local-full-path-to-folder-containing-the-scripts>
JWT_SECRET=<SuperDuperSecretSecretKey>
PAPERTRAIL_HOST=logs.example.com
PAPERTRAIL_PORT=port
PAPERTRAIL_HOSTNAME=<coolname>
NODE_ENV=production
SERVICE_PATH can and should contain a
%service%
part to support a variaty of service endpoints.
Example: D:\Scripts\%service%\scripts
MAX_BUFFER
is total bytes to accept in stdout
Set ACCEPTED_PATH_ROOT
to the root path of where all scripts are stored. All scripts to be invoked must be directly inside the root path or in any number of sub folders.
Set JWT_SECRET
to a super duper secret 🗝 to enable JWT token auth. To disable, remove this configuration
Add PAPERTRAIL_*
and NODE_ENV
to enable papertrails logging
The user that will be running the webservice needs to have local administrative privileges to setup the Windows Service.
After the service is setup, the user no longer needs administrative privileges
- Install PM2 (A Process Manager for node.js) (Must be run with the user that will be running the webservice)
npm install -g pm2
- Move
PM2 home
toD:\PM2
- Create a new folder
D:\PM2
- Create a new System level environment variable
PM2_HOME
and set it toD:\PM2
- Open a new
cmd
and verify thatPM2_HOME
is set correctly by runningecho %PM2_HOME%
- Create a new folder
- Start the webservice in
pm2
and save the current process list- Open a new
cmd
- Navigate to the folder containing the webservice you cloned
- Start the webservice in
pm2
by runningpm2 start index.js
- If all goes well, you should see a table containing your service and it should have it's
status
set toonline
- To save the current process list, run
pm2 save
- You should see
Successfully saved in D:\PM2\dump.pm2
- Open a new
- Install pm2-windows-service (Must be run with the user that will be running the webservice)
npm install -g pm2-windows-service
- Open a new
cmd
as administrator (this must be with the same user that will be running the webservice!)pm2-service-install -n DUST
? Perform environment setup (recommended)
: Yes? Set PM2_HOME
: Yes? PM2_HOME value...
: D:\PM2? Set PM2_SERVICE_SCRIPTS...
: No? Set PM2_SERVICE_PM2_DIR...
: Yes? Specify the directory containing the pm2 version to be used by the service
: C:\Users%username-of-user-to-run-the-webservice%\AppData\Roaming\npm\node_modules\pm2\index.js- PM2 service installed and started
- Set Windows Service to log on as the correct user account
- Open
services.msc
- Open
Properties
on the Windows Service - Go to the
Log On
tab - Select
This account
- Click
browse
and choose the correct user - Put in users password
Stop
andStart
the Windows Service to switch to the new user
- Open
If you remove administrative privileges from the user running the Windows Service, the user doesn't have access to start the service on Windows startup. To go around this, create a scheduled task that will start the service on Windows Startup
- Open
Task Scheduler
as administrator- Create a new task
- Set
SYSTEM
as the running user for the task - Activate
Run with highest privileges
- Add a trigger for
At startup
and set a delay for 1 minute to allow other required Windows services to launch first - Add a action:
- Program:
powershell
- Add arguments:
-nologo -noninteractive -command Start-Service -Name "DUST" -Confirm:$False
- Program: