[英]Windows: Auto start PM2 and node apps
At a Windows AWS server i have a NODE app and i'm using PM2 to launch the app在 Windows AWS 服务器上,我有一个 NODE 应用程序,我正在使用 PM2 启动该应用程序
I have tried the NPMs: "pm2-windows-startup" and "pm2-windows-service"我已经尝试过 NPM:“pm2-windows-startup”和“pm2-windows-service”
But after i restart my AWS instance and run但是在我重新启动我的 AWS 实例并运行之后
PM2 ls
No node app shows up in the list...列表中没有显示节点应用程序...
I followed the instructions...我按照说明操作...
The PM2 logs dont contain any thing... PM2 日志不包含任何东西......
I have not added any ENV variables explicit (when i tried PM2 could not start any more - so i created a fresh AWS windows instance and installed every thing from scratch again...)我没有显式添加任何 ENV 变量(当我尝试 PM2 无法再启动时 - 所以我创建了一个新的 AWS windows 实例并再次从头开始安装所有东西......)
PM2 is located the default place (i have not changed any paths) PM2 位于默认位置(我没有更改任何路径)
C:\Users\Administrator\.pm2
My PM2 file contains:我的 PM2 文件包含:
2017-03-13 07:37:48: =============================================================================== 2017-03-13 07:37:48: --- New PM2 Daemon started ---------------------------------------------------- 2017-03-13 07:37:48: ===================================== ======================================== 2017-03-13 07:37:48 : --- 新的 PM2 守护进程开始了 ------------------------------------------ ----------
2017-03-13 07:37:48: Time: Mon Mar 13 2017 07:37:48 GMT+0000 (Coordinated Universal Time) 2017-03-13 07:37:48: PM2 version: 2.4.2 2017-03-13 07:37:48: Node.js version: 6.10.0 2017-03-13 07:37:48: Current arch: x64 2017-03-13 07:37:48: PM2 home: C:\Users\Administrator.pm2 2017-03-13 07:37:48: PM2 PID file: C:\Users\Administrator.pm2\pm2.pid 2017-03-13 07:37:48: RPC socket file: \.\pipe\rpc.sock 2017-03-13 07:37:48: BUS socket file: \.\pipe\pub.sock 2017-03-13 07:37:48: Application log path: C:\Users\Administrator.pm2\logs 2017-03-13 07:37:48: Process dump file: C:\Users\Administrator.pm2\dump.pm2 2017-03-13 07:37:48: Concurrent actions: 2 2017-03-13 07:37:48: SIGTERM timeout: 1600 2017-03-13 07:37:48: =============================================================================== 2017-03-13 07:37:48:时间:2017 年 3 月 13 日星期一 07:37:48 GMT+0000(协调世界时)2017-03-13 07:37:48:PM2 版本:2.4.2 2017-03 -13 07:37:48:Node.js 版本:6.10.0 2017-03-13 07:37:48:当前架构:x64 2017-03-13 07:37:48:PM2 主页:C:\Users\Administrator。 pm2 2017-03-13 07:37:48:PM2 PID 文件:C:\Users\Administrator.pm2\pm2.pid 2017-03-13 07:37:48:RPC 套接字文件:\.\pipe\rpc。 sock 2017-03-13 07:37:48:BUS 套接字文件:\.\pipe\pub.sock 2017-03-13 07:37:48:应用程序日志路径:C:\Users\Administrator.pm2\logs 2017 -03-13 07:37:48:进程转储文件:C:\Users\Administrator.pm2\dump.pm2 2017-03-13 07:37:48:并发操作:2 2017-03-13 07:37: 48:SIGTERM 超时:1600 2017-03-13 07:37:48:================================= ==============================================
2017-03-13 07:37:48: Starting execution sequence in -fork mode- for app name:mySuperApp id:0 2017-03-13 07:37:48: App name:mySuperApp id:0 online 2017-03-13 07:40:45: =============================================================================== 2017-03-13 07:37:48:在 -fork 模式下开始执行序列 - 应用名称:mySuperApp id:0 2017-03-13 07:37:48:应用名称:mySuperApp id:0 在线 2017-03- 13 07:40:45: =========================================== ====================================
2017-03-13 07:40:45: --- New PM2 Daemon started ---------------------------------------------------- 2017-03-13 07:40:45: Time: Mon Mar 13 2017 07:40:45 GMT+0000 (Coordinated Universal Time) 2017-03-13 07:40:45: PM2 version: 2.4.2 2017-03-13 07:40:45: Node.js version: 6.10.0 2017-03-13 07:40:45: Current arch: x64 2017-03-13 07:40:45: PM2 home: C:\Users\Administrator.pm2 2017-03-13 07:40:45: PM2 PID file: C:\Users\Administrator.pm2\pm2.pid 2017-03-13 07:40:45: RPC socket file: \.\pipe\rpc.sock 2017-03-13 07:40:45: BUS socket file: \.\pipe\pub.sock 2017-03-13 07:40:45: Application log path: C:\Users\Administrator.pm2\logs 2017-03-13 07:40:45: Process dump file: C:\Users\Administrator.pm2\dump.pm2 2017-03-13 07:40:45: Concurrent actions: 2 2017-03-13 07:40:45: SIGTERM timeout: 1600 2017-03-13 07:40:45: =============================================================================== 2017-03-13 07:40:45: --- 新的 PM2 守护进程启动了 ------------------------------ ------------------ 2017-03-13 07:40:45:时间:2017 年 3 月 13 日星期一 07:40:45 GMT+0000(协调世界时) 2017-03-13 07:40:45:PM2 版本:2.4.2 2017-03-13 07:40:45:Node.js 版本:6.10.0 2017-03-13 07:40:45:当前拱门:x64 2017 -03-13 07:40:45: PM2 主页:C:\Users\Administrator.pm2 2017-03-13 07:40:45: PM2 PID 文件:C:\Users\Administrator.pm2\pm2.pid 2017- 03-13 07:40:45:RPC 套接字文件:\.\pipe\rpc.sock 2017-03-13 07:40:45:BUS 套接字文件:\.\pipe\pub.sock 2017-03-13 07 :40:45:应用程序日志路径:C:\Users\Administrator.pm2\logs 2017-03-13 07:40:45:进程转储文件:C:\Users\Administrator.pm2\dump.pm2 2017-03- 13 07:40:45:并发操作:2 2017-03-13 07:40:45:SIGTERM 超时:1600 2017-03-13 07:40:45:============= ================================================ ================
My PM2 DUMB file contains:我的 PM2 DUMB 文件包含:
[ { "exec_mode": "fork_mode", "watch": false, "treekill": true, "autorestart": true, "automation": true, "pmx": true, "vizion": true, "name": "mySuperApp", "node_args": [], "pm_exec_path": "c:\mypath\mySuperApp\server.js", "env": { "windir": "C:\Windows", "USERPROFILE": "C:\Users\Administrator", "USERNAME": "Administrator", "USERDOMAIN_ROAMINGPROFILE": "EC2AMAZ-REBQJDK", "USERDOMAIN": "EC2AMAZ-REBQJDK", "TMP": "C:\Users\ADMINI~1\AppData\Local\Temp\2", "TEMP": "C:\Users\ADMINI~1\AppData\Local\Temp\2", "SystemRoot": "C:\Windows", "SystemDrive": "C:", "SESSIONNAME": "RDP-Tcp#1", "PUBLIC": "C:\Users\Public", "PSModulePath": "C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules;C:\Program Files (x86)\AWS Tools\PowerShell\", "PROMPT": "$P$G", "ProgramW6432": "C:\Program Files", "ProgramFiles(x86)": "C:\Program Files (x86)", "ProgramFiles": "C:\Program Files", "ProgramData": "C:\ProgramData", "PROCESSOR_REVISION": "3f02", "PRO [{“exec_mode”:“fork_mode”,“watch”:false,“treekill”:true,“autorestart”:true,“automation”:true,“pmx”:true,“vizion”:true,“name”: "mySuperApp", "node_args": [], "pm_exec_path": "c:\mypath\mySuperApp\server.js", "env": { "windir": "C:\Windows", "USERPROFILE": "C :\Users\Administrator", "USERNAME": "Administrator", "USERDOMAIN_ROAMINGPROFILE": "EC2AMAZ-REBQJDK", "USERDOMAIN": "EC2AMAZ-REBQJDK", "TMP": "C:\Users\ADMINI~1\AppData \Local\Temp\2", "TEMP": "C:\Users\ADMINI~1\AppData\Local\Temp\2", "SystemRoot": "C:\Windows", "SystemDrive": "C:" , "SESSIONNAME": "RDP-Tcp#1", "PUBLIC": "C:\Users\Public", "PSModulePath": "C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\ v1.0\Modules;C:\Program Files (x86)\AWS Tools\PowerShell\", "PROMPT": "$P$G", "ProgramW6432": "C:\Program Files", "ProgramFiles(x86) ": "C:\Program Files (x86)", "ProgramFiles": "C:\Program Files", "ProgramData": "C:\ProgramData", "PROCESSOR_REVISION": "3f02", "PRO CESSOR_LEVEL": "6", "PROCESSOR_IDENTIFIER": "Intel64 Family 6 Model 63 Stepping 2, GenuineIntel", "PROCESSOR_ARCHITECTURE": "AMD64", "PM2_USAGE": "CLI", "PM2_INTERACTOR_PROCESSING": "true", "PATHEXT": ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JSE;.WSF;.WSH;.MSC", "Path": "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Amazon\cfn-bootstrap\;C:\Program Files\nodejs\;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\AppData\Roaming\npm", "OS": "Windows_NT", "NUMBER_OF_PROCESSORS": "1", "LOGONSERVER": "\\EC2AMAZ-REBQJDK", "LOCALAPPDATA": "C:\Users\Administrator\AppData\Local", "HOMEPATH": "\Users\Administrator", "HOMEDRIVE": "C:", "ComSpec": "C:\Windows\system32\cmd.exe", "COMPUTERNAME": "EC2AMAZ-REBQJDK", "CommonProgramW6432": "C:\Program Files\Common Files", "CommonProgramFiles(
CESSOR_LEVEL": "6", "PROCESSOR_IDENTIFIER": "Intel64 Family 6 Model 63 Stepping 2, GenuineIntel", "PROCESSOR_ARCHITECTURE": "AMD64", "PM2_USAGE": "CLI", "PM2_INTERACTOR_PROCESSING": "true", "PATHEXT" : ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JSE;.WSF;.WSH;.MSC", "路径": "C:\Windows\system32;C:\Windows; C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Amazon\cfn-bootstrap\;C:\Program Files\nodejs\85038\855User3;8681 Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\AppData\Roaming\npm", "OS": "Windows_NT", "NUMBER_OF_PROCESSORS": "1", "LOGONSERVER": "\\EC2AMAZ-REBQJDK ", "LOCALAPPDATA": "C:\Users\Administrator\AppData\Local", "HOMEPATH": "\Users\Administrator", "HOMEDRIVE": "C:", "ComSpec": "C:\Windows\system32 \cmd.exe", "COMPUTERNAME": "EC2AMAZ-REBQJDK", "CommonProgramW6432": "C:\Program Files\Common Files", "CommonProgramFiles( x86)": "C:\Program Files (x86)\Common Files", "CommonProgramFiles": "C:\Program Files\Common Files", "CLIENTNAME": "THESILVERFOX", "APPDATA": "C:\Users\Administrator\AppData\Roaming", "ALLUSERSPROFILE": "C:\ProgramData", "PM2_HOME": "C:\Users\Administrator\.pm2", "mySuperApp": {} }, "pm_cwd": "c:\mypath\mySuperApp", "exec_interpreter": "node", "pm_out_log_path": "C:\Users\Administrator\.pm2\logs\mySuperApp-out-0.log", "pm_err_log_path": "C:\Users\Administrator\.pm2\logs\mySuperApp-error-0.log", "pm_pid_path": "C:\Users\Administrator\.pm2\pids\mySuperApp-0.pid", "km_link": false, "NODE_APP_INSTANCE": 0, "vizion_running": false, "windir": "C:\Windows", "USERPROFILE": "C:\Users\Administrator", "USERNAME": "Administrator", "USERDOMAIN_ROAMINGPROFILE": "EC2AMAZ-REBQJDK", "USERDOMAIN": "EC2AMAZ-REBQJDK", "TMP": "C:\Users\ADMINI~1\AppData\Local\Temp\2", "TEMP": "C:\Users\ADMINI~1\AppData\Local\Temp\2", "SystemRoot": "C:\Windows", "SystemDrive": "C:", "SESSIONNAME": "RDP-Tcp#1", "PUBLIC": "C:\
x86)": "C:\Program Files (x86)\Common Files", "CommonProgramFiles": "C:\Program Files\Common Files", "CLIENTNAME": "THESILVERFOX", "APPDATA": "C:\Users \Administrator\AppData\Roaming", "ALLUSERSPROFILE": "C:\ProgramData", "PM2_HOME": "C:\Users\Administrator\.pm2", "mySuperApp": {} }, "pm_cwd": "c: \mypath\mySuperApp", "exec_interpreter": "node", "pm_out_log_path": "C:\Users\Administrator\.pm2\logs\mySuperApp-out-0.log", "pm_err_log_path": "C:\Users\ Administrator\.pm2\logs\mySuperApp-error-0.log", "pm_pid_path": "C:\Users\Administrator\.pm2\pids\mySuperApp-0.pid", "km_link": false, "NODE_APP_INSTANCE": 0, "vizion_running": false, "windir": "C:\Windows", "USERPROFILE": "C:\Users\Administrator", "USERNAME": "Administrator", "USERDOMAIN_ROAMINGPROFILE": "EC2AMAZ-REBQJDK", “USERDOMAIN”:“EC2AMAZ-REBQJDK”,“TMP”:“C:\Users\ADMINI~1\AppData\Local\Temp\2”,“TEMP”:“C:\Users\ADMINI~1\AppData\Local \Temp\2", "SystemRoot": "C:\Windows", "SystemDrive": "C:", "SESSIONNAME": "RDP-Tcp#1", "PUBLIC": "C:\ Users\Public", "PSModulePath": "C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules;C:\Program Files (x86)\AWS Tools\PowerShell\", "PROMPT": "$P$G", "ProgramW6432": "C:\Program Files", "ProgramFiles(x86)": "C:\Program Files (x86)", "ProgramFiles": "C:\Program Files", "ProgramData": "C:\ProgramData", "PROCESSOR_REVISION": "3f02", "PROCESSOR_LEVEL": "6", "PROCESSOR_IDENTIFIER": "Intel64 Family 6 Model 63 Stepping 2, GenuineIntel", "PROCESSOR_ARCHITECTURE": "AMD64", "PM2_USAGE": "CLI", "PM2_INTERACTOR_PROCESSING": "true", "PATHEXT": ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JSE;.WSF;.WSH;.MSC", "Path": "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Amazon\cfn-bootstrap\;C:\Program Files\nodejs\;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;881
Users\Public", "PSModulePath": "C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules;C:\Program Files (x86)\AWS Tools\PowerShell\" , "PROMPT": "$P$G", "ProgramW6432": "C:\Program Files", "ProgramFiles(x86)": "C:\Program Files (x86)", "ProgramFiles": "C:\ Program Files", "ProgramData": "C:\ProgramData", "PROCESSOR_REVISION": "3f02", "PROCESSOR_LEVEL": "6", "PROCESSOR_IDENTIFIER": "Intel64 Family 6 Model 63 Stepping 2, GenuineIntel", "PROCESSOR_ARCHITECTURE" : "AMD64", "PM2_USAGE": "CLI", "PM2_INTERACTOR_PROCESSING": "true", "PATHEXT": ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JSE;.WSF; .WSH;.MSC", "路径": "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ Program Files\Amazon\cfn-bootstrap\;C:\Program Files\nodejs\;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;881 03756586388:\Users\Administrator\AppData\Roaming\npm", "OS": "Windows_NT", "NUMBER_OF_PROCESSORS": "1", "LOGONSERVER": "\\EC2AMAZ-REBQJDK", "LOCALAPPDATA": "C:\Users\Administrator\AppData\Local", "HOMEPATH": "\Users\Administrator", "HOMEDRIVE": "C:", "ComSpec": "C:\Windows\system32\cmd.exe", "COMPUTERNAME": "EC2AMAZ-REBQJDK", "CommonProgramW6432": "C:\Program Files\Common Files", "CommonProgramFiles(x86)": "C:\Program Files (x86)\Common Files", "CommonProgramFiles": "C:\Program Files\Common Files", "CLIENTNAME": "THESILVERFOX", "APPDATA": "C:\Users\Administrator\AppData\Roaming", "ALLUSERSPROFILE": "C:\ProgramData", "PM2_HOME": "C:\Users\Administrator\.pm2", "status": "online", "pm_uptime": 1489390668484, "axm_actions": [], "axm_monitor": { "Loop delay": { "alert": {}, "agg_type": "avg", "value": "36.91ms" } }, "axm_options": { "default_actions": true, "transactions": false, "http": false, "http_latency": 200, "http_code": 500, "ignore_routes": [], "profiling": true, "errors": true, "a
03756586388:\Users\Administrator\AppData\Roaming\npm", "OS": "Windows_NT", "NUMBER_OF_PROCESSORS": "1", "LOGONSERVER": "\\EC2AMAZ-REBQJDK", "LOCALAPPDATA": "C:\ Users\Administrator\AppData\Local", "HOMEPATH": "\Users\Administrator", "HOMEDRIVE": "C:", "ComSpec": "C:\Windows\system32\cmd.exe", "COMPUTERNAME": “EC2AMAZ-REBQJDK”,“CommonProgramW6432”:“C:\ Program Files\Common Files", "CLIENTNAME": "THESILVERFOX", "APPDATA": "C:\Users\Administrator\AppData\Roaming", "ALLUSERSPROFILE": "C:\ProgramData", "PM2_HOME": "C: \Users\Administrator\.pm2", "status": "online", "pm_uptime": 1489390668484, "axm_actions": [], "axm_monitor": { "Loop delay": { "alert": {}, "agg_type “:“平均”,“价值”:“36.91ms”}},“axm_options”:{“default_actions”:true,“交易”:false,“http”:false,“http_latency”:200,“http_code”: 500,“ignore_routes”:[],“分析”:真,“错误”:真,“一个lert_enabled": true, "custom_probes": true, .network": false, "ports": false, "ignoreFilter": { "method": [ "OPTIONS" ], "url": [] }, "excludedHooks": [], "module_conf": {}, "module_name": "mySuperApp", "module_version": "2.4.2", "pmx_version": "1.0.3", "error": true }, "axm_dynamic": {}, "created_at": 1489390668484, "restart_time": 0, "unstable_restarts": 0, "versioning": null, "node_version": "6.10.0" } ]
lert_enabled": true, "custom_probes": true, .network": false, "ports": false, "ignoreFilter": { "method": [ "OPTIONS" ], "url": [] }, "excludedHooks": [], "module_conf": {}, "module_name": "mySuperApp", "module_version": "2.4.2", "pmx_version": "1.0.3", "error": true }, "axm_dynamic": { }, "created_at": 1489390668484, "restart_time": 0, "unstable_restarts": 0, "versioning": null, "node_version": "6.10.0" } ]
UPDATE 16 FEB 2020: 2020 年 2 月 16 日更新:
If it is important to you that PM2 automatically starts up without you logging into the machine (after reboot) please follow my new set of instructions instead of the old ones.如果您认为 PM2 无需您登录机器(重启后)即可自动启动对您很重要,请按照我的新说明而不是旧说明进行操作。
New instructions (recommended):新说明(推荐):
Prerequisites (part # 1):先决条件(第 1 部分):
First, I have installed NPM
in a location which is available to all users.首先,我将
NPM
安装在所有用户都可以使用的位置。 Depending on your use-case(s) it might not be necessary.根据您的用例,可能没有必要。 But if you like to change your default location of
NPM
- you should do it first (before continuing).但是,如果您想更改
NPM
的默认位置 - 您应该先执行此操作(在继续之前)。 Here is how you change it to the location (in terminal as administrator): C:\NodeJS\npm
:以下是将其更改为位置的方法(以管理员身份在终端中):
C:\NodeJS\npm
:
npm config set prefix "C:\\NodeJS\\npm"
npm config set cache "C:\\NodeJS\\npm-cache"
npm config set temp "C:\\NodeJS\\temp"
npm config ls -l (this will list all NPM settings -> look for the 3 lines/changes marked as `overriden`)
Prerequisites (part # 2):先决条件(第 2 部分):
PM2_HOME
in System environments
(not user environments).System environments
(不是用户环境)中添加和设置PM2_HOME
。 Like: PM2_HOME
= C:\NodeJS\npm
PM2_HOME
= C:\NodeJS\npm
C:\NodeJS\npm
to the existing system PATH variable (Then you are sure it will work - there has been some issues reported that PM2_HOME
not always working).C:\NodeJS\npm
添加到现有的系统 PATH 变量中(然后你确定它会工作 - 报告了一些问题PM2_HOME
并不总是工作)。 Prerequisites (part # 3):先决条件(第 3 部分):
Currently there is a bug in a module which the package pm2-windows-service
uses - so lets fix this as well, please follow the steps below:目前,
pm2-windows-service
包使用的模块中有一个错误 - 所以让我们也修复这个问题,请按照以下步骤操作:
cd
into: C:\NodeJS\npm\node_modules\pm2-windows-service
cd
进入: C:\NodeJS\npm\node_modules\pm2-windows-service
ncu inquirer
this only outputs the existing and the newest available version of the inquirer
module we need to update, currently: version: 1.1.2
--> 7.0.4
. ncu inquirer
这仅输出我们需要更新的inquirer
器模块的现有和最新可用版本,当前:版本: 1.1.2
--> 7.0.4
。ncu inquirer -u
this will update your packages.json file. ncu inquirer -u
这将更新您的 packages.json 文件。npm install
this will download and update the inquirer
module (please be aware if you don't use specific version syntax in your packages.json
file or you have made manually changes --> other modules would be updated as well. npm install
这将下载和更新inquirer
器模块(请注意,如果您没有在您的packages.json
文件中使用特定的版本语法,或者您手动进行了更改——> 其他模块也将被更新。 Install and setup PM2 (as a service) to automatically startup after reboot:安装并设置 PM2(作为服务)以在重启后自动启动:
cd
into: C:\NodeJS\npm\node_modules\pm2-windows-service
cd
进入: C:\NodeJS\npm\node_modules\pm2-windows-service
pm2-service-install -n PM2_STARTUP_SCRIPT
( PM2_STARTUP_SCRIPT
will be the "Display name" of the Windows service. Change it to what you prefer and hit ENTER
.) pm2-service-install -n PM2_STARTUP_SCRIPT
( PM2_STARTUP_SCRIPT
将是 Windows 服务的“显示名称”。将其更改为您喜欢的名称,然后按ENTER
。)Yes
No
(No need - You have set it already) No
(不需要 - 您已经设置好了)Yes
ENTER
(when nothing is entered - it will default to use PM2's dump.pm2
file - which is created when you run PM2 -f save
, I will return and explain this later on).ENTER
(当没有输入时 - 它会默认使用 PM2 的dump.pm2
文件 - 当你运行PM2 -f save
时创建,我稍后将返回并解释这一点)。 Set PM2_SERVICE_PM2_DIR (the location of the global pm2 to use with the service)?设置 PM2_SERVICE_PM2_DIR(与服务一起使用的全局 pm2 的位置)?
Yes
Specify the directory containing the pm2 version to be used by the service?指定包含服务要使用的 pm2 版本的目录?
ENTER
PM2 service installed and started. PM2 服务已安装并启动。
Setup the app(s) you like PM2 to startup - when shutdown or after a reboot:设置您喜欢 PM2 的应用程序以启动 - 关闭或重新启动后:
pm2 start myApp.js --name mySuperApp
pm2 -f save
pm2 ls
and check your app has been up and running for ~ 5 min (and not only few secs because you just logged in).pm2 ls
并检查您的应用程序是否已启动并运行约 5 分钟(不仅是几秒钟,因为您刚刚登录)。 Uninstall and cleanup "pm2-windows-startup" from your registry (if you switch from my "old instruction" to the new ones):从您的注册表中卸载并清理“pm2-windows-startup”(如果您从我的“旧指令”切换到新指令):
PM2
key from registry like in the picture below:PM2
键,如下图所示: Old instructions (not recommended):旧指令(不推荐):
My old answer below is still working - but PM2 doesn't startup unless you log into the machine because it is loading PM2 from registry and doesn't run it as a service.我在下面的旧答案仍然有效 - 但除非您登录机器,否则 PM2 不会启动,因为它正在从注册表加载 PM2 并且不会将其作为服务运行。
I don't know why - but after several attempts this worked out (at a fresh installed AWS Windows 2016 BASE instance)我不知道为什么 - 但经过几次尝试,这解决了(在新安装的 AWS Windows 2016 BASE 实例上)
UPDATE 08/06/2022 2022 年 8 月 6 日更新
I found out that npm i -g pm2
is global install per user .我发现
npm i -g pm2
是 global install per user 。
it means that if another user logged in into the server, he won't have pm2 install - because -g
is not fully global as we want it to be.这意味着如果另一个用户登录到服务器,他将不会安装 pm2 - 因为
-g
并不像我们希望的那样完全全局。
so the solution for those who wants it fully globall:所以对于那些想要它完全全球化的人的解决方案:
c:\etc
c:\etc
cd c:\etc
npm i pm2
cd c:\etc
npm i pm2
C:\etc\node_modules\.bin
to the System variable PATH
C:\etc\node_modules\.bin
添加到系统变量PATH
pm2
to initialize and create the .pm2
folderpm2
以初始化并创建.pm2
文件夹C:\Users\USER\.pm2
to C:\etc\.pm2
C:\Users\USER\.pm2
到C:\etc\.pm2
PM2_HOME
value: c:\etc\.pm2
PM2_HOME
值: c:\etc\.pm2
pm2 start app.js --name=MY_API
.pm2 start app.js --name=MY_API
。pm2 save
to create a dump of the current apps running. pm2 save
以创建当前正在运行的应用程序的转储。pm2 kill
and then pm2 resurrect
(app should be running, check with pm2 status
)pm2 kill
然后pm2 resurrect
(应用程序应该正在运行,检查pm2 status
)now we need to perform the resurrect command at startup, so:现在我们需要在启动时执行 resurrect 命令,所以:
npm install -g @innomizetech/pm2-windows-service
pm2-service-install -n PM2 --unattended
thats it.而已。
pm2-windows-startup
works great if you're okay with the fact that it is launched on login. pm2-windows-startup
如果您对它在登录时启动这一事实感到满意,那么它的效果很好。 If you have a reboot on a server though (say Windows Update) you are out of luck.如果您在服务器上重新启动(例如 Windows 更新),那么您就不走运了。
pm2-windows-service
did work for me, using @innomizetech
fork, but I've had some issues, probably due to the user or its setup, or something else. pm2-windows-service
确实为我工作,使用@innomizetech
fork,但我遇到了一些问题,可能是由于用户或其设置或其他原因。 Basically the service would start an old version of the saved process list, even though I tried pm2 delete all
, pm2 start ecosystem.config.js
, pm2 save
.基本上该服务会启动一个旧版本的已保存进程列表,即使我尝试过
pm2 delete all
、 pm2 start ecosystem.config.js
、 pm2 save
。
I resorted to a very simple home-made solution:我采用了一个非常简单的自制解决方案:
pm2-resurrect.sh
in C:\
, which contains the single line pm2 resurrect
.C:\
创建一个文件pm2-resurrect.sh
,其中包含单行pm2 resurrect
。C:\pm2-resurrect.sh
.C:\pm2-resurrect.sh
。 In my case I have Git for Windows which comes with bash, which opens the file and executes it.在我的例子中,我有 Git for Windows,它带有 bash,它打开文件并执行它。 I didn't test it but I guess you could have a
.cmd
file with the same content.我没有测试它,但我想你可以有一个具有相同内容的
.cmd
文件。
I tried all of the above with no luck.我尝试了以上所有方法都没有运气。 What worked for me:
什么对我有用:
pm2 resurrect
commandpm2 resurrect
命令easiest way & it works great hope it will help some最简单的方法,效果很好,希望对某些人有所帮助
%windir%\system32\CMD.exe /k "start pm2 start myApp.js --name mySuperApp"
See pm2-installer请参阅pm2 安装程序
Readme is also make it clear how to use it. Readme 也清楚地说明了如何使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.