Code Monkey home page Code Monkey logo

pm2-windows-service's Introduction

pm2-windows-service [DEPRECATED]



This package is NO LONGER SUPPORTED OR MAINTAINED



To run pm2 on Windows you should now use pm2-installer instead.



Original docs

Allows easily installing and uninstalling PM2 as a service on Windows machines - inspired by pm2-windows-startup, and largely achieved using node-windows.

npm i pm2-windows-service -g

NOTE: pm2-windows-service currently requires node v4.0.0+, if node v0.12.x support is a requirement for you, please post in this issue.

Install and Uninstall the Service

TIP: Run these from an administrative command prompt to avoid getting hit with a bunch of UAC dialogs

pm2-service-install [-n <service name>] [--unattended]

pm2-service-uninstall

The install command also offers to perform some basic setup for you which helps address some of the caveats detailed below.

Quickstart

After reading the caveats section, use PM2 to start the set of processes that you want the service to restore, and then just do:

pm2 save

The service will then restart that set of processes when the service is next started (by default this will be on system boot).

Configuration

You can control what the PM2 service runs using the PM2_SERVICE_SCRIPTS environment variable, which should be set to a semi-colon separated list of javascript files and/or json config files to run when the service starts (using pm2 start).

If PM2_SERVICE_SCRIPTS is not set, then the default behaviour is to call pm2 resurrect on service startup - when PM2 is running with the list of processes you want launched by the service, use pm2 save to dump the process list, ready for the service to restore it when it next starts.

Caveats

While testing this, a few caveats have arisen which need to be detailed upfront, as they can lead to issues when PM2 is installed as a service:

  • If you don't have the PM2_HOME environment variable set (in such a way that it is available to the service user - the simplest being set it at machine level), you might find PM2 attempting to run in strange directories. To resolve this, make sure you set the environment variable and restart the service - though see the comment just below about the location it points to being accessible for the service user.
  • If you run the service under one user account, and then attempt to interact with PM2 from the command line using a different account, you'll find things don't work as expected if the PM2_HOME environment variable contains any "user context" env vars (%APPDATA%, %USERPROFILE% etc.), or if one of the users cannot access the location of PM2_HOME.
    • To avoid this problem, either set PM2_HOME to an absolute path that all potential users (service and CLI) can write to, or run the service under the same account as you intend to use the CLI from.
  • It also seems PM2 throws an error when you try to use the CLI from a non-administrative command prompt after it has been launched as a service, regardless of which user the service runs under (not tested with a non-admin user, yet).
    • Currently, the workaround for this, unfortunately, is just use an administrative command prompt if you need to access PM2 via command line when it is running as a service.
  • As raised in #24, there appears to be a dependency on having .NET 3.5 installed on the machine on which the service runs (and this holds true even when later versions are installed, you still need 3.5 as well) - this issue is still under investigation but, while that's happening, this is something to bear in mind when setting up the service.
  • Lastly, when launching json config files using PM2_SERVICE_SCRIPTS, problems arise if the apps declared in the config file don't explicitly have a cwd set (it ends up being the home dir of the service user).
    • pm2-windows-service attempts to solve this issue for you by automatically defaulting the cwd property to the directory of the config file when it isn't explicitly set, if this is an issue for you then explicitly setting the cwd for your apps might be what you need to do.

Logs

The service created by node-windows is currently placed in <global npm packages directory>/node_modules/pm2-windows-service/src/daemon/, as such, this is also where you will find the log output from the service, should you need it.

pm2-windows-service's People

Contributors

frg avatar irbrad avatar jon-hall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pm2-windows-service's Issues

Error on starting application in fork mode with HTTP server

Very simple NodeJS HTTP server started in fork mode ended with exception:

1|server | Error: listen EADDRINUSE 0.0.0.0:5674
1|server | at Object.exports._errnoException (util.js:1022:11)
1|server | at exports._exceptionWithHostPort (util.js:1045:20)
1|server | at Server._listen2 (net.js:1262:14)
1|server | at Server._listen2 C:\USERS\USER\APPDATA\ROAMING\NPM\node_modules\pm2\node_modules\async-listener\index.js:51:23)
1|server | at listen (net.js:1298:10)
1|server | at doListening (net.js:1397:7)
1|server | at _combinedTickCallback (internal/process/next_tick.js:77:11)
1|server | at process._tickDomainCallback [as _tickCallback] (internal/process/next_tick.js:122:9)
1|server | at Module.runMain (module.js:607:11)
1|server | at run (bootstrap_node.js:420:7)
1|server | at startup (bootstrap_node.js:139:9)
1|server | at bootstrap_node.js:535:3

PM2 Service starts wrong app

Hi Jon,

Strange issue here, hoping you can help me. I was using a test application, myApp, that I had running in PM2. You helped me get a Pm2 Windows Service up and running with that test application. After that was working, I removed the app myApp by using PM2 Kill, then PM2 delete process.json(the config file I used to set it up). I set up my Production application on this Development server and was able to get it up and running in PM2:
image

Following your advice, I used JSONinstead of JSON5 to get the config file set up:
{
"apps" : [{
"name" : "source",
"script" : "bin\www", // Script to be run
"exec_mode" : "cluster", // Allow your app to be clustered
"instances" : 1, // Optional: Scale your app by 4
"args" : "Node1",
"max_memory_restart" : "100M" // Opt
},{
"name" : "source",
"script" : "bin\www", // Script to be run
"exec_mode" : "cluster", // Allow your app to be clustered
"instances" : 1, // Optional: Scale your app by 4
"args" : "Node2",
"max_memory_restart" : "100M" // Opt
},{
"name" : "source",
"script" : "bin\www", // Script to be run
"exec_mode" : "cluster", // Allow your app to be clustered
"instances" : 1, // Optional: Scale your app by 4
"args" : "Node3",
"max_memory_restart" : "100M" // Opt
},{
"name" : "source",
"script" : "bin\www", // Script to be run
"exec_mode" : "cluster", // Allow your app to be clustered
"instances" : 1, // Optional: Scale your app by 4
"args" : "Node4",
"max_memory_restart" : "100M" // Opt
}
]}

