jessety / pm2-installer

Install PM2 offline as a service on Windows or Linux. Mostly designed for Windows.
MIT License
477 stars 47 forks source link

Service does not not start on "npm run setup" #28

Open paony opened 3 years ago

paony commented 3 years ago

Description

output: D:\tmp\pm2-installer-main>npm run setup

pm2-installer@3.1.6 setup D:\tmp\pm2-installer-main node ./src/tools/script-for-os.js

pm2-installer@3.1.6 setup:windows D:\tmp\pm2-installer-main PowerShell -NoProfile -ExecutionPolicy Bypass src\windows\setup.ps1

=== Setup === === Checking Script Privileges === Script is running as administrator. === Checking Script Privileges Complete === === Checking npm Configuration === Global npm prefix location appears valid: C:\ProgramData\npm\npm Global npm cache location appears valid: C:\ProgramData\npm\npm-cache === Checking npm Configuration Complete === === Install Packages === Running on: 18.5.2021, pm2-installer 3.1.6 with node v14.17.0 and npm 6.14.13 on win32-10.0.14393. Using: pm2@4.5.6 pm2-logrotate@2.7.0

Checking connectivity to the npm registry.. Successfully connected to registry.npmjs.org. Installing packages.. C:\ProgramData\npm\npm\pm2-docker -> C:\ProgramData\npm\npm\node_modules\pm2\bin\pm2-docker C:\ProgramData\npm\npm\pm2 -> C:\ProgramData\npm\npm\node_modules\pm2\bin\pm2 C:\ProgramData\npm\npm\pm2-dev -> C:\ProgramData\npm\npm\node_modules\pm2\bin\pm2-dev C:\ProgramData\npm\npm\pm2-runtime -> C:\ProgramData\npm\npm\node_modules\pm2\bin\pm2-runtime

pm2-installer@3.1.6 postinstall C:\ProgramData\npm\npm\node_modules\pm2-installer echo 'Installing this package is not necessary. Run "npm run setup" to install pm2.'

'Installing this package is not necessary. Run "npm run setup" to install pm2.'

Attempting to create "C:\ProgramData\pm2\home" Directory "C:\ProgramData\pm2\home" does not exist, creating it.. Attempting to create "C:\ProgramData\pm2\service" Directory "C:\ProgramData\pm2\service" does not exist, creating it.. Copying service files from ".\src\windows\service\" to "C:\ProgramData\pm2\service".. Copying files complete. Attempting to grant "NT-AUTORITÄT\Lokaler Dienst" full permissions to "C:\ProgramData\pm2\home". Successfully set permissions on "C:\ProgramData\pm2\home". Attempting to grant "NT-AUTORITÄT\Lokaler Dienst" full permissions to "C:\ProgramData\pm2\service". Successfully set permissions on "C:\ProgramData\pm2\service". Running Node service install script.. service-management\install Installing Installing service "PM2" at "C:\ProgramData\pm2\service" service-management\install Complete Attempting to grant "NT-AUTORITÄT\Lokaler Dienst" full permissions to "C:\ProgramData\pm2\home". Successfully set permissions on "C:\ProgramData\pm2\home". Attempting to grant "NT-AUTORITÄT\Lokaler Dienst" full permissions to "C:\ProgramData\pm2\service". Successfully set permissions on "C:\ProgramData\pm2\service". Updating "pm2.exe" service to run as "NT AUTHORITY\LocalService" Found "pm2.exe" service: State: Stopped Status: OK Started: False Start Mode: Auto Service Type: Own Process Start Name: LocalSystem Changing service user account.. Starting service.. State is now: Start Pending State is now: Stopped State is now: Stopped State is now: Stopped

Steps to Reproduce npm run configure npm run configure-policy npm run setup

Environment D:\tmp\pm2-installer-main>npm run info

pm2-installer@3.1.6 info D:\tmp\pm2-installer-main node ./src/bundle-info/current.js Running on: 18.5.2021, pm2-installer 3.1.6 with node v14.17.0 and npm 6.14.13 on win32-10.0.14393.

Any ideas

jackiewu commented 3 years ago

you can check C:\ProgramData\pm2\service\daemon\pm2.wrapper.log if you meet security, state error message, maybe you should change identity of PM2 service to local user

haydanu commented 3 years ago

you can check C:\ProgramData\pm2\service\daemon\pm2.wrapper.log if you meet security, state error message, maybe you should change identity of PM2 service to local user

hi @jackiewu how to change the identity to local user?

ChrisDu17 commented 2 years ago

Hello from France , just to say in Windows 7, I have the same issue with the last pm2-installer 3.2.5 update.

Node version is 12.22.6 (due to Windows server 2008R2 limitations)

Output: npm run configure -> OK npm run configure-policy -> OK npm run setup

pm2-installer@3.2.5 setup D:\Users\c.gueriteau\Downloads\pm2-installer node ./src/tools/script-for-os.js

pm2-installer@3.2.5 setup:windows D:\Users\c.gueriteau\Downloads\pm2-installer PowerShell -NoProfile -ExecutionPolicy Bypass src\windows\setup.ps1

=== Setup === === Checking Script Privileges === Script is running as administrator. === Checking Script Privileges Complete === === Checking npm Configuration === Global npm prefix location appears valid: C:\ProgramData\npm\npm Global npm cache location appears valid: C:\ProgramData\npm\npm-cache === Checking npm Configuration Complete === === Install Packages === Running on: 2021-9-29, pm2-installer 3.2.5 with node v12.22.6 and npm 6.14.15 on win32-6.1.7601. Using: pm2@5.1.2 @jessety/pm2-logrotate@2.7.1 node-windows@1.0.0-beta.1 Checking connectivity to the npm registry.. Successfully connected to registry.npmjs.org. Installing packages.. C:\ProgramData\npm\npm\pm2 -> C:\ProgramData\npm\npm\node_modules\pm2\bin\pm2 C:\ProgramData\npm\npm\pm2-dev -> C:\ProgramData\npm\npm\node_modules\pm2\bin\pm2-dev C:\ProgramData\npm\npm\pm2-docker -> C:\ProgramData\npm\npm\node_modules\pm2\bin\pm2-docker C:\ProgramData\npm\npm\pm2-runtime -> C:\ProgramData\npm\npm\node_modules\pm2\bin\pm2-runtime

Attempting to create "C:\ProgramData\pm2\home" Directory "C:\ProgramData\pm2\home" already exists, no need to create it. Attempting to create "C:\ProgramData\pm2\service" Directory "C:\ProgramData\pm2\service" already exists, no need to create it. Copying service files from ".\src\windows\service\" to "C:\ProgramData\pm2\service".. Copying files complete. Attempting to grant "AUTORITE NT\SERVICE LOCAL" full permissions to "C:\ProgramData\pm2\home". Successfully set permissions on "C:\ProgramData\pm2\home". Attempting to grant "AUTORITE NT\SERVICE LOCAL" full permissions to "C:\ProgramData\pm2\service". Successfully set permissions on "C:\ProgramData\pm2\service". Running Node service install script.. service-management\install Installing Installing service "PM2" at "C:\ProgramData\pm2\service" Already installed. service-management\install Complete Attempting to grant "AUTORITE NT\SERVICE LOCAL" full permissions to "C:\ProgramData\pm2\home". Successfully set permissions on "C:\ProgramData\pm2\home". Attempting to grant "AUTORITE NT\SERVICE LOCAL" full permissions to "C:\ProgramData\pm2\service". Successfully set permissions on "C:\ProgramData\pm2\service". Updating "pm2.exe" service to run as "NT AUTHORITY\LocalService" Found "pm2.exe" service: State: Stopped Status: OK Started: False Start Mode: Auto Service Type: Own Process Start Name: NT AUTHORITY\LocalService Changing service user account.. Starting service.. State is now: Stopped State is now: Stopped State is now: Stopped State is now: Stopped State is now: Stopped State is now: Stopped State is now: Stopped State is now: Stopped (nevere ending)

I can give you pm2-wrapper-log:

