@echo off
rem 提供Windows下nginx的启动,重启,关闭功能
echo ==================begin========================
cls
::ngxin 所在的盘符
set NGINX_PATH=F:
::nginx mysql 所在目录
set NGINX_DIR=F:\xampp\nginx\
set MYSQL_DIR=F:\xampp\mysql\bin\
color 0a
TITLE 拉风的老衲
CLS
echo 初始化...
GOTO restart
:MENU
::tasklist|findstr /i "nginx.exe"
::tasklist /fi "imagename eq nginx.exe"
::*************************************************************************************************************
echo.
echo. [1] 启动wnmp
echo. [2] 关闭wnmp
echo. [3] 重启wnmp
echo. [0] 退 出
echo.
echo.请输入选择的序号:
set /p ID=
IF "%id%"=="1" GOTO start
IF "%id%"=="2" GOTO stop
IF "%id%"=="3" GOTO restart
IF "%id%"=="0" EXIT
PAUSE
::*************************************************************************************************************
::启动
:start
call :startNginx
call :startMysql
GOTO MENU
::停止
:stop
call :shutdownNginx
call :shutdownMysql
GOTO MENU
::重启
:restart
call :shutdownNginx
call :startNginx
call :shutdownMysql
call :startMysql
GOTO MENU
::*************************************************************************************
::底层
::*************************************************************************************
:shutdownNginx
taskkill /F /IM nginx.exe > nul
echo nginx shut success
goto :eof
:startNginx
IF NOT EXIST "%NGINX_DIR%nginx.exe" (
goto :eof
)
%NGINX_PATH%
cd "%NGINX_DIR%"
IF EXIST "%NGINX_DIR%nginx.exe" (
start "" nginx.exe
)
echo nginx start success
goto :eof
:startMysql
net start "MySQL"
echo mysql start success
goto :eof
:shutdownMysql
sc query |find /i "MySQL" >nul 2>nul
if not errorlevel 1 (net stop "MySQL")
echo mysql shutdown success
goto :eof
net start "MySQL" 如果执行失败 服务名无效,因为net start +服务名,启动的是win下注册的服务。此时,系统中并没有注册mysql到服务中。即下面没有mysql服务
1.进入MySQL的bin目录
2.在命令行窗口输入:mysqld –install,回车,提示:Service successfully installed,代表注册服务成功。
3.测试结果 net start mysql
补充
如果要删除服务:
sc delete ServiceName
停止服务
net stop mysql
查看更多操作
sc –help
网友评论