Installed the service:

image

Then I check to see if the service is online using PM2 List:

image

It shows that the service is still running myApp! Any idea what I'm doing wrong? I do see the "In-memory PM2 is out-of-date" message which I can't seem to get rid of even after running pm2 update. I'm unsure whether or not that is related.

Thanks, Clint

Warning about non-existent property & circular dependency

This package appears to successfully install and uninstall PM2 as a Windows Service; however, the install/uninstall commands both trigger about 2 dozen warnings (see screenshot):

(node:7008) Warning: Accessing non-existent property 'pushd' of module exports inside circular dependency

image

Windows Server, 2012 R2
npm: 6.14.8
node: 14.15.0

Custom service name support

Is it possible to specify the service name during the pm2-service-install command execution? I see that install function takes name as a parameter, but don't know how to provide it via command line.

I'd like to have something like this:

pm2-service-install -name "My PM2 service"

If there is no such functionality, I can implement it via minimist and make a PR.

Error: Unable to load PM2 JSON configuration file

Hi Jon,

I'm trying to start PM2 as a service using a file called process.json with the following parameters:

{
"apps" : [{
name : "myapp",
script : 'c:\myApp\server.js', // Script to be run
exec_mode : 'cluster', // Allow your app to be clustered
instances : 1, // Optional: Scale your app by 4
args : "Node1",
max_memory_restart : '100M' // Opt
}]
}

It works fine running PM2 in command line and creates the service just fine but when I try to start the service, I keep getting the above error in the logs. The env vars are all set a machine level. Here is how I set it up:

image

I also tried setting the PM2_SERVICE_SCRIPTS var with process.json in the path, but I get the same error.

Any thoughts?

Thanks, Clint

PM2 broken after complete deletion of this plugin

I tried to work with this plugin that looked pretty good but it didn't work for me.. I uninstalled the service and the the package. But now my regular install of pm2 doesn't work anymore... Seems like pm2 is running in a wrong directory..

I tried to uninstall pm2 and reinstall it again but it didn't work.

Any bit of help very much appreciated

Log on Privileges

This is more of a potential caveat then an issue. I have found an issue when using this module that on restart, while my app is running, I could not access network storage (used to store files for upload/download as opposed to directly on the server). I was getting EPERM: operation not permitted. After pulling my hair out for a while, testing different project folders, etc. I realized that the service runs as "Local System", which by definition only has local privileges. My understanding is that you can assign permissions to the computer account and that would give "Local System" the corresponding permissions on the network storage but I did not have any luck. I had to change the log on to a domain admin (theoretically this could be a domain user with permissions as well) and change under Recovery for First failure to Restart the Service.
Not sure if this is something worth while to post in the caveat section or if there is a better solution than what I've presented.

pm2-windows-service does not start after reboot

Hi,
I have installed pm2-windows-service on my Windows Server 2019 remote server machine. Everything's been working well, except that the service does not start after I reboot the machine if I do not sign in as a user. The service starts right after I sign in as a user. After that, signing out/signing in does not affect the service. I was wondering if anyone has seen problems similar to this and if anyone has a solution for it?

Unable to install pm2 as a service

Node version: 0.12.17
Win version: Windows Server 2012 R2 64-bit

Considering this is a different error that was experienced in this issue #2

I know the minimum requirement is 4.0 for node but wondering if there's something obviously wrong with what I'm doing which is breaking it.

image

Thanks.

Occasional failure to start service with system reboot

I am using this service on about 90 machines with varying version of Windows and sometimes on system reboots, the PM2 service doesn't start.

I have not found any errors logged in either the PM2 logs or Windows Event Viewer that suggests any cause. In fact, I was surprised to find that there is NO entry of success of fail for the PM2 service in the Windows Event Viewer either way.

I'm suspecting some kind of race condition where PM2 needs something to be running that isn't yet, but don't know what that might be.

Any suggestions?

App failing to launch

Hello,

I made a service for testing, and it worked with no issue. I later ran the uninstall service command. Afterwards, I created a service again, but creating the service closed my apps (main + worker). I started them manually and ran pm2 save, which said it saved successfully, but I get this error

[2018-05-03 16:24:42] PM2 log: App name:APPid:0 online
[2018-05-03 16:24:42] PM2 error: Change detected on path pids\APP-0.pid for app APP- restarting

This will go on forever, visual inspection shows the pid file for APP being destroyed and recreated. If I run pm2 stop on this, followed by pm2 start, it will run OK, but restarting the service will not work correctly.

Have you seen this before?

Thanks.

pm2-windows-service installed but not started.

Hello,

I am using pm2-windows-service on several windows 7 servers. Even with the environment variables properly set, after a while the the process just does not start. When I look at services.msc however I can see that the service is installed but not started.

The versions of things that are installed are as follows:
node v4.4.5
npm 2.15.5
pm2 2.0.15
pm2-windows-service 0.2.0

PM2_HOME is set at C:\Users\some_user\AppData\Roaming\npm\etc.pm2

PM2_SERVICE_PM2_DIR is set at C:\Users\some_user\APPDATA\Roaming\NPM\node_modules\pm2\index.js