2021-09-29 14:57:12 - Failed to log event in Windows Event Log: Starting C:\Program Files\nodejs\node.exe --harmony C:\ProgramData\npm\npm\node_modules\node-windows\lib\wrapper.js --file C:\ProgramData\pm2\service\index.js --scriptoptions= --log "PM2 wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst true; Reason: Message:La source est introuvable mais certains ou l'ensemble des journaux des événements n'ont pas pu faire l'objet d'une recherche. Journaux inaccessibles : Security. Stacktrace: à System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly) à System.Diagnostics.EventLog.SourceExists(String source, String machineName) à System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName) à System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) à System.Diagnostics.EventLog.WriteEntry(String message) à winsw.WrapperService.LogEvent(String message) 2021-09-29 14:57:12 - Starting C:\Program Files\nodejs\node.exe --harmony C:\ProgramData\npm\npm\node_modules\node-windows\lib\wrapper.js --file C:\ProgramData\pm2\service\index.js --scriptoptions= --log "PM2 wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst true 2021-09-29 15:01:02 - Failed to log event in Windows Event Log: Starting C:\Program Files\nodejs\node.exe --harmony C:\ProgramData\npm\npm\node_modules\node-windows\lib\wrapper.js --file C:\ProgramData\pm2\service\index.js --scriptoptions= --log "PM2 wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst true; Reason: Message:La source est introuvable mais certains ou l'ensemble des journaux des événements n'ont pas pu faire l'objet d'une recherche. Journaux inaccessibles : Security. Stacktrace: à System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly) à System.Diagnostics.EventLog.SourceExists(String source, String machineName) à System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName) à System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) à System.Diagnostics.EventLog.WriteEntry(String message) à winsw.WrapperService.LogEvent(String message) 2021-09-29 15:01:02 - Starting C:\Program Files\nodejs\node.exe --harmony C:\ProgramData\npm\npm\node_modules\node-windows\lib\wrapper.js --file C:\ProgramData\pm2\service\index.js --scriptoptions= --log "PM2 wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst true

the message is in french, and can be translate by: : The source could not be found, but some or all of the event logs could not be searched. Logs inaccessible

I finish with @jessety/pm2-logrotate wich doesn't start... Just my API with "pm2 ls".

I work in remote VMWare machine with Windows 7 for dev and test, and it will have to work on a Windows Server 2008R2.

With my Windows 10, at home, all is right, pm2, pm2-installer et @jessety/pm2-logrotate.

Thanks for any help.

And sorry for my english...

ChrisDu17 commented 2 years ago

Hello from France , just to say in Windows 7, I have the same issue with the last pm2-installer 3.2.5 update.

Node version is 12.22.6 (due to Windows server 2008R2 limitations)

Output: npm run configure -> OK npm run configure-policy -> OK npm run setup

pm2-installer@3.2.5 setup D:\Users\c.gueriteau\Downloads\pm2-installer node ./src/tools/script-for-os.js

pm2-installer@3.2.5 setup:windows D:\Users\c.gueriteau\Downloads\pm2-installer PowerShell -NoProfile -ExecutionPolicy Bypass src\windows\setup.ps1

=== Setup === === Checking Script Privileges === Script is running as administrator. === Checking Script Privileges Complete === === Checking npm Configuration === Global npm prefix location appears valid: C:\ProgramData\npm\npm Global npm cache location appears valid: C:\ProgramData\npm\npm-cache === Checking npm Configuration Complete === === Install Packages === Running on: 2021-9-29, pm2-installer 3.2.5 with node v12.22.6 and npm 6.14.15 on win32-6.1.7601. Using: pm2@5.1.2 @jessety/pm2-logrotate@2.7.1 node-windows@1.0.0-beta.1 Checking connectivity to the npm registry.. Successfully connected to registry.npmjs.org. Installing packages.. C:\ProgramData\npm\npm\pm2 -> C:\ProgramData\npm\npm\node_modules\pm2\bin\pm2 C:\ProgramData\npm\npm\pm2-dev -> C:\ProgramData\npm\npm\node_modules\pm2\bin\pm2-dev C:\ProgramData\npm\npm\pm2-docker -> C:\ProgramData\npm\npm\node_modules\pm2\bin\pm2-docker C:\ProgramData\npm\npm\pm2-runtime -> C:\ProgramData\npm\npm\node_modules\pm2\bin\pm2-runtime

