diff --git a/src/windows/remove-service.ps1 b/src/windows/remove-service.ps1 index 4589d67..3bdf32c 100644 --- a/src/windows/remove-service.ps1 +++ b/src/windows/remove-service.ps1 @@ -2,6 +2,7 @@ Write-Host "=== Remove Service ===" $PM2_HOME = $env:PM2_HOME; $PM2_SERVICE_DIRECTORY = $env:PM2_SERVICE_DIRECTORY; +$PM2_SERVICE_NAME = $env:PM2_SERVICE_NAME; function Stop-Service { param([string] $name) @@ -85,7 +86,7 @@ if (($null -ne $PM2_SERVICE_DIRECTORY) -and (Test-Path $PM2_SERVICE_DIRECTORY)) Write-Host "Running Node service uninstall script.." -node "$wd\src\windows\service-management\uninstall.js" $PM2_SERVICE_DIRECTORY +node "$wd\src\windows\service-management\uninstall.js" $PM2_SERVICE_DIRECTORY $PM2_SERVICE_NAME if ($? -ne $True) { Set-Location $wd diff --git a/src/windows/service-management/install.js b/src/windows/service-management/install.js index 0074734..78e00a4 100644 --- a/src/windows/service-management/install.js +++ b/src/windows/service-management/install.js @@ -22,7 +22,7 @@ for (const key of ['PM2_HOME', 'PM2_INSTALL_DIRECTORY', 'PM2_SERVICE_DIRECTORY'] } } -let [directory, user, name, description] = process.argv.slice(2); +let [directory, name, description, user] = process.argv.slice(2); // Pull the process directory, service name, and service description from the script parameters or pricess env, or use a default directory = directory || process.env.PM2_SERVICE_DIRECTORY || 'c:\\ProgramData\\pm2\\service\\'; diff --git a/src/windows/service-management/uninstall.js b/src/windows/service-management/uninstall.js index 3e2a586..c7b33a0 100644 --- a/src/windows/service-management/uninstall.js +++ b/src/windows/service-management/uninstall.js @@ -14,7 +14,7 @@ const { Service } = require('node-windows'); // Create a "Service" object -let [directory, user, name, description] = process.argv.slice(2); +let [directory, name, description, user] = process.argv.slice(2); // Pull the process directory, service name, and service description from the script parameters or pricess env, or use a default directory = directory || process.env.PM2_SERVICE_DIRECTORY || 'c:\\ProgramData\\pm2\\service\\'; diff --git a/src/windows/setup-service.ps1 b/src/windows/setup-service.ps1 index 07024f9..883a309 100644 --- a/src/windows/setup-service.ps1 +++ b/src/windows/setup-service.ps1 @@ -78,14 +78,19 @@ function Install-Service-Files { } function Install-Service { - param([string] $Directory, [string] $User) + param( + [string] $Directory, + [string] $Name = "PM2", + [string] $Description = "Node process manager", + [string] $User + ) Write-Host "Running Node service install script.." $wd = (Get-Item -Path '.\' -Verbose).FullName Set-Location $PM2_SERVICE_DIRECTORY - node "$wd\src\windows\service-management\install.js" $Directory $User + node "$wd\src\windows\service-management\install.js" $Directory $Name $Description $User Set-Location $wd if ($? -ne $True) { @@ -315,7 +320,7 @@ Set-Permissions -Directory $PM2_SERVICE_DIRECTORY -User $ServiceUser # Create the service itself # Install-Service -Directory $PM2_SERVICE_DIRECTORY -User $ServiceUser -Install-Service -Directory $PM2_SERVICE_DIRECTORY +Install-Service -Directory $PM2_SERVICE_DIRECTORY # -Name $ServiceName -Description $ServiceDescription # There is currently (May 2020) an issue with the way that node-windows uses user credentials. # Sending it the local service user fails, so instead: # - Create the service to run as LocalSystem, but don't start it