Deploy process on windows never ends

My issue is the same as this closed issue: Deploy process nerver end

The problem is that the machine running pm2 is a Windows machine, in both my case and in the poster’s case. On linux it would of course work fine, because it’s linux! Unfortunately the deployment machine is Windows, so I have to manually log into the computer and start pm2 myself, because no matter how many ways I try to run the deployment process in the background, it can’t be done.

It is my understanding that Windows won’t run a process in the background unless a new window is opened. Maybe I’m wrong. But of course, Octopus can’t open new windows. So, I need to start the node process in the background, but can’t.

Is it possible for Octopus Deploy to start pm2 on a Windows machine? So far, I have concluded that it is not.

Thank you!

Hi Sam,

You need to run PM2 as a windows service in a windows machine, otherwise, it waits for the process to end as you are experiencing.
The documentation in the PM2 website explains how to go about it.

I hope this makes sense?


Hi John,

Thank you for your answer, however it is of limited help.

The documentation to which you link is all about running pm2 on linux. At the end, there’s a footnote that mentions in a rather off-hand way some other programs you might try with limited success for windows. I have tried them, and they do not work reliably, I am not sure why or why not; but pm2 is not always running when Windows reboots on some environments.

However I don’t think it should matter. If pm2 is already running when I want to deploy, I still need to use pm2 to stop serving the old version, and start up serving the new version. That amounts to a command like “pm2 startOrReload ecosystem.config.js”, plus a couple others to ensure smooth operations.

When I RDP into the machine, I can open up a terminal, run the same command I want Octopus to execute, close the terminal, logout, and pm2 will keep serving. Whether pm2 was started by me in this way, or at boot time automatically, it is running when the deployment happens. (Although, this ought not to be a breaking requirement – I don’t expect my whole infrastructure to stop working because I forgot to start a service relevant to one application.)

Either way, running the “startOrReload” command will ensure my website is being served, but when Octopus does it, it will hang infinitely long, block all other deployments from proceeding, and require a reboot of Octopus. If I can’t run “startOrReload” from Octopus, what pm2 commands am I supposed to run in order to ensure my new deployment is served? It needs to replace the existing runtimes with new runtimes.

In order for Octopus to interoperate with pm2, it needs to be able to execute pm2 commands without hanging up. Are you saying that it can execute “startOrReload” if pm2 is already running or has been started as a Windows service? Because I don’t think that’s correct; but if I’m wrong and this can be quickly resolved I would appreciate it.


Hi Sam,

We haven’t seen a lot of people using pm2, so unfortunately finding the cause of the issue you have described will be a matter of trail and error.

A quick test using running pm2 startOrReload app.yaml against a Windows 2016 server worked OK locally, which would indicate that it is at least possible to run pm2 via Octopus successfully.

Can you please supply the raw Octopus logs for the deployment? has documentation on getting the raw logs.

Also, what version of Octopus and Windows are you running?

There are a a few things we can look at to try and narrow down the cause of the hanging deployments:

  1. Can you start a simple app like the one below with pm2 through Octopus?
var http=require('http')
var server=http.createServer((function(request,response)
	{"Content-Type" : "text/plain"});
	response.end("Hello World\n");
  - script   : app.js
    instances: 1
    env      :
      DEBUG: "*"
  1. Does changing the user account the tentacle runs under to match the account that your use with an RDP login allow the deployment to succeed ( has documentation on changing the user account).
  2. If you enable debugging in pm2, do the pm2 logs display any useful information during the application start?
  3. While Octopus is attempting to deploy the app, what does pm2 app show report if you RDP into the server?

Matt C

Looking at this closer, the issue may be any commands that launch an executable will force later versions of Powershell to wait until the executable has been closed before the script will end.

So running

pm2.cmd list

if the pm2 daemon has not started will result in a node.exe instance being run in the background, and Powershell then sits and waits for it to be closed (which obviously isn’t going to happen because pm2 is designed to run in the background).

What you can do is run this instead:

$p = Start-Process "pm2.cmd" -ArgumentList "list" -PassThru 

By starting a command with Start-Process and waiting for the exit with $p.WaitForExit(), Powershell will not wait for any launched executables to close before exiting.

Matt C

I will try this and get back to you either with a confirmation, or with some more detailed information.

Thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.