* pm2@5.1.2
  updated 1 package in 25.376s

* @jessety/pm2-logrotate@2.7.1
  updated 1 package in 33.17s

* node-windows@1.0.0-beta.1
  updated 1 package in 1.097s
  Installing packages took 65 seconds.
  Linking node-windows..
  D:\Users\c.gueriteau\Downloads\pm2-installer\node_modules\node-windows -> C:\ProgramData\npm\npm\node_modules\node-windows
  Unblocking script at C:\ProgramData\npm\npm\pm2.ps1..
  === Install Packages Complete: took 69 seconds ===
  === Creating Service ===
  Determining pm2 installation directory..
  Determining Local Service user name ("S-1-5-19")..
  Configuration:
  PM2_HOME:              C:\ProgramData\pm2\home
  PM2_SERVICE_DIRECTORY: C:\ProgramData\pm2\service
  PM2_INSTALL_DIRECTORY: C:\ProgramData\npm\npm\node_modules\pm2
  Service User:          AUTORITE NT\SERVICE LOCAL

Attempting to create "C:\ProgramData\pm2\home" Directory "C:\ProgramData\pm2\home" already exists, no need to create it. Attempting to create "C:\ProgramData\pm2\service" Directory "C:\ProgramData\pm2\service" already exists, no need to create it. Copying service files from ".\src\windows\service" to "C:\ProgramData\pm2\service".. Copying files complete. Attempting to grant "AUTORITE NT\SERVICE LOCAL" full permissions to "C:\ProgramData\pm2\home". Successfully set permissions on "C:\ProgramData\pm2\home". Attempting to grant "AUTORITE NT\SERVICE LOCAL" full permissions to "C:\ProgramData\pm2\service". Successfully set permissions on "C:\ProgramData\pm2\service". Running Node service install script.. service-management\install Installing Installing service "PM2" at "C:\ProgramData\pm2\service" Already installed. service-management\install Complete Attempting to grant "AUTORITE NT\SERVICE LOCAL" full permissions to "C:\ProgramData\pm2\home". Successfully set permissions on "C:\ProgramData\pm2\home". Attempting to grant "AUTORITE NT\SERVICE LOCAL" full permissions to "C:\ProgramData\pm2\service". Successfully set permissions on "C:\ProgramData\pm2\service". Updating "pm2.exe" service to run as "NT AUTHORITY\LocalService" Found "pm2.exe" service: State: Stopped Status: OK Started: False Start Mode: Auto Service Type: Own Process Start Name: NT AUTHORITY\LocalService Changing service user account.. Starting service.. State is now: Stopped State is now: Stopped State is now: Stopped State is now: Stopped State is now: Stopped State is now: Stopped State is now: Stopped State is now: Stopped (nevere ending)

I can give you pm2-wrapper-log:

2021-09-29 14:57:12 - Failed to log event in Windows Event Log: Starting C:\Program Files\nodejs\node.exe --harmony C:\ProgramData\npm\npm\node_modules\node-windows\lib\wrapper.js --file C:\ProgramData\pm2\service\index.js --scriptoptions= --log "PM2 wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst true; Reason: Message:La source est introuvable mais certains ou l'ensemble des journaux des événements n'ont pas pu faire l'objet d'une recherche. Journaux inaccessibles : Security. Stacktrace: à System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly) à System.Diagnostics.EventLog.SourceExists(String source, String machineName) à System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName) à System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) à System.Diagnostics.EventLog.WriteEntry(String message) à winsw.WrapperService.LogEvent(String message) 2021-09-29 14:57:12 - Starting C:\Program Files\nodejs\node.exe --harmony C:\ProgramData\npm\npm\node_modules\node-windows\lib\wrapper.js --file C:\ProgramData\pm2\service\index.js --scriptoptions= --log "PM2 wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst true 2021-09-29 15:01:02 - Failed to log event in Windows Event Log: Starting C:\Program Files\nodejs\node.exe --harmony C:\ProgramData\npm\npm\node_modules\node-windows\lib\wrapper.js --file C:\ProgramData\pm2\service\index.js --scriptoptions= --log "PM2 wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst true; Reason: Message:La source est introuvable mais certains ou l'ensemble des journaux des événements n'ont pas pu faire l'objet d'une recherche. Journaux inaccessibles : Security. Stacktrace: à System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly) à System.Diagnostics.EventLog.SourceExists(String source, String machineName) à System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName) à System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) à System.Diagnostics.EventLog.WriteEntry(String message) à winsw.WrapperService.LogEvent(String message) 2021-09-29 15:01:02 - Starting C:\Program Files\nodejs\node.exe --harmony C:\ProgramData\npm\npm\node_modules\node-windows\lib\wrapper.js --file C:\ProgramData\pm2\service\index.js --scriptoptions= --log "PM2 wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst true