And here are the log files
pm2.err.log
2016-10-11 12:23:34: Unknown id 0
2016-10-11 12:23:35: Unknown id 0
2016-10-11 12:23:36: Unknown id 0
2016-10-11 12:23:37: Unknown id 0
2016-10-11 12:23:38: Unknown id 0
2016-10-11 12:23:39: Unknown id 0
2016-10-11 12:23:40: Unknown id 0
2016-10-11 12:23:41: Unknown id 0
2016-10-11 12:23:42: Unknown id 0
2016-10-11 12:23:43: Unknown id 0
2016-10-11 12:23:44: Unknown id 0
2016-10-11 12:23:45: Unknown id 0
2016-10-11 12:23:46: Unknown id 0
2016-10-11 12:23:47: Unknown id 0
2016-10-11 12:23:48: Unknown id 0
2016-10-11 12:23:49: Unknown id 0
2016-10-11 12:23:50: Unknown id 0
2016-10-11 12:23:51: Unknown id 0
2016-10-11 12:23:52: Unknown id 0
2016-10-11 12:23:53: Unknown id 0
2016-10-11 12:23:54: Unknown id 0
2016-10-11 12:23:55: Unknown id 0
2016-10-11 12:23:56: Unknown id 0
2016-10-11 12:23:57: Unknown id 0
2016-10-11 12:23:58: Unknown id 0
2016-10-11 12:23:59: Unknown id 0
2016-10-11 12:24:00: Unknown id 0
2016-10-11 12:24:01: Unknown id 0
2016-10-11 12:24:02: Unknown id 0
2016-10-11 12:24:03: Unknown id 0
2016-10-11 12:24:04: Unknown id 0
2016-10-11 12:24:05: Unknown id 0
2016-10-11 12:24:06: Unknown id 0
2016-10-11 12:24:07: Unknown id 0
2016-10-11 12:24:08: Unknown id 0
2016-10-11 12:24:09: Unknown id 0
2016-10-11 12:24:10: Unknown id 0
2016-10-11 12:24:11: Unknown id 0
2016-10-11 12:24:12: Unknown id 0
2016-10-11 12:24:13: Unknown id 0
2016-10-11 12:24:14: Unknown id 0
2016-10-11 12:24:15: Unknown id 0
2016-10-11 12:24:16: Unknown id 0
2016-10-11 12:24:17: Unknown id 0
2016-10-11 12:24:18: Unknown id 0
2016-10-11 12:24:19: Unknown id 0
2016-10-11 12:24:20: Unknown id 0
2016-10-11 12:24:21: Unknown id 0
2016-10-11 12:24:22: Unknown id 0
2016-10-11 12:24:23: Unknown id 0
2016-10-11 12:24:24: Unknown id 0
2016-10-11 12:24:25: Unknown id 0
2016-10-11 12:24:26: Unknown id 0
2016-10-11 12:24:27: Unknown id 0
2016-10-11 12:24:28: Unknown id 0
2016-10-11 12:24:29: Unknown id 0
2016-10-11 12:24:30: Unknown id 0
2016-10-11 12:24:31: Unknown id 0
2016-10-11 12:24:32: Unknown id 0
2016-10-11 12:24:33: Unknown id 0
2016-10-11 12:24:34: Unknown id 0
2016-10-11 12:24:35: Unknown id 0
2016-10-11 12:24:36: Unknown id 0
2016-10-11 12:24:37: Unknown id 0
2016-10-11 12:24:38: Unknown id 0
2016-10-11 12:24:39: Unknown id 0
2016-10-11 12:24:40: Unknown id 0
2016-10-11 12:24:41: Unknown id 0
2016-10-11 12:24:42: Unknown id 0
2016-10-11 12:24:43: Unknown id 0
2016-10-11 12:24:44: Unknown id 0

