问题描述
在 Windows AWS 服务器上,我有一个 NODE 应用程序和我正在使用 PM2 启动应用程序
At a Windows AWS server i have a NODE app andi'm using PM2 to launch the app
我尝试过 NPM:pm2-windows-startup"和pm2-windows-service"
I have tried the NPMs: "pm2-windows-startup" and "pm2-windows-service"
但是在我重新启动我的 AWS 实例并运行之后
But after i restart my AWS instance and run
PM2 ls
列表中没有显示节点应用...
No node app shows up in the list...
我按照说明...
- 安装了 NPM(重启后 PM2 自动启动)
- PM2 启动 myApp.js --name mySuperApp
- PM2 保存
- 重启
- PM2 ls --> 没有运行节点应用程序?:-(
PM2 日志不包含任何内容...
我没有显式添加任何 ENV 变量(当我尝试 PM2 时无法再启动 - 所以我创建了一个新的 AWS Windows 实例并从头开始重新安装所有东西......)
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...)
PM2 位于默认位置(我没有更改任何路径)
PM2 is located the default place (i have not changed any paths)
C:\Users\Administrator\.pm2
我的 PM2 文件包含:
2017-03-13 07:37:48: ================================================================================2017-03-13 07:37:48:--- 新的 PM2 守护进程启动 ----------------------------------------------------
2017-03-13 07:37:48: ===============================================================================2017-03-13 07:37:48: --- New PM2 Daemon started ----------------------------------------------------
2017-03-13 07:37:48:时间:2017 年 3 月 13 日星期一 07:37:48 GMT+0000(协调世界时)2017-03-13 07:37:48:PM2 版本:2.4.22017-03-13 07:37:48:Node.js 版本:6.10.02017-03-13 07:37:48:当前拱:x642017-03-13 07:37:48:PM2 主页:C:\Users\Administrator.pm22017-03-13 07:37:48:PM2 PID 文件:C:\Users\Administrator.pm2\pm2.pid2017-03-13 07:37:48:RPC 套接字文件:\.\pipe\rpc.sock2017-03-13 07:37:48:总线套接字文件:\.\pipe\pub.sock2017-03-13 07:37:48:应用程序日志路径:C:\Users\Administrator.pm2\logs2017-03-13 07:37:48:进程转储文件:C:\Users\Administrator.pm2\dump.pm22017-03-13 07:37:48:并发操作:22017-03-13 07:37:48:SIGTERM 超时:16002017-03-13 07:37:48: ================================================================================
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.22017-03-13 07:37:48: Node.js version : 6.10.02017-03-13 07:37:48: Current arch : x642017-03-13 07:37:48: PM2 home : C:\Users\Administrator.pm22017-03-13 07:37:48: PM2 PID file : C:\Users\Administrator.pm2\pm2.pid2017-03-13 07:37:48: RPC socket file : \.\pipe\rpc.sock2017-03-13 07:37:48: BUS socket file : \.\pipe\pub.sock2017-03-13 07:37:48: Application log path : C:\Users\Administrator.pm2\logs2017-03-13 07:37:48: Process dump file : C:\Users\Administrator.pm2\dump.pm22017-03-13 07:37:48: Concurrent actions : 22017-03-13 07:37:48: SIGTERM timeout : 16002017-03-13 07:37:48: ===============================================================================
2017-03-13 07:37:48:在-fork 模式下启动执行序列,应用名称:mySuperApp id:02017-03-13 07:37:48:应用名称:mySuperApp id:0 在线2017-03-13 07:40:45: ================================================================================
2017-03-13 07:37:48: Starting execution sequence in -fork mode- for app name:mySuperApp id:02017-03-13 07:37:48: App name:mySuperApp id:0 online2017-03-13 07:40:45: ===============================================================================
2017-03-13 07:40:45: --- 新 PM2 守护进程启动 ----------------------------------------------------2017-03-13 07:40:45:时间 : Mon Mar 13 2017 07:40:45 GMT+0000 (协调世界时)2017-03-13 07:40:45:PM2 版本:2.4.22017-03-13 07:40:45:Node.js 版本:6.10.02017-03-13 07:40:45:当前拱:x642017-03-13 07:40:45:PM2 主页:C:\Users\Administrator.pm22017-03-13 07:40:45:PM2 PID 文件:C:\Users\Administrator.pm2\pm2.pid2017-03-13 07:40:45:RPC 套接字文件:\.\pipe\rpc.sock2017-03-13 07:40:45:总线套接字文件:\.\pipe\pub.sock2017-03-13 07:40:45:应用程序日志路径:C:\Users\Administrator.pm2\logs2017-03-13 07:40:45:进程转储文件:C:\Users\Administrator.pm2\dump.pm22017-03-13 07:40:45:并发操作:22017-03-13 07:40:45:SIGTERM 超时:16002017-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.22017-03-13 07:40:45: Node.js version : 6.10.02017-03-13 07:40:45: Current arch : x642017-03-13 07:40:45: PM2 home : C:\Users\Administrator.pm22017-03-13 07:40:45: PM2 PID file : C:\Users\Administrator.pm2\pm2.pid2017-03-13 07:40:45: RPC socket file : \.\pipe\rpc.sock2017-03-13 07:40:45:BUS socket file : \.\pipe\pub.sock2017-03-13 07:40:45: Application log path : C:\Users\Administrator.pm2\logs2017-03-13 07:40:45: Process dump file : C:\Users\Administrator.pm2\dump.pm22017-03-13 07:40:45: Concurrent actions : 22017-03-13 07:40:45: SIGTERM timeout : 16002017-03-13 07:40:45: ===============================================================================
我的 PM2 DUMB 文件包含:
[{"exec_mode": "fork_mode",看":假,杀树":真的,自动重启":真,自动化":真,pmx":真的,视觉":真实,"name": "mySuperApp",节点参数":[],"pm_exec_path": "c:\mypath\mySuperApp\server.js",环境":{"windir": "C:\Windows","USERPROFILE": "C:\用户\管理员","USERNAME": "管理员","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","系统驱动器": "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\","提示": "$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": "真","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;C:\Users\Administrator\AppData\Roaming\npm","OS": "Windows_NT","NUMBER_OF_PROCESSORS": "1","登录服务器": "\\EC2AMAZ-REBQJDK","LOCALAPPDATA": "C:\Users\Administrator\AppData\Local","HOMEPATH": "\用户\管理员","HOMEDRIVE": "C:","ComSpec": "C:\Windows\system32\cmd.exe","计算机名": "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",我的超级应用":{}},"pm_cwd": "c:\mypath\mySuperApp","exec_interpreter": "节点","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":假,"NODE_APP_INSTANCE": 0,vizion_running":假,"windir": "C:\Windows","USERPROFILE": "C:\用户\管理员","USERNAME": "管理员","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","系统驱动器": "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\","提示": "$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": "真","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;C:\Users\Administrator\AppData\Roaming\npm","OS": "Windows_NT","NUMBER_OF_PROCESSORS": "1","登录服务器": "\\EC2AMAZ-REBQJDK","LOCALAPPDATA": "C:\Users\Administrator\AppData\Local","HOMEPATH": "\用户\管理员","HOMEDRIVE": "C:","ComSpec": "C:\Windows\system32\cmd.exe","计算机名": "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","状态": "在线",pm_uptime":1489390668484,"axm_actions": [],axm_monitor":{循环延迟":{警报": {},"agg_type": "平均",值":36.91 毫秒"}},axm_options":{default_actions":真,交易":假,http":假,http_latency":200,"http_code": 500,"ignore_routes": [],分析":真实,错误":对,alert_enabled":真,custom_probes":真,网络":假,端口":假,忽略过滤器":{方法": [选项"],网址":[]},"excludedHooks": [],module_conf":{},"module_name": "mySuperApp","module_version": "2.4.2","pmx_version": "1.0.3",错误":真的},axm_dynamic":{},created_at":1489390668484,重启时间":0,"unstable_restarts": 0,版本控制":空,节点版本":6.10.0"}]
[ { "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", "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;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:\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;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", "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, "alert_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" }]
推荐答案
2020 年 2 月 16 日更新:
如果 PM2 在您不登录机器的情况下自动启动对您很重要(重新启动后),请按照我的新说明而不是旧说明进行操作.
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.
新说明(推荐):
先决条件(第 1 部分):
首先,我在一个可供所有用户使用的位置安装了 NPM
.根据您的用例,它可能没有必要.但是如果你想改变 NPM
的默认位置 - 你应该先做(在继续之前).以下是将其更改为位置的方法(在终端中以管理员身份):C:\NodeJS\npm
:
First, I have installed NPM
in a location which is available to all users. 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). Here is how you change it to the location (in terminal as administrator): 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`)
先决条件(第 2 部分):
- 在
系统环境
(不是用户环境)中添加和设置PM2_HOME
.如:PM2_HOME
=C:\NodeJS\npm
- 将
C:\NodeJS\npm
添加到现有的系统 PATH 变量(然后您确定它会起作用 - 有一些问题报告说PM2_HOME
并不总是有效). - 关闭所有终端并再次打开它们(以管理员身份).您的终端窗口现在将了解您的环境变化.
- Add and set
PM2_HOME
inSystem environments
(not user environments). Like:PM2_HOME
=C:\NodeJS\npm
- Add
C:\NodeJS\npm
to the existing system PATH variable (Then you are sure it will work - there has been some issues reported thatPM2_HOME
not always working). - Close all terminals and open them again (as administrator). Your terminal windows will now be aware of your environment changes.
先决条件(第 3 部分):
- npm install pm2 -g
- npm i pm2-windows-service -g
- npm install -g npm-check-updates
当前,pm2-windows-service
包使用的模块中存在一个错误 - 所以我们也解决这个问题,请按照以下步骤操作:
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:
- 在终端
cd
进入:C:\NodeJS\npm\node_modules\pm2-windows-service
ncuquirer
这只输出我们需要更新的inquirer
模块的现有和最新可用版本,目前:版本:1.1.2代码> -->
7.0.4
.ncu 查询器 -u
这将更新您的 packages.json 文件.npm install
这将下载并更新inquirer
模块(请注意,如果您没有在packages.json
中使用特定版本的语法)code> 文件,或者您进行了手动更改 --> 其他模块也会更新.
- In terminal
cd
into:C:\NodeJS\npm\node_modules\pm2-windows-service
ncu inquirer
this only outputs the existing and the newest available version of theinquirer
module we need to update, currently: version:1.1.2
-->7.0.4
.ncu inquirer -u
this will update your packages.json file.npm install
this will download and update theinquirer
module (please be aware if you don't use specific version syntax in yourpackages.json
file or you have made manually changes --> other modules would be updated as well.
安装并设置 PM2(作为服务)以在重启后自动启动:
- 在终端
cd
进入:C:\NodeJS\npm\node_modules\pm2-windows-service
pm2-service-install -n PM2_STARTUP_SCRIPT
(PM2_STARTUP_SCRIPT
将是 Windows 服务的显示名称".将其更改为您喜欢的名称并点击回车
.)- 执行环境设置(推荐)?
是
- 设置 PM2_HOME?
No
(不需要 - 你已经设置了) - 设置 PM2_SERVICE_SCRIPTS(pm2 的启动脚本列表)?
是
- 设置启动脚本/文件列表(分号分隔的json配置文件或 js 文件)
ENTER
(当没有输入时 - 它会默认使用 PM2 的dump.pm2
文件 - 当你运行PM2 -f save 时创建
,我稍后会返回并解释这一点). 设置 PM2_SERVICE_PM2_DIR(与服务一起使用的全局 pm2 的位置)?
是
- In terminal
cd
into: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 hitENTER
.)- Perform environment setup (recommended)?
Yes
- Set PM2_HOME?
No
(No need - You have set it already) - Set PM2_SERVICE_SCRIPTS (the list of start-up scripts for pm2)?
Yes
- Set the list of startup scripts/files (semi-colon separated json configfiles or js files)
ENTER
(when nothing is entered - it will default to use PM2'sdump.pm2
file - which is created when you runPM2 -f save
, I will return and explain this later on). Set PM2_SERVICE_PM2_DIR (the location of the global pm2 to use with the service)?
Yes
指定包含要使用的 pm2 版本的目录服务?回车
Specify the directory containing the pm2 version to be used by theservice? ENTER
PM2 服务已安装并启动.
- 在 Windows 中打开服务并将服务更改为以管理员(或您的首选角色)身份运行.
设置您喜欢 PM2 的应用程序启动 - 关机时或重启后:
pm2 start myApp.js --name mySuperApp
pm2 -f 保存
- 重新启动或者如果您使用 AWS(或任何其他云提供商).重新启动您的实例 - 等待 5 分钟,然后登录机器并执行
pm2 ls
并检查您的应用程序已启动并运行约 5 分钟(不仅仅是几秒钟,因为您刚刚登录).
pm2 start myApp.js --name mySuperApp
pm2 -f save
- reboot or if you use AWS (or any other cloud provider). Reboot your instance - wait 5 minutes and then log into the machine and execute
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-windows-startup"(如果您从我的旧指令"切换到新指令):
- npm 卸载 pm2-windows-startup -g
- 从注册表中删除
PM2
键,如下图所示:
- npm uninstall pm2-windows-startup -g
- Delete the
PM2
key from registry like in the picture below:
旧说明(不推荐):
我在下面的旧答案仍然有效 - 但除非您登录计算机,否则 PM2 不会启动,因为它正在从注册表加载 PM2 并且不会将其作为服务运行.
我不知道为什么 - 但经过多次尝试后(在全新安装的 AWS Windows 2016 BASE 实例上)
I don't know why - but after several attempts this worked out (at a fresh installed AWS Windows 2016 BASE instance)
- npm install pm2 -g
- npm install pm2-windows-startup -g
- pm2-启动安装
- pm2 start myApp.js --name mySuperApp
- pm2 保存
- 重启
- pm2 ls
这篇关于Windows:自动启动 PM2 和节点应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!