我想创建一个批处理脚本(我认为批处理是最好的编程语言),它可以自动检测django或postgresql服务器是否正在运行,如果是,则应停止并重新启动它们,如果不是,则应启动它们。
我在用
pg_ctl status
以确定服务器是否正在运行。
@echo off
::chcp 437
chcp 1525
:start
FOR /F "tokens=*" %%F IN ('pg_ctl -D "%ProgramFiles%\PostgreSQL\10\data" status') do SET result=%%F
echo %result%
if /I %result% == "pg_ctl: kein server läuft" (
goto start_server
) else (
goto restart_server
)
:start_server
echo "Server wird gestartet..."
call pg_ctl -D "%ProgramFiles%\PostgreSQL\10\data" start
call manage.py runserver
:restart_server
echo "Server läuft bereits, Stopp..."
call pg_ctl -D "%ProgramFiles%\PostgreSQL\10\data" stop
pkill -f runserver
goto start_server
goto start
pause