pm2.out.log
2016-10-11 12:20:51: Launching in no daemon mode
2016-10-11 12:22:46: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:22:46: App name:store-ingestor id:0 online
2016-10-11 12:23:06: Starting execution sequence in -fork mode- for app name:pm2-logrotate id:1
2016-10-11 12:23:06: App name:pm2-logrotate id:1 online
2016-10-11 12:23:12: Stopping app:store-ingestor id:0
2016-10-11 12:23:12: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:12: App name:store-ingestor id:0 online
2016-10-11 12:23:12: App [store-ingestor] with id [0] and pid [0], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:12: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:12: App name:store-ingestor id:0 online
2016-10-11 12:23:13: App [store-ingestor] with id [0] and pid [15652], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:13: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:13: App name:store-ingestor id:0 online
2016-10-11 12:23:14: App [store-ingestor] with id [0] and pid [12792], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:14: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:14: App name:store-ingestor id:0 online
2016-10-11 12:23:15: App [store-ingestor] with id [0] and pid [14596], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:15: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:15: App name:store-ingestor id:0 online
2016-10-11 12:23:16: App [store-ingestor] with id [0] and pid [16176], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:16: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:16: App name:store-ingestor id:0 online
2016-10-11 12:23:16: App [store-ingestor] with id [0] and pid [7024], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:16: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:16: App name:store-ingestor id:0 online
2016-10-11 12:23:17: App [store-ingestor] with id [0] and pid [15636], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:17: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:17: App name:store-ingestor id:0 online
2016-10-11 12:23:18: App [store-ingestor] with id [0] and pid [13680], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:18: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:18: App name:store-ingestor id:0 online
2016-10-11 12:23:19: App [store-ingestor] with id [0] and pid [15640], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:19: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:19: App name:store-ingestor id:0 online
2016-10-11 12:23:19: App [store-ingestor] with id [0] and pid [14748], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:19: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:19: App name:store-ingestor id:0 online
2016-10-11 12:23:20: App [store-ingestor] with id [0] and pid [2608], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:20: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:20: App name:store-ingestor id:0 online
2016-10-11 12:23:21: App [store-ingestor] with id [0] and pid [7692], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:21: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:21: App name:store-ingestor id:0 online
2016-10-11 12:23:22: App [store-ingestor] with id [0] and pid [15212], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:22: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:22: App name:store-ingestor id:0 online
2016-10-11 12:23:23: App [store-ingestor] with id [0] and pid [9928], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:23: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:23: App name:store-ingestor id:0 online
2016-10-11 12:23:23: App [store-ingestor] with id [0] and pid [15152], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:23: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:23:23: App name:store-ingestor id:0 online
2016-10-11 12:23:24: App [store-ingestor] with id [0] and pid [11488], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:24: Script C:\Users\DatalakeSA\Datalake\store-ingestor.js had too many unstable restarts (16). Stopped. "errored"
2016-10-11 12:23:34: Stopping app:store-ingestor id:0
2016-10-11 12:23:44: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:44: App name:store-ingestor id:2 online
2016-10-11 12:23:45: App [store-ingestor] with id [2] and pid [5968], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:45: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:45: App name:store-ingestor id:2 online
2016-10-11 12:23:45: App [store-ingestor] with id [2] and pid [5608], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:45: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:45: App name:store-ingestor id:2 online
2016-10-11 12:23:46: App [store-ingestor] with id [2] and pid [9760], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:46: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:46: App name:store-ingestor id:2 online
2016-10-11 12:23:47: App [store-ingestor] with id [2] and pid [16040], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:47: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:47: App name:store-ingestor id:2 online
2016-10-11 12:23:48: App [store-ingestor] with id [2] and pid [13344], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:48: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:48: App name:store-ingestor id:2 online
2016-10-11 12:23:49: App [store-ingestor] with id [2] and pid [16016], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:49: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:49: App name:store-ingestor id:2 online
2016-10-11 12:23:49: App [store-ingestor] with id [2] and pid [12356], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:49: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:49: App name:store-ingestor id:2 online
2016-10-11 12:23:50: App [store-ingestor] with id [2] and pid [13940], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:50: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:50: App name:store-ingestor id:2 online
2016-10-11 12:23:51: App [store-ingestor] with id [2] and pid [16272], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:51: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:51: App name:store-ingestor id:2 online
2016-10-11 12:23:52: App [store-ingestor] with id [2] and pid [15856], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:52: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:52: App name:store-ingestor id:2 online
2016-10-11 12:23:53: App [store-ingestor] with id [2] and pid [8040], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:53: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:53: App name:store-ingestor id:2 online
2016-10-11 12:23:53: App [store-ingestor] with id [2] and pid [15580], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:53: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:53: App name:store-ingestor id:2 online
2016-10-11 12:23:54: App [store-ingestor] with id [2] and pid [15972], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:54: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:54: App name:store-ingestor id:2 online
2016-10-11 12:23:55: App [store-ingestor] with id [2] and pid [16232], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:55: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:55: App name:store-ingestor id:2 online
2016-10-11 12:23:56: App [store-ingestor] with id [2] and pid [3040], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:56: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:23:56: App name:store-ingestor id:2 online
2016-10-11 12:23:57: App [store-ingestor] with id [2] and pid [14184], exited with code [1] via signal [SIGINT]
2016-10-11 12:23:57: Script C:\Users\DatalakeSA\Datalake\store-ingestor.js had too many unstable restarts (16). Stopped. "errored"
2016-10-11 12:24:13: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:13: App name:store-ingestor id:2 online
2016-10-11 12:24:14: App [store-ingestor] with id [2] and pid [7412], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:14: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:14: App name:store-ingestor id:2 online
2016-10-11 12:24:15: App [store-ingestor] with id [2] and pid [16056], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:15: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:15: App name:store-ingestor id:2 online
2016-10-11 12:24:16: App [store-ingestor] with id [2] and pid [14460], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:16: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:16: App name:store-ingestor id:2 online
2016-10-11 12:24:16: App [store-ingestor] with id [2] and pid [13916], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:16: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:16: App name:store-ingestor id:2 online
2016-10-11 12:24:17: App [store-ingestor] with id [2] and pid [15904], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:17: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:17: App name:store-ingestor id:2 online
2016-10-11 12:24:18: App [store-ingestor] with id [2] and pid [13732], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:18: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:18: App name:store-ingestor id:2 online
2016-10-11 12:24:19: App [store-ingestor] with id [2] and pid [13176], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:19: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:19: App name:store-ingestor id:2 online
2016-10-11 12:24:20: App [store-ingestor] with id [2] and pid [8776], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:20: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:20: App name:store-ingestor id:2 online
2016-10-11 12:24:20: App [store-ingestor] with id [2] and pid [15928], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:20: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:20: App name:store-ingestor id:2 online
2016-10-11 12:24:21: App [store-ingestor] with id [2] and pid [14408], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:21: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:21: App name:store-ingestor id:2 online
2016-10-11 12:24:22: App [store-ingestor] with id [2] and pid [15708], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:22: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:22: App name:store-ingestor id:2 online
2016-10-11 12:24:23: App [store-ingestor] with id [2] and pid [12452], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:23: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:23: App name:store-ingestor id:2 online
2016-10-11 12:24:24: App [store-ingestor] with id [2] and pid [12720], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:24: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:24: App name:store-ingestor id:2 online
2016-10-11 12:24:24: App [store-ingestor] with id [2] and pid [9096], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:24: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:24: App name:store-ingestor id:2 online
2016-10-11 12:24:25: App [store-ingestor] with id [2] and pid [16324], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:25: Starting execution sequence in -fork mode- for app name:store-ingestor id:2
2016-10-11 12:24:25: App name:store-ingestor id:2 online
2016-10-11 12:24:26: App [store-ingestor] with id [2] and pid [10692], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:26: Script C:\Users\DatalakeSA\Datalake\store-ingestor.js had too many unstable restarts (16). Stopped. "errored"
2016-10-11 12:24:44: Stopping app:pm2-logrotate id:1
2016-10-11 12:24:44: Process with pid 10684 still not killed, retrying...
2016-10-11 12:24:44: App [pm2-logrotate] with id [1] and pid [10684], exited with code [1] via signal [SIGINT]
2016-10-11 12:24:44: [HandleExit] PM2 is being killed, stopping restart procedure...
2016-10-11 12:24:44: Stopping app:store-ingestor id:2
2016-10-11 12:24:44: ===============================================================================
2016-10-11 12:24:44: --- Stopping PM2 --------------------------------------------------------------
2016-10-11 12:24:44: Time : Tue Oct 11 2016 12:24:44 GMT-0500 (Central Daylight Time)
2016-10-11 12:24:44: ===============================================================================
2016-10-11 12:24:44: RPC closed
2016-10-11 12:24:44: PUB closed
2016-10-11 12:24:44: PM2 successfully stopped
2016-10-11 12:24:46: Launching in no daemon mode
2016-10-11 12:24:46: Starting execution sequence in -fork mode- for app name:store-ingestor id:0
2016-10-11 12:24:46: App name:store-ingestor id:0 online
2016-10-11 12:27:36: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:36: App name:pm2 id:1 online
2016-10-11 12:27:38: App [pm2] with id [1] and pid [16184], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:38: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:38: App name:pm2 id:1 online
2016-10-11 12:27:38: App [pm2] with id [1] and pid [14956], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:38: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:38: App name:pm2 id:1 online
2016-10-11 12:27:39: App [pm2] with id [1] and pid [12356], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:39: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:39: App name:pm2 id:1 online
2016-10-11 12:27:40: App [pm2] with id [1] and pid [14468], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:40: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:40: App name:pm2 id:1 online
2016-10-11 12:27:41: App [pm2] with id [1] and pid [14404], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:41: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:41: App name:pm2 id:1 online
2016-10-11 12:27:41: App [pm2] with id [1] and pid [14572], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:41: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:41: App name:pm2 id:1 online
2016-10-11 12:27:42: App [pm2] with id [1] and pid [12784], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:42: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:42: App name:pm2 id:1 online
2016-10-11 12:27:43: App [pm2] with id [1] and pid [14844], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:43: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:43: App name:pm2 id:1 online
2016-10-11 12:27:44: App [pm2] with id [1] and pid [15728], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:44: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:44: App name:pm2 id:1 online
2016-10-11 12:27:45: App [pm2] with id [1] and pid [5192], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:45: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:45: App name:pm2 id:1 online
2016-10-11 12:27:45: App [pm2] with id [1] and pid [11488], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:45: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:45: App name:pm2 id:1 online
2016-10-11 12:27:46: App [pm2] with id [1] and pid [16016], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:46: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:46: App name:pm2 id:1 online
2016-10-11 12:27:47: App [pm2] with id [1] and pid [16288], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:47: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:47: App name:pm2 id:1 online
2016-10-11 12:27:48: App [pm2] with id [1] and pid [16296], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:48: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:48: App name:pm2 id:1 online
2016-10-11 12:27:49: App [pm2] with id [1] and pid [1380], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:49: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:49: App name:pm2 id:1 online
2016-10-11 12:27:49: App [pm2] with id [1] and pid [16152], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:49: Starting execution sequence in -fork mode- for app name:pm2 id:1
2016-10-11 12:27:49: App name:pm2 id:1 online
2016-10-11 12:27:50: App [pm2] with id [1] and pid [15652], exited with code [1] via signal [SIGINT]
2016-10-11 12:27:50: Script C:\Users\DatalakeSA\AppData\Roaming\npm\etc.pm2\node_modules\pm2\bin\pm2 had too many unstable restarts (16). Stopped. "errored"

