jon-hall / pm2-windows-service

Easily install (and uninstall) PM2 as a Windows service
231 stars 66 forks source link

Error Trying To Install As Windows Service #14

Closed crjackso closed 2 years ago

crjackso commented 8 years ago

I'm trying to use this tool (version 0.2.0) to host a simple Express app as a Windows service. When running the following command...

pm2-service-install MySimpleExpressApp

... with the following environment parameters:

PM2_SERVICE_PM2_DIR = C:\USERS\jdoe\APPDATA\ROAMING\NPM\node_modules\pm2\index.js PM2_HOME = C:\Users\jdoe\.pm2 PM2_SERVICE_SCRIPTS = C:\apps\simpleApp\process.json

...I end up with the following error in the logs

Error: spawn node ENOENT at exports._errnoException (util.js:874:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32) at onErrorNT (internal/child_process.js:344:16) at doNTCallback2 (node.js:441:9) at process._tickDomainCallback (node.js:396:17)

I'm sure I'm missing something obvious here, but nothing is jumping out at me. I could use another pair of eyes.

jon-hall commented 8 years ago

Hi, sorry you're getting this issue - first question would be: did you use the built-in prompt to set up the environment? If not, are the environment variables set at machine level rather than user level to make sure they are visible to the service user?

From the message in the error it looks like the service might be failing to start node - this could mean that the directory node is installed to is inaccessible to the service user (this wouldn't be the case if it's just a standard node install in program files though), or that the machine-level PATH variable doesn't have the directory with node in on it, if not then update PATH to include the node directory, reboot, and retry.

If the machine-level environment variables (including PATH) all appear to be setup correctly and node is in the usual location, check to see if there's any additional info in the C:\Users\jdoe\.pm2\pm2.log file, or in any of the service logs and post anything you find here; and I'll try and reproduce the issue locally as soon as I get time if the above suggestions still don't sort it out for you.

crjackso commented 8 years ago

Hi Jon, thanks so much for the fast response. I can confirm that the environment variables are set at the system level, not the user. Also, I can confirm that node is part of my path. Running node -v without the full path of node works fine and returns v4.2.3.

Your response triggered something for me though. I realized the service was running as Local System, instead of the jdoe user. Manually changing that in the Services window worked. Is there a way to install and run as a particular user from the start?

jon-hall commented 8 years ago

The issue of running the service as a different user is one that was originally raised a while ago (#3) - at the time I was unable to come up with a reliable solution, but the user who raised the issue very kindly put together a powershell script that installs the service to run under the LOCAL SERVICE account (https://github.com/jon-hall/pm2-windows-service/issues/3#issuecomment-171028296).

It's been on my TODO list for a while to comb through the script and figure out how best to integrate it into this package, while allowing it to be configured for any user on the target machine. This particular problem has come up a couple of times recently though so I'll make sure I set aside some time this weekend to take a crack at adding this feature to the package - it would then hopefully be a case of simply specifying/selecting the service user during the pm2-service-install command.

I'll update all the affected issues as soon as I have some progress on it.

jon-hall commented 8 years ago

Update on specifying service user - https://github.com/jon-hall/pm2-windows-service/issues/3#issuecomment-247784482.

jon-hall commented 2 years ago

Closing this as the package is now deprecated, users should migrate to pm2-installer.