node.js - 如何永远停止重试?
问题描述
我有一个 nodejs 服务器。我永远使用以下批处理脚本启动服务器:
c:\
cd c:\somefolder
forever start server.js
sleep 10
pause
问题是如果服务器无法启动,它会不断地重试。我怎样才能让它只运行一次或几次(n)次?
我也使用这个脚本来停止服务器:
c:\
cd c:\somefolder
forever stopall
cmd /k
它表明当我运行永久列表时没有永久脚本正在运行,但是当我检查资源监视器时 node.exe 处于活动状态。这会导致端口被阻塞。(它是一个 VM 服务器,多个用户使用它)。
解决方案
如果您第一次检查服务是否正在运行,会发生什么?
@echo off
cd /d c:\somefolder
:check_again
(
%__APPDIR__%tasklist.exe /nh | %__APPDIR__%find.exe /I "forever_service_name" >nul
) && (
echo/ Services Forever is Running & Goto :next
) || (
forever start server.js
%__APPDIR__%timeout.exe /t 5
goto :check_again
)
:next
Rem :: Do some task, the services running...
推荐阅读
- java - Log4j ThreadContext MultiThread 不会继承
- mule - XML解析以使用dataweave 2转换json
- python - 与 FORTRAN shell 程序进行交互通信
- r - 在 pheatmap 的行上添加带有图例的颜色
- swift - SwiftUI 小部件 DateStyle 自定义格式
- wordpress - Wordpress子页面在windows子目录安装中给出404
- r - 基于多个条件的标志
- javascript - 将 If/Else 转换为三元 React Typescript
- java - 如何将现有的 Maven 项目作为多模块 Maven 项目的一部分?
- powershell - 在 PowerShell 中运行 PowerShell 脚本运行正确,但从调度程序运行时出错