pm2.wrapper.log
2016-10-12 03:22:33 - Stopping pm2.exe
2016-10-12 03:22:33 - ProcessKill 15908
2016-10-12 03:22:33 - Finished pm2.exe

In the Caveats section you have mentioned not to use any user variable in setting PM2_HOME but since that is what the service recommends/finds during pm2-service-install, I have been doing so. Could this be a reason why the service seems to mysteriously fail to start for me? If I were to set PM2_HOME to a different directory where should this be set to achieve persistence?

I am using the pm2-windows-service in a production environment with many servers and seeing them go offline and having to reinstall the service over and over is getting frustrating.
Any help would be much much appreciated.

Thank you again!
krishna

Installing without prompts?

I'm trying to use pm2-windows-service to install multiple services (in our case we want them to be discrete rather than pm2 centrally running/managing them all together) as part of a deployment script.

At the moment though, I'm not sure how I avoid the on-screen prompts during the installation process? Is there a way I can provide the parameters up-front/setup environment variables so we don't need respond via the command line questions?

Running as a less-privileged user

Since LocalSystem is effectively root on Windows, it'd be better to run the pm2 service as a less-privileged account, such as LocalService or NetworkService.

I tried just changing the the Log On user account to LocalService, but this didn't work due to the fact that the PM2 daemon sits in my user's AppData\Roaming folder, so starting the service gets an "Access Denied" error when attempting to run as LocalService.

Is it possible to install the service (and PM2, I guess) at a more accessible location to support this?

Auto-save on shutdown doesn't work

Because of the way winsw shuts down the service (in turn, due to how node-windows sets up the winsw config), the service.js file don't receive any of the exit signals/events that it was attempting to hook into, and so it never ends up dumping the process list.

It looks like https://github.com/kohsuke/winsw#stopargumentstopexecutable can be leveraged to be able to make this work, but that would require either customising the service config after node-windows creates it, or forking/PR-ing node-windows to support stopargument/stopexecutable.

As a peripherally related note, coreybutler/node-windows#47, could also be addressed at the same time utilising https://github.com/kohsuke/winsw#net-runtime-40.

Error Trying To Install As Windows Service

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.

pm2-windows-services installs but fails to start

Hello,

I am having trouble making pm2-windows-service persist mainly on windows 7 machines. After installation, when I look at services.msc I can see that it is installed but not 'started'. It seems rather inconsistent. In some computers, installing the service a second time, seems to fix the issue, but in others no matter what I do, the service does not get started on its own. If I start it manually from services.msc and start my application and save it, later on I log back in only to find that pm2-windows-service has mysteriously failed to start. It is there, it is installed, but not started.

How could we fix this issue?
Any help would be much appreciated

Krishna

Script args not passed with service start

I launch an app in pm2 with pm2 start index.js -- --some-argument. When I type pm2 show index it lists script args โ”‚ --some-argument. I pm2 save this, and when I resurrect, it correctly passes those args.

