社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Django

尚未运行时批量启动PostgreSQL和Django

Myzel394 • 7 年前 • 688 次点击  

我想创建一个批处理脚本(我认为批处理是最好的编程语言),它可以自动检测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
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/39917