the message is in french, and can be translate by: : The source could not be found, but some or all of the event logs could not be searched. Logs inaccessible

I finish with @jessety/pm2-logrotate wich doesn't start... Just my API with "pm2 ls".

I work in remote VMWare machine with Windows 7 for dev and test, and it will have to work on a Windows Server 2008R2.

With my Windows 10, at home, all is right, pm2, pm2-installer et @jessety/pm2-logrotate.

Thanks for any help.

And sorry for my english...

I have found my error.

The max NodeJS version for Windows Server 2008R2 is 10.24.1. And all of this won't run correctly if the Windows Powershell version is 2.0. So, no problem anymore with Powershell 5.1 and NodeJS 10.24.1.

Sorry, but if it can help someone, take it.

zuohaot commented 2 years ago

you can check C:\ProgramData\pm2\service\daemon\pm2.wrapper.log if you meet security, state error message, maybe you should change identity of PM2 service to local user

hi @jackiewu how to change the identity to local user?

Did you fix your problem? I met this endless "State is now: Stopped" issue today, and I notice @jackiewu's response about "local user". Then I realised that it might be related to the Microsoft Account signed in, so I signed out my Microsoft account and did "npm run remove" and "npm run deconfigure" to make sure anything installed is removed. After that, i followed the instruction again. It worked. Not sure if you had the same problem as I did, but hope it helps.

ChrisDu17 commented 2 years ago

you can check C:\ProgramData\pm2\service\daemon\pm2.wrapper.log if you meet security, state error message, maybe you should change identity of PM2 service to local user

hi @jackiewu how to change the identity to local user?

Did you fix your problem? I met this endless "State is now: Stopped" issue today, and I notice @jackiewu's response about "local user". Then I realised that it might be related to the Microsoft Account signed in, so I signed out my Microsoft account and did "npm run remove" and "npm run deconfigure" to make sure anything installed is removed. After that, i followed the instruction again. It worked. Not sure if you had the same problem as I did, but hope it helps.

Hi zuohaot,

I don't change the identity of PM2 service, but I change in the folder. My folder is in a different hard drive, so I add AUTORITE NT\SERVICE LOCAL to the folder grant. And everything works now. Hope this help you.

Alynva commented 2 years ago

Same problem here.

iii-james commented 2 years ago

I am having the same issue. Here is my pm2.wrapper.log. Which folder do I check to make sure the rights are ok?

2021-12-23 07:08:30 - Failed to log event in Windows Event Log: Starting C:\Program Files\nodejs\node.exe  --harmony C:\ProgramData\npm\npm\node_modules\node-windows\lib\wrapper.js --file C:\ProgramData\pm2\service\index.js --scriptoptions= --log "PM2 wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst true; Reason: 
Message:The source was not found, but some or all event logs could not be searched.  To create the source, you need permission to read all event logs to make sure that the new source name is unique.  Inaccessible logs: Security, State.
Stacktrace:   at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly, Boolean wantToCreate)
   at System.Diagnostics.EventLog.SourceExists(String source, String machineName, Boolean wantToCreate)
   at System.Diagnostics.EventLogInternal.VerifyAndCreateSource(String sourceName, String currentMachineName)
   at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
   at System.Diagnostics.EventLog.WriteEntry(String message)
   at winsw.WrapperService.LogEvent(String message)