But when I install the service, the --some-argument does not get passed to index.js (and pm2 show index shows "N/A" for script args). Is there any way to ensure these args are passed to app when the service starts?

task scheduling to automate send email and start the pm2 services using powershell

I have created a website named abccompany.com and used a node js with pm2 services. now I want to make a task scheduled like that whenever my website goes down or services go offline it checks for pm2 status either it is online or offline in every x seconds or minutes and automatically sends an email to admin and automatically starts the services without admin interference so that there should not be any fault tolerance when anybody reached or viewed my website. So how to do all this in using Power Shell and task scheduler.

suppose I want to check whether my pm2 status is online or offline by typing pm2 status in command prompt as follows:

image

now if instead of online if offline is showing then it should run PowerShell script in which it will send email to an admin and automatic start the pm2 services using the command "pm2 resurrect".

And I have PowerShell code of sending email file too but didn't get where and how to use and start it. You can find it below as :

Code:
$secpasswd = ConvertTo-SecureString "your password" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)

#Send-MailMessage -Attachments "E:\Email Code.ps1" -From 'abc <[email protected]>' -To 'Dark Horse <[email protected]>' -Cc 'Black Widow <[email protected]>' -Bcc 'Iron Man <[email protected]>' -Subject "Test Email from Powershell" -Credential $cred -SmtpServer smtp.office365.com -Port 587 -UseSsl

$Username = "your username"
$Password = "your password"

$path = @(
"C:\Users\Admin\Desktop\file1.txt"
"C:\Users\Admin\Desktop\file2.txt"
)

function Send-ToEmail([string]$email, [array]$attachmentpath)
{
try
{
$message = new-object Net.Mail.MailMessage;
$message.From = "[email protected]";
$message.To.Add($email);
$message.Subject = "Email from Powershell";
$message.IsBodyHtml = $true;
#$message.Body = "<h1>Please find the Attachment</h1>";

`foreach ($file in $attachmentpath)`

{
$attachment = New-Object Net.Mail.Attachment($file);
$message.Attachments.Add($attachment);
}

$smtp = new-object Net.Mail.SmtpClient("smtp.office365.com", "587");
$smtp.EnableSSL = $true;
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.send($message);
Write-Host "Mail Sent" ;
$attachment.Dispose();
}

catch
{
Write-Host "Error occured"
}
}
Send-ToEmail -email "toemail address" -attachmentpath $path;

How do I launch scripts with custom env variables ?

Here is how I'd do it with only pm2:

# Inject what is declared in env_production
$ pm2 start process.json --env production

i'm looking for a way to tell the service to start pm2 with --env production. How can I do this ?

Dependency on .NET 3.5, gives false positive result of service install

Hi,

It appears as though there's a hard dependency on .net 3.5, which throws a windows error if .net 3.5 isn't installed.

When trying to install the windows service via command prompt (admin console) the console output says it has been successfully installed but windows throws an error because .NET 3.5 isn't installed.
I would have thought there would be some sort of backwards compatibility with .NET 4.5.

I'm not sure if you'd want to do anything with this bug or update the documentation to state the dependencies. This may be a problem more so on corporate servers where dependencies need to be clearly defined and approved prior to installing software.

Anyway installed .NET 3.5 and the windows service has been working great so far. Thanks!

My setup:
Windows 2012 R2 64bit
.NET 4.5 Installed
Node.js v6.9.4

image

Error: Unable to load PM2 JSON configuration file

env:
PM2_HOME=c:\apps\pm
PM2_SERVICE_PM2_DIR=C:\nodejs-v6\node_modules\pm2\index.js
PM2_SERVICE_SCRIPTS=c:/apps/pm/test-webservice-run.json
SET_PM2_HOME=true
SET_PM2_SERVICE_PM2_DIR=true
SET_PM2_SERVICE_SCRIPTS=true

Error: Unable to load PM2 JSON configuration file (c:\apps\pm\test-webservice-run.json) at process_start_script (C:\nodejs-v6\node_modules\pm2-windows-service\src\service.js:62:19) at Array.forEach (native) at C:\nodejs-v6\node_modules\pm2-windows-service\src\service.js:45:33 at C:\nodejs-v6\node_modules\pm2\lib\API.js:136:14 at C:\nodejs-v6\node_modules\pm2\lib\Client.js:86:18 at Timeout._onTimeout (C:\nodejs-v6\node_modules\pm2\lib\Client.js:309:19) at ontimeout (timers.js:365:14) at tryOnTimeout (timers.js:237:5) at Timer.listOnTimeout (timers.js:207:5) C:\nodejs-v6\node_modules\pm2-windows-service\src\service.js:62 throw new Error('Unable to load PM2 JSON configuration file (' + start_script + ')');

Tried with / and double \ as path sep. but same error

The file is present in c:\apps\pm
Content:

{
  apps : [{
    name   : "test-webservice",
    script : "./index.js",
    watch  : true,
    cwd    : "c:/apps/pm2-test-services"
  }]
}

resurrect not being done after server reboot

Hello, here is the sequence:

  1. npm i pm2 -g
  2. npm i pm2-windows-service -g
  3. manually create PM2_HOME pointing to c:\users\admin\.pm2
  4. call pm2-service-install answer No to environment setup
  5. launch node services, call pm2 save
  6. reboot server - pm2 service is running, no nodejs services are up
  7. calling pm2 ls gives an empty table
  8. calling pm2 resurrect manually successfully restores the nodejs processes.

What I'm doing wrong?

PM2 v.2.0.19
Nodejs 6.9.1 32bit
pm2-windows-service - latest

App had too many unstable restarts

I ran the install (pm2-service-install) and set all the variables.
I made sure PM2_Home is a absolute path.
My ecosystem.config.js has the following content:
module.exports = { apps : [{ name : "TelecomProvider", script : "MyPath\\app.js", watch : false instances : 4, exec_mode : "cluster" }] }

However when starting the service I get the error that it had to many unstable restarts.
Here is a snippet from the logfile

