node.js - AWS 用户数据无法在 Windows Server 2019 上运行
问题描述
当前设置:
在 AWS 中手动启动带有节点应用程序的 Windows Server 2019 实例。下面的命令在这个实例上工作正常
Pm2 delete myapp
Pm2 start
问题 :
我们已经创建了上述实例的 AMI,并使用 cloudformation 模板启动它。在 cloudformation 模板的 userdata 中,我们对 nodejs 的配置文件进行了一些更改,并使用上述命令重新启动了节点应用程序。
输出:
使用 cloduformation userdata 成功修改配置文件
错误:
上述命令(Pm2 delete myapp 和 Pm2 start)在执行 userdata 时失败。下面是用户数据日志。
The errors from user scripts: pm2 : The term 'pm2' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Windows\TEMP\UserScript.ps1:15 char:1
+ pm2 delete RenderWorker
+ ~~~
+ CategoryInfo : ObjectNotFound: (pm2:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
pm2 : The term 'pm2' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Windows\TEMP\UserScript.ps1:16 char:1
+ pm2 start
+ ~~~
+ CategoryInfo : ObjectNotFound: (pm2:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
其他发现:
Pm2 命令可用于新启动的 ec2 实例。
C:\Users\Administrator>pm2
usage: pm2 [options] <command>
pm2 -h, --help all available commands and options
pm2 examples display pm2 usage examples
pm2 <command> -h help on a specific command
Access pm2 files in ~/.pm2
cloudofmation中的用户数据:
UserData:
Fn::Base64: !Sub |
<powershell>
$config = '{
"MyENV": "${MyENV}",
"UR1L": "${URL1}",
"URL2": "${URL2}",
"BUCKET": "${MyBucket}",
"PATH": "${Mypath}"
}'
echo $config
$config | Set-Content C:\Projects\myapp\settings\config.json
cd 'C:\Projects\myapp'
pm2 delete RenderWorker
pm2 start
</powershell>
<runAsLocalSystem>true</runAsLocalSystem>
<persist>true</persist>
解决方案
我怀疑您是否可以pm2
直接这样运行,因为pm2
SYSTEM 路径下不存在路径。
您可能需要按如下方式包含它的完整路径才能运行该命令。
例如,您的pm2
居住C:\etc\
地如下,您需要包括以下内容:
C:\etc\.pm2 delete RenderWorker
C:\etc\.pm2 start
或者如果您熟悉路径,则可以将其作为环境变量。
推荐阅读
- c++ - 如何编辑文本文件中的特定行?
- java - 使用 mockito 具有 CompletableFuture.allOf 的测试方法
- multithreading - 为什么在子例程昂贵的情况下多线程执行不起作用?
- python-3.x - 关于定义函数和字符串列表的问题
- python - 如何将一列添加到 df 以汇总 A 列中条目的所有匹配值?
- swift - 如何在swiftUI中制作一堆垂直滑块
- saml - 如何修复在 Hue 应用程序中使用 SAML 的错误
- c++ - 搜索 -ldeepsort 时跳过不兼容的 ../tracker/libdeepsort.so
- c# - 如何使用 RSA 私钥和消息创建签名。签名长度为 256 位
- jira-rest-api - 如何通过 Agile rest api 从 sprint 中删除问题