2021-12-23 07:08:30 - Starting C:\Program Files\nodejs\node.exe  --harmony C:\ProgramData\npm\npm\node_modules\node-windows\lib\wrapper.js --file C:\ProgramData\pm2\service\index.js --scriptoptions= --log "PM2 wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst true
ChrisDu17 commented 2 years ago

I am having the same issue. Here is my pm2.wrapper.log. Which folder do I check to make sure the rights are ok?

2021-12-23 07:08:30 - Failed to log event in Windows Event Log: Starting C:\Program Files\nodejs\node.exe  --harmony C:\ProgramData\npm\npm\node_modules\node-windows\lib\wrapper.js --file C:\ProgramData\pm2\service\index.js --scriptoptions= --log "PM2 wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst true; Reason: 
Message:The source was not found, but some or all event logs could not be searched.  To create the source, you need permission to read all event logs to make sure that the new source name is unique.  Inaccessible logs: Security, State.
Stacktrace:   at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly, Boolean wantToCreate)
   at System.Diagnostics.EventLog.SourceExists(String source, String machineName, Boolean wantToCreate)
   at System.Diagnostics.EventLogInternal.VerifyAndCreateSource(String sourceName, String currentMachineName)
   at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
   at System.Diagnostics.EventLog.WriteEntry(String message)
   at winsw.WrapperService.LogEvent(String message)
2021-12-23 07:08:30 - Starting C:\Program Files\nodejs\node.exe  --harmony C:\ProgramData\npm\npm\node_modules\node-windows\lib\wrapper.js --file C:\ProgramData\pm2\service\index.js --scriptoptions= --log "PM2 wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst true

Hi iii-james,

I verify the folder where my API is. My API is in a different hard drive, so I verify the API folder and change the rights to be sure that AUTORITE NT\SERVICE LOCAL have the correct rights. My API folder name is "USV_API", and the "SERVICE LOCAL" have all rights to this folder (Total control). Right click on the folder were is your process, then Security, add "SERVICE LOCAL" if it is not in the list, and then change the rights to have "total control".

Then try to run again the pm2-installer and I hope it will works, it works for me like that.

iii-james commented 2 years ago

I ended up changing the service to use the local user account to make it work. Is there a downside to this?

iii-james commented 2 years ago

@ChrisDu17 sorry I commented before seeing your suggestion. I will put the service property back like it was and try your approach. Thanks

ChrisDu17 commented 2 years ago

@ChrisDu17 sorry I commented before seeing your suggestion. I will put the service property back like it was and try your approach. Thanks

Tell us if it works...

iii-james commented 2 years ago

I could not get it to work without changing the service to use the local user account. I am probably doing something wrong. At the end of the install process when it tries to start the service ,and fails, it does not know what api I am going to run. So I don't understand what the folder rights of my api have to do with it. Maybe the rights to the folder containing the pm2.exe?

image

ChrisDu17 commented 2 years ago

I could not get it to work without changing the service to use the local user account. I am probably doing something wrong. At the end of the install process when it tries to start the service ,and fails, it does not know what api I am going to run. So I don't understand what the folder rights of my api have to do with it. Maybe the rights to the folder containing the pm2.exe?

image

Hi,

I use nvm and node, and booth are installed in C: (c:\nvm and C:\nodejs), not in C:\Program Files....

For pm2 service, it is the same as you (C:\Program Data\pm2\service\daemon\pm2.exe). And if I want to run my API with PM2, I need to change the rights for the folder API. I'm with Windows Server 2008R2 (old server), so I cannot run nodejs more than 10.24.1 All is running well, from 24 days...

Be sure that nodejs is accessible for any user.

And if you find a way to run it Local User account, don't change anything. And if you can test another way, you can do it.

m-mohamedin commented 2 years ago

Hi,

In my setup, it was nvm problem. NVM is installed as the current user and I fixed the problem by added LOCAL SERVICE user to the node directory and the link in program files.

andriyetch commented 2 years ago

Also having this same issue on Windows Server 2019, the service never starts...

C:\ProgramData\pm2-installer-main>npm run setup

pm2-installer@3.4.0 setup node ./src/tools/script-for-os.js