2016-11-25 13:57:52: Launching in no daemon mode
2016-11-25 13:58:00: Starting execution sequence in -fork mode- for app name:TelecomProvider id:0
2016-11-25 13:58:00: App name:TelecomProvider id:0 online
2016-11-25 13:58:01: App [TelecomProvider] with id [0] and pid [12120], exited with code [1] via signal [SIGINT]
2016-11-25 13:58:01: Starting execution sequence in -fork mode- for app name:TelecomProvider id:0
2016-11-25 13:58:01: App name:TelecomProvider id:0 online
2016-11-25 13:58:02: App [TelecomProvider] with id [0] and pid [15908], exited with code [1] via signal [SIGINT]
2016-11-25 13:58:02: Starting execution sequence in -fork mode- for app name:TelecomProvider id:0
2016-11-25 13:58:02: App name:TelecomProvider id:0 online
2016-11-25 13:58:03: App [TelecomProvider] with id [0] and pid [14020], exited with code [1] via signal [SIGINT]
2016-11-25 13:58:03: Starting execution sequence in -fork mode- for app name:TelecomProvider id:0
2016-11-25 13:58:03: App name:TelecomProvider id:0 online
2016-11-25 13:58:03: App [TelecomProvider] with id [0] and pid [15184], exited with code [1] via signal [SIGINT]
2016-11-25 13:58:03: Script Mypath\app.js had too many unstable restarts (16). Stopped. "errored"

The app itself is stable and using just pm2 is working fine.

Any idea what is going wrong?

pm2 resurrect not being called on reboot

The documentation says:

If PM2_SERVICE_SCRIPTS is not set, then the default behavior is to call pm2 resurrect on service startup - when PM2 is running with the list of processes you want launched by the service, use pm2 save to dump the process list, ready for the service to restore it when it next starts.

I can't get this to work. When I run pm2-service-install, I've set all values except selecting no "n" for PM2_SERVICE_SCRIPTS. When I fill out PM2_SERVICE_SCRIPTS with index.js, my app is launched. However, I want to use non-default configuration including cluster mode.

I've gotten my configuration perfect with just pm2, then called pm2 save. When I restart, pm2 list shows no entries. When I manually call pm2 resurrect all my processes are successfully restored.

System info:
Windows Server 2012 R2 Standard
Latest pm2 and pm2-windows-service installed with npm -g.

How do I get this working? It's critical for our setup that we can restart an entire process list, not just a single service when we restart.

Configuring it as startup service with windows scripting

Hi,

I would to configure my project as startup service with pm2-service install.

I set these env variables to provide the defaults:

SET PM2_HOME=C:\workspace\nodejs\startup\appCfgData.pm2
SET PM2_SERVICE_PM2_DIR=C:\workspace\nodejs\startup\node_modules\pm2\index.js
SET PM2_SERVICE_SCRIPTS=C:\workspace\nodejs\startup\bin\client1.js
SET SET_PM2_HOME=true
SET SET_PM2_SERVICE_PM2_DIR=true
SET SET_PM2_SERVICE_SCRIPTS=true

My requirement is to install my script as startup service without asking user for any input.

I tried like providing the same inputs from input.txt file, but its not working as expected as

pm2-service-install -n test < input.txt.

Input isn't matching the prompted query as prompting is happening lately.

Thanks,
Rajashekhar

Make dealing with the caveats easier

Add a command to the CLI to help perform some of the setup that is detailed in the caveats section (environment variables etc.), possibly also expand this to allow using pm2 from a non-admin prompt (e.g. pm2-service <pm2 args go here>).

Support different versions of global pm2

Currently the pm2 CLI starts emitting warning messages when the plugin version and the globally installed versions differ, there should be an easy way to tell pm2-windows-service what version of pm2 you want it to use.

Storage or update location

Hi,

Could you please let me know what actually it modifies, how to get the list of startup list?
where does it store?

App keeps on restarting

After restarting the server to check if it will start the app. This happened:
image

It keeps on restarting... any idea?

Requesting ability to assign a priority to the service

I have a script that is time sensitive, and having it not be interrupted when the computer is busy would be preferable. So having the ability to set the process(s) to high priority in Windows would be ideal.

Thank you

pm2-service-install throws exception

Hi,

I get an exception when trying to install with pm2-service-install.
The exception is:

C:\Users\ariel.j\AppData\Roaming\npm\node_modules\pm2-windows-service\bin\pm2-se
const pm2ws = require('../src/index');
^^^^^
SyntaxError: Use of const in strict mode.
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

Maybe it has something to do with my node version?

Publish new changes

Hello everyone!
There is new option for passive installation of service [--unattended]. But this is not publish yet. Can you publish the new changes please?
Thank you!

Running service as specific user

My node process acesses a network folder. Pm2-windows-service runs the node process but as it is running with administrator it can not acess the network folder. Can a daemon process run as a specific user?

Service crash at start up

Error log: \AppData\Roaming\npm\node_modules\pm2-windows-service\src\daemon\pm2.err.log

