Startup, restart, shutdown function under Windows

@echo off
rem provides nginx startup, restart and shutdown functions under Windows

echo ================ ==begin========================

cls
:: Drive letter where ngxin is located
set NGINX_PATH=E:

: The directory where nginx is located
set NGINX_DIR=E:\service\1\nginx-1.16.0color 0a
TITLE Nginx Management Program Enhanced Edition
br />
CLS

echo.
echo. ** Nginx management program***
echo. *** create 2019-09-10 ***
echo.

:MENU

echo. ***** nginx process list ******
::tasklist|findstr / i "nginx.exe"
tasklist /fi "imagename eq nginx.exe"

echo.

if ERRORLEVEL 1 (
echo nginx.exe Does not exist
) else (
echo nginx.exe exists
)

echo.
::*********** ************************************************** ************************************************
echo.
echo. [1] Start Nginx
echo. [2] Turn off Nginx
echo. [3] Restart Nginx
echo. [4] Refresh the console< br /> echo. [5] Reload Nginx configuration file
echo . [6] Check and test nginx configuration file
echo. [7] Check nginx version
echo. [0] Exit
echo.

echo. Please enter selection Serial number:
set /p ID=
IF "%id%"=="1" GOTO start
IF "%id%"=="2" GOTO stop
IF "%id%"=="3" GOTO restart
IF "%id%"=="4" GOTO MENU
IF "%id%"=="5" GOTO reloadConf
IF "%id%"=="6" GOTO checkConf
IF "%id%"=="7" GOTO showVersion
IF "%id%"=="0" EXIT
PAUSE

::************************************** ************************************************** *********************
::Start
:start
call :startNginx
GOTO MENU

::Stop
:stop
call :shutdownNginx
GOTO MENU

::Restart
:restart
call: shutdownNginx
call :startNginx
GOTO MENU

::Check test configuration file
:checkConf
call :checkConfNginx
GOTO MENU

::Reload Nginx configuration file
:reloadConf
call :checkConfNginx
call :r eloadConfNginx
GOTO MENU

:: show nginx version
:showVersion
call :showVersionNginx
GOTO MENU


::*********************************************** **************************************
::Bottom layer
: :************************************************* ************************************
:shutdownNginx
echo.
echo.Close Nginx...
taskkill /F /IM nginx.exe> ​​nul
echo.OK, close all nginx processes
goto :eof
< br />:startNginx
echo.
echo. Start Nginx......
IF NOT EXIST "%NGINX_DIR%nginx.exe" (
echo "%NGINX_DIR% nginx.exe "does not exist
goto :eof
)

%NGINX_PATH%
cd "%NGINX_DIR%"

IF EXIST " %NGINX_DIR%nginx.exe" (
echo "start'' nginx.exe"
start "" nginx.exe
)
echo.OK
goto :eof


:checkConfNginx
echo.
echo. check test ng inx configuration file...
IF NOT EXIST "%NGINX_DIR%nginx.exe" (
echo "%NGINX_DIR%nginx.exe" does not exist
goto :eof
)

%NGINX_PATH%
cd "%NGINX_DIR%"
nginx -t -c conf/nginx.conf

goto :eof

::Reload the nginx configuration file
:reloadConfNginx
echo.
echo. Reload the nginx configuration file...
IF NOT EXIST " %NGINX_DIR%nginx.exe" (
echo "%NGINX_DIR%nginx.exe" does not exist
goto :eof
)

%NGINX_PATH%
cd "%NGINX_DIR%"
nginx -s reload

goto :eof

:: show nginx version
:showVersionNginx
echo.
%NGINX_PATH%
cd "%NGINX_DIR%"
nginx -V
goto :eof

Leave a Comment

Your email address will not be published.