Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support specifying the service name & description #24

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/windows/remove-service.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/windows/service-management/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\\';
Expand Down
2 changes: 1 addition & 1 deletion src/windows/service-management/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\\';
Expand Down
11 changes: 8 additions & 3 deletions src/windows/setup-service.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down