pm2-installer@3.4.0 setup:windows PowerShell -NoProfile -ExecutionPolicy Bypass src\windows\setup.ps1

=== Setup === === Checking Script Privileges === Script is running as administrator. === Checking Script Privileges Complete === === Checking npm Configuration === Global npm prefix location appears valid: C:\ProgramData\npm\npm Global npm cache location appears valid: C:\ProgramData\npm\npm-cache === Checking npm Configuration Complete === === Install Packages === Running on: 6/9/2022, pm2-installer 3.4.0 with node v16.15.1 and npm 8.11.0 on win32-10.0.17763. Using: pm2@5.2.0 @jessety/pm2-logrotate@2.7.1 node-windows@1.0.0-beta.6 Checking connectivity to the npm registry.. Successfully connected to registry.npmjs.org. Installing packages..

added 182 packages in 9s

added 211 packages in 8s

added 5 packages in 1s Installing packages took 20 seconds. Linking node-windows..

added 220 packages in 6s Unblocking script at C:\ProgramData\npm\npm\pm2.ps1.. === Install Packages Complete: took 29 seconds === === Creating Service === Determining pm2 installation directory.. Determining Local Service user name ("S-1-5-19").. Configuration: PM2_HOME: C:\ProgramData\pm2\home PM2_SERVICE_DIRECTORY: C:\ProgramData\pm2\service PM2_INSTALL_DIRECTORY: C:\ProgramData\npm\npm\node_modules\pm2 Service User: NT AUTHORITY\LOCAL SERVICE

Attempting to create "C:\ProgramData\pm2\home" Directory "C:\ProgramData\pm2\home" does not exist, creating it.. Attempting to create "C:\ProgramData\pm2\service" Directory "C:\ProgramData\pm2\service" does not exist, creating it.. Copying service files from ".\src\windows\service\" to "C:\ProgramData\pm2\service".. Copying files complete. Attempting to grant "NT AUTHORITY\LOCAL SERVICE" full permissions to "C:\ProgramData\pm2\home". Successfully set permissions on "C:\ProgramData\pm2\home". Attempting to grant "NT AUTHORITY\LOCAL SERVICE" full permissions to "C:\ProgramData\pm2\service". Successfully set permissions on "C:\ProgramData\pm2\service". Running Node service install script.. service-management\install Installing Installing service "PM2" at "C:\ProgramData\pm2\service" service-management\install Complete Attempting to grant "NT AUTHORITY\LOCAL SERVICE" full permissions to "C:\ProgramData\pm2\home". Successfully set permissions on "C:\ProgramData\pm2\home". Attempting to grant "NT AUTHORITY\LOCAL SERVICE" full permissions to "C:\ProgramData\pm2\service". Successfully set permissions on "C:\ProgramData\pm2\service". Updating "pm2.exe" service to run as "NT AUTHORITY\LocalService" Found "pm2.exe" service: State: Stopped Status: OK Started: False Start Mode: Auto Service Type: Own Process Start Name: LocalSystem Changing service user account.. Starting service.. State is now: Start Pending State is now: Stopped State is now: Stopped State is now: Stopped State is now: Stopped State is now: Stopped

TomMiller-mas commented 2 years ago

@andriyetch Having the same problem too with pretty much the same setup.

The first time I installed it, the service installed and worked. I could see the module in the status dashboard.
I uninstalled everything realizing I made a mistake trying to get my API running.

I uninstalled everything and now having this problem setting up a second time.

The Local Service security wasn't set up on the ProgramData/pm2 or ProgramData/npm. I did that. I also ran pm2 manually and the default directory setup in the environment table wasn't getting picked up. I rebooted. pm2 now ran properly. I retried "npm run setup", but I am still getting the same error.

I tried starting the pm2 service, I get this error: Error 1067: 'The process terminated unexpectedly' image

One suggestion is to fix the log on info, and it was wrong. It had local service in the user name and a password vs choosing the local service account option.

Something is broken in the wrapper function that calls the pm2 javascript library that actually runs pm2. At this point, I will likely move on to another solution. This has promise, but it seems prone to not working. There isn't any documentation for troubleshooting. Anyone have any ideas?