首页 > 解决方案 > 如何永远停止重试?

问题描述

我有一个 nodejs 服务器。我永远使用以下批处理脚本启动服务器:

c:\

cd c:\somefolder

forever start server.js

sleep 10

pause

问题是如果服务器无法启动,它会不断地重试。我怎样才能让它只运行一次或几次(n)次?

我也使用这个脚本来停止服务器:

c:\

cd c:\somefolder

forever stopall

cmd /k

它表明当我运行永久列表时没有永久脚本正在运行,但是当我检查资源监视器时 node.exe 处于活动状态。这会导致端口被阻塞。(它是一个 VM 服务器,多个用户使用它)。

标签: node.jswindowsbatch-filenpmforever

解决方案


如果您第一次检查服务是否正在运行,会发生什么?

@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...



推荐阅读