Skip to content

Instantly share code, notes, and snippets.

@zyzsdy
Created May 22, 2019 09:16
Show Gist options
  • Save zyzsdy/f07d3ff332548039c20d3fe26cd88a60 to your computer and use it in GitHub Desktop.
Save zyzsdy/f07d3ff332548039c20d3fe26cd88a60 to your computer and use it in GitHub Desktop.
Nginx windows版启动脚本,防止多开
@echo off
if exist logs/nginx.pid ( goto checknginx ) else ( goto start )
:checknginx
setlocal enabledelayedexpansion
for /f %%k in (logs/nginx.pid) do (set pid=%%k & goto next)
:next
wmic process get name,processid | findstr !pid! > ~pidprocess.txt
echo xxxxx >> ~pidprocess.txt
for /f %%i in (~pidprocess.txt) do (set processname=%%i & goto processcheck)
:processcheck
set processhead=!processname:~0,5!
if !processhead!==nginx ( echo Nginx already running ) else ( goto cleanandstart )
goto end
:start
start nginx.exe
goto :eof
:cleanandstart
del ~pidprocess.txt
start nginx.exe
goto :eof
:end
rem clean
del ~pidprocess.txt
pause
@echo off
nginx -s stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment