bat启停脚本

1.启动scratch和node(node可能有两个版本)

@echo off

rem start nginx begin
set nginxPid=-1
if exist ./nginx-1.14.0/logs/nginx.pid (
	for /f "tokens=* delims=" %%i in (./nginx-1.14.0/logs/nginx.pid) do set nginxPid=%%i
)
echo nginx pid:%nginxPid%

set needStartNginx=1
if %nginxPid% NEQ -1 (
	for /f "tokens=1" %%i in ('tasklist ^| findstr %nginxPid%') do (
		if '%%i' == 'nginx.exe' (
			set needStartNginx=0
		)
	)
)

if %needStartNginx% == 1 (
	echo "start nginx begin!"
	cd nginx-1.14.0
	start nginx.exe
	cd ..
	echo "start nginx end!"
) else (
	echo "nginx already start!"
)
rem start nginx end


rem start scratch begin 
set scratchPid=-1
for /f "tokens=5" %%i in ('netstat -ano ^| findstr ":3000"') do (
    set scratchPid=%%i
)

if %scratchPid% == -1 (
	echo "start scratch begin!"
	node6.exe Main.js
	echo "start scratch end!"
) else (
	for /f "tokens=1" %%i in ('tasklist ^| findstr %scratchPid%') do (
		if '%%i' == 'node6.exe' (
			echo "scratch already start"
		) else (
			if '%%i' == 'node.exe' (
				echo "scratch already start"
			) else (
				echo "scratch port(3000) is used by other process."
				echo "start stop %%i begin!"
				taskkill /pid %%i -f
				echo "start stop %%i end!"
				echo "start scratch begin!"
				node6.exe Main.js
				echo "start scratch end!"
			)
		)
	)
)
rem start scratch end

2.停止nginx和node脚本

@echo off

rem stop nginx begin
set nginxPid=-1
if exist ./nginx-1.14.0/logs/nginx.pid (
	for /f "tokens=* delims=" %%i in (./nginx-1.14.0/logs/nginx.pid) do set nginxPid=%%i
)
echo nginx pid:%nginxPid%

if %nginxPid% == -1 (
	echo "nginx already stop!"
) else (
	for /f "tokens=1" %%i in ('tasklist ^| findstr %nginxPid%') do (
		if '%%i' == 'nginx.exe' (
			echo "stop nginx begin"
			cd nginx-1.14.0
			start nginx.exe -s quit
			cd ..
			echo "stop nginx end"
		)
	)
)
rem stop nginx end

rem stop scratch begin
set scratchPid=-1
for /f "tokens=5" %%i in ('netstat -ano ^| findstr ":3000"') do (
    set scratchPid=%%i
)

if %scratchPid% == -1 (
	echo "scratch already stop!"
) else (
	for /f "tokens=1" %%i in ('tasklist ^| findstr %scratchPid%') do (
		if '%%i' == 'node6.exe' (
			echo "stop scratch begin!"
			taskkill -f /pid %scratchPid%
			echo "stop scratch end!"
		) else (
			if '%%i' == 'node.exe' (
				echo "stop scratch begin!"
				taskkill -f /pid %scratchPid%
				echo "stop scratch end!"
			) else (
				echo "scratch already stop!"
			)
		)
	)
)
rem stop scratch end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kenick

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值