Closed rajashekhargundeti closed 2 years ago
Hi, thanks for raising this issue and sorry about the delay in getting back to you on this; currently you could use the programmatic API to achieve what you want (by using the no_config
flag for the install), but you'd need to set the environment up manually.
This isn't ideal so I've reworked the setup code and added an -r
/--rc
flag to the cli which allows you to supply the environment variables in a .pm2wsrc
file (or by any of the mechanisms supported by rc) - an example .pm2wsrc
:
{
"PM2_HOME": "C:\\workspace\\nodejs\\startup\\appCfgData.pm2",
"PM2_SERVICE_PM2_DIR": "C:\\workspace\\nodejs\\startup\\node_modules\\pm2\\index.js",
"PM2_SERVICE_SCRIPTS": "C:\\workspace\\nodejs\\startup\\bin\\client1.js"
}
You would then run the install with pm2-service-install -n test -r
from the directory containing the rc file (or from a child directory).
You can try this out now by installing directly from the branch on github -npm i jon-hall/pm2-windows-service#feature/config-rc -g
, and I'll publish it in the next version once I've given it another check over and figured out if I need to push out any more changes at the same time.
I use a PowerShell script to install pm2-windows-service along with a number of other applications and set the relevant environment variables beforehand, similar to the following:
[System.Environment]::SetEnvironmentVariable("PM2_HOME","$env:ProgramFiles\pm2")
[System.Environment]::SetEnvironmentVariable("PM2_SERVICE_SCRIPTS","$env:ProgramFiles\pm2\ecosystem.json")
[System.Environment]::SetEnvironmentVariable("PM2_SERVICE_PM2_DIR","$env:LOCALAPPDATA\Yarn\config\global\node_modules\pm2\ecosystem.json")
...
Start-Process -FilePath 'yarn' -ArgumentList "global add pm2-windows-service" -wait
...
Start-Process 'pm2-service-install' -n 'PM2' -wait
Given this, I'd also like to suppress the input prompt. I tested the config-rc
branch locally using the above and it seems to do the trick. Would love to see this implemented in master
!
As an aside, the setup input prompt for pm2-windows-service
will change the default foreground color to yellow for PowerShell 5.1. It's not a huge concern for me, just interesting.
Hi @seevee, yeah sorry I had completely forgotten that I never got round to finalising and merging the config-rc
branch. I'll do my best to tidy it up and get it merged and published as soon as I can since it is an essential feature for this kind of thing.
As far as the yellow foreground colour goes, I'd guess that might be something caused by inquirer
which is what handles the prompts (that and maybe running as admin at the same time).
Hi @jon-hall! Thanks for responding; it's good to hear that this package is still being actively maintained.
I'm happy to open a PR and do some testing if that will help. Otherwise, eagerly awaiting the update!
Would love to see config-rc
delivered! @jon-hall
I added a quick --unattended
flag in #32 to bypass the Y/n prompt on install. I have the init script using SetX to set all required environment variables before the service is created and started.
The flag works for me! Thanks @irbrad!
Hello @irbrad,
I was trying to use --unattended
, but unfortunately not successful
I tried following command: pm2-service-install -n PM2 --unattended
but I still receiving promts.
I also set variables: PM2_HOME, PM2_SERVICE_PM2_DIR and PM2_SERVICE_SCRIPTS
and have file .pm2wsrc on the same place where command is called
Can you help me?
Or @seevee, probably you can give more details how to use `--unattended``?
Thanks in advance
I found what the problem, last changes where not published https://github.com/jon-hall/pm2-windows-service/issues/37
@aliluyko89 if you does not want to wait until next publish, you can just override your pm2-service-install.js. Just copy pm2-service-install.js from a current git-repository. Then you can use "--unattended"-flag.
@jon-hall , Please, can publish a new stable version? With --unattended and rc with the node V8 fix
thank's 😀
Closing this as the package is now deprecated, users should migrate to pm2-installer
.
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