C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\safe-clone-deep\src\index.js:49
    if (obj.hasOwnProperty(attr)) {
            ^

TypeError: obj.hasOwnProperty is not a function
    at safeDeepClone (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\safe-clone-deep\src\index.js:49:13)
    at safeDeepClone (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\safe-clone-deep\src\index.js:53:22)
    at cloneWrap (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\safe-clone-deep\src\index.js:65:10)
    at Object.clone (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\Utility.js:39:12)
    at Object.Common.deepCopy.Common.serialize.Common.clone (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\Common.js:151:18)
    at C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\God.js:379:23
    at forkMode (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\God.js:231:15)
    at C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\God\ForkMode.js:203:22
    at C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\async\lib\async.js:52:16
    at C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\async\lib\async.js:1209:30
C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\safe-clone-deep\src\index.js:49
    if (obj.hasOwnProperty(attr)) {
            ^

TypeError: obj.hasOwnProperty is not a function
    at safeDeepClone (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\safe-clone-deep\src\index.js:49:13)
    at safeDeepClone (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\safe-clone-deep\src\index.js:53:22)
    at cloneWrap (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\safe-clone-deep\src\index.js:65:10)
    at Object.clone (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\Utility.js:39:12)
    at Object.Common.deepCopy.Common.serialize.Common.clone (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\Common.js:151:18)
    at C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\God.js:379:23
    at forkMode (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\God.js:231:15)
    at C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\God\ForkMode.js:203:22
    at C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\async\lib\async.js:52:16
    at C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\async\lib\async.js:1209:30
C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\safe-clone-deep\src\index.js:49
    if (obj.hasOwnProperty(attr)) {
            ^

TypeError: obj.hasOwnProperty is not a function
    at safeDeepClone (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\safe-clone-deep\src\index.js:49:13)
    at safeDeepClone (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\safe-clone-deep\src\index.js:53:22)
    at cloneWrap (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\safe-clone-deep\src\index.js:65:10)
    at Object.clone (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\Utility.js:39:12)
    at Object.Common.deepCopy.Common.serialize.Common.clone (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\Common.js:151:18)
    at C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\God.js:379:23
    at forkMode (C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\God.js:231:15)
    at C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\pm2\lib\God\ForkMode.js:203:22
    at C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\async\lib\async.js:52:16
    at C:\Users\sahlf\AppData\Roaming\npm\node_modules\pm2-windows-service\node_modules\async\lib\async.js:1209:30

js error when installing service

I receive the following error when running pm2-service-install.

C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2-windows-service\node
_modules\promisify-node\utils\args.js:9
  var args = func.toString().match(/function\s.*?\(([^)]*)\)/)[1];
                                                              ^

TypeError: Cannot read property '1' of null
    at module.exports (C:\Users\Administrator\AppData\Roaming\npm\node_modules\p
m2-windows-service\node_modules\promisify-node\utils\args.js:9:63)
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2-windows-servi
ce\node_modules\promisify-node\index.js:79:29
    at Array.filter (<anonymous>)
    at processExports (C:\Users\Administrator\AppData\Roaming\npm\node_modules\p
m2-windows-service\node_modules\promisify-node\index.js:60:6)
    at module.exports (C:\Users\Administrator\AppData\Roaming\npm\node_modules\p
m2-windows-service\node_modules\promisify-node\index.js:112:10)
    at Object.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modul
es\pm2-windows-service\src\install.js:7:11)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)

This is on node v 8.4.0

"Sorry, this script requires pm2" - environment variable issue?

Hi. I'm having some trouble getting PM2 working as a service using this code. To explain what I have done so far:

NPM global install directory set to: C:\ProgramData\npm
NPM global cache set to: C:\ProgramData\npm-cache\

pm2 and pm2-windows-service installed globally.

I have set up pm2 and it works fine, I can run 'pm2 resurrect' from any user account and the apps are launched successfully. I have run pm2-install-service and followed the instructions. Environment variables are set up as follows within the system variables:

PM2_HOME : C:\etc\pm2_home
PM2_SERVICE_PM2_DIR : C:\ProgramData\npm
PM2_SERVICE_SCRIPTS : y
Path : (includes others);C:\ProgramData\npm\

When I try to start the service, it shows started in services then almost immediately stops. The log file shows:

Sorry, this script requires pm2
C:\ProgramData\npm\node_modules\pm2-windows-service\node_modules\node-windows\lib\wrapper.js:177
    child.send('shutdown');
         ^

TypeError: Cannot read property 'send' of null
    at process.killkid (C:\ProgramData\npm\node_modules\pm2-windows-service\node_modules\node-windows\lib\wrapper.js:177:10)
    at emitOne (events.js:115:13)
    at process.emit (events.js:210:7)
    at process.exit (internal/process.js:156:15)
    at monitor (C:\ProgramData\npm\node_modules\pm2-windows-service\node_modules\node-windows\lib\wrapper.js:99:17)
    at ChildProcess.<anonymous> (C:\ProgramData\npm\node_modules\pm2-windows-service\node_modules\node-windows\lib\wrapper.js:170:5)
    at emitTwo (events.js:125:13)
    at ChildProcess.emit (events.js:213:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)

From my own digging, this appears to indicate an environment variable issue but I am at a loss as to what exactly given I can run node, npm and pm2 from any user account within cmd.

Any suggestions?

Thanks

Windows 10 installation locks up and does not complete

I've used this service on many versions of Windows successfully, but am stuck trying to install on a new VM using Windows 10. I wish I had more details and can try to answer any diagnostic questions, but that's all I know right now. Any suggestions?

How to keep pm2 running when logging off?

I have the service running and it re-spawns the process on the server correctly when the server is restarted. The problem is this only works when I am logged into the server. I want this to be kept alive regardless if the user is logged on or not. How can I do this?

App is a meteor app built as a nodejs app

P2_HOME: c:\node\pm2\lib
PM2_SERVICE_SCRIPTS: c:/node/pm2/scripts/process.json
PM2_SERVICE_PM2_DIR: c:\npm\node_modules\pm2\index.js

process.json

{
"apps": [
{
"name": "myapp",
"script": "../../apps/myapp/1.0.0/main.js",
"log_date_format": "YYYY-MM-DD",
"exec_mode": "fork_mode",
"watch": true,
"env": {
"PORT": 3000,
"MONGO_URL": "",
"ROOT_URL": "http://localhost:3000"
},
"env_production" : {
"NODE_ENV": "production"
}
}
]
}

Documentation improvements

Might be worth mentioning that paths should be double quoted when installing a service. This helps when they contain spaces.

Feature Request

Awesome job so far!

A few features that I would like to see included:

  1. Service description (e.g. -n ServiceName -d Service Description)
  2. Clean Environment variables on uninstall (PM2_HOME, PM2_SERVICE_SCRIPTS... and SET_PM2_SERVICE_SCRIPTS...)
  3. Setup service from configuration file (-r) // create service from batch file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.