首页 > Day After Day > 给自己编的一个方便管理本地开发环境的批处理

给自己编的一个方便管理本地开发环境的批处理

2016年8月18日 发表评论 阅读评论
@echo off
title 开发环境控制面板

:act_main
cls
echo ----------------------------
echo.
echo 1、启动全部服务
echo 2、停止全部服务
echo.
echo 3、启动单个服务
echo 4、停止单个服务
echo.
echo 按 Q 键退出
echo.
echo ----------------------------
echo.

choice /c:1234q /n /m "请输入命令:"

if %errorlevel% EQU 1 goto start_all
if %errorlevel% EQU 2 goto stop_all
if %errorlevel% EQU 3 goto start_one
if %errorlevel% EQU 4 goto stop_one
if %errorlevel% EQU 5 goto act_exit

:act_exit
exit
goto :eof

:start_one
cls
echo ----------------------------
echo.
echo 1、启动 Nginx
echo 2、启动 PHP
echo 3、启动 Memcache
echo 4、启动 MySQL
echo 5、返回
echo.
echo 按 Q 键退出
echo.
echo ----------------------------

choice /c:12345q /n /m "请输入命令:"

if %errorlevel% EQU 1 goto start_nginx
if %errorlevel% EQU 2 goto start_php
if %errorlevel% EQU 3 goto start_memcached
if %errorlevel% EQU 4 goto start_mysql
if %errorlevel% EQU 5 goto act_main
if %errorlevel% EQU 6 goto act_exit

:stop_one
cls
echo ----------------------------
echo.
echo 1、停止 Nginx
echo 2、停止 PHP
echo 3、停止 Memcached
echo 4、停止 MySQL
echo 5、返回
echo.
echo 按 Q 键退出
echo.
echo ----------------------------

choice /c:12345q /n /m "请输入命令:"

if %errorlevel% EQU 1 goto stop_nginx
if %errorlevel% EQU 2 goto stop_php
if %errorlevel% EQU 3 goto stop_memcached
if %errorlevel% EQU 4 goto stop_mysql
if %errorlevel% EQU 5 goto act_main
if %errorlevel% EQU 6 goto act_exit

:start_all
cls
set "act_type=1"
goto start_nginx

:stop_all
cls
set "act_type=1"
goto stop_nginx

ram ---------- 启动 Nginx -------------

:start_nginx
tasklist | find /i "nginx.exe" > Nul && set "nginx_status=1" || set "nginx_status=0"

if "%nginx_status%" == "1" (
    echo Nginx 服务已启动
) else (
    echo Nginx 服务正在启动 .
    C:\Server\RunHiddenConsole.exe C:\Server\Nginx\nginx.exe -p C:\Server\Nginx
    tasklist | find /i "nginx.exe" > Nul && echo Nginx 服务已经启动成功。 || echo Nginx 服务启动失败。
)

echo.

if "%act_type%" == "1" (
    goto start_php
)

sleep 3
exit
goto :eof

ram ---------- 启动 PHP FastCGI -------------

:start_php
tasklist | find /i "php-cgi.exe" > Nul && set "php_status=1" || set "php_status=0"

if "%php_status%" == "1" (
    echo PHP FastCGI 服务已启动
) else (
    echo PHP FastCGI 服务正在启动 .
    C:\Server\RunHiddenConsole.exe C:\Server\PHP\php-cgi.exe -b 127.0.0.1:9999
    tasklist | find /i "php-cgi.exe" > Nul && echo PHP FastCGI 服务已经启动成功。 || echo PHP FastCGI 服务启动失败。
)

echo.

if "%act_type%" == "1" (
    goto start_memcached
)

sleep 3
exit
goto :eof

ram ---------- 启动 Memcached -------------

:start_memcached
net start | find /i "memcached" > Nul && set "memcached_status=1" || set "memcached_status=0"

if "%memcached_status%" == "1" (
    echo Memcached 服务已启动。
    echo.
) else (
    net start memcached
)

if "%act_type%" == "1" (
    goto start_mysql
)

sleep 3
exit
goto :eof

ram ---------- 启动 MariaDB -------------

:start_mysql
net start | find /i "MariaDB" > Nul && set "mariadb_status=1" || set "mariadb_status=0"

if "%mariadb_status%" == "1" (
    echo MariaDB 服务已启动。
    echo.
) else (
    net start MariaDB
)

sleep 3
exit
goto :eof

ram ---------- 停止 Nginx -------------

:stop_nginx
tasklist | find /i "nginx.exe" > Nul && set "nginx_status=1" || set "nginx_status=0"

if "%nginx_status%" == "1" (
    echo Nginx 服务正在停止 .
    taskkill /F /IM nginx.exe > nul
    tasklist | find /i "nginx.exe" > Nul && echo Nginx 服务停止失败。 || echo Nginx 服务已成功停止。
) else (
    echo 没有启动 Ngnix 服务。
)

echo.

if "%act_type%" == "1" (
    goto stop_php
)

sleep 3
exit
goto :eof

ram ---------- 停止 PHP FastCGI -------------

:stop_php
tasklist | find /i "php-cgi.exe" > Nul && set "php_status=1" || set "php_status=0"
if "%php_status%" == "1" (
    echo PHP FastCGI 服务正在停止 .
    taskkill /F /IM php-cgi.exe > nul
    tasklist | find /i "php-cgi.exe" > Nul && echo PHP FastCGI 服务停止失败。 || echo PHP FastCGI 服务已成功停止。
) else (
    echo 没有启动 PHP FastCGI 服务。
)

echo.

if "%act_type%" == "1" (
    goto stop_memcached
)

sleep 3
exit
goto :eof

ram ---------- 停止 Memcached -------------

:stop_memcached
net start | find /i "memcached" > Nul && set "memcached_status=1" || set "memcached_status=0"

if "%memcached_status%" == "1" (
    net stop memcached
) else (
    echo 没有启动 Memcached 服务。
    echo.
)

if "%act_type%" == "1" (
    goto stop_mysql
)

sleep 3
exit
goto :eof

ram ---------- 停止 MariaDB -------------

:stop_mysql
net start | find /i "MariaDB" > Nul && set "mariadb_status=1" || set "mariadb_status=0"

if "%mariadb_status%" == "1" (
    net stop MariaDB
) else (
    echo 没有启动 MariaDB 服务。
    echo.
)

sleep 3
exit
goto :eof
分类: Day After Day 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.