@echo off
cd C:\Pendataan_Dikdas\
set host=127.0.0.1
set port=8123
set ignore_result=INFO:
cd %~dp0
IF [%1] EQU [] GOTO RUN
GOTO %1

:START
REM cd bin
REM php-cgi.exe set_config.php
REM SET PHP_FCGI_MAX_REQUESTS=0
REM start /MIN nginx
REM start /MIN php-cgi.exe -b 127.0.0.1:9123 -c php.ini
REM cd ..

REM start /MIN Apache24/bin/httpd.exe

for /f "usebackq" %%B in (`tasklist /nh /fi "imagename eq postgres.exe"`) do if not %%B==%ignore_result% GOTO END
:: bin\hstart.exe /NOCONSOLE "pgsql\bin\pg_ctl.exe start -D data -l data\pgsql.log"
C:\Pendataan_Dikdas\pgsql\bin\pg_ctl.exe start -D C:\Pendataan_Dikdas\data -l C:\Pendataan_Dikdas\data\pgsql.log
GOTO OPEN

:STOP
taskkill /f /IM php-cgi.exe
taskkill /f /IM httpd.exe
::Apache24/bin/httpd.exe -s quit

C:\Pendataan_Dikdas\pgsql\bin\pg_ctl.exe stop -D C:\Pendataan_Dikdas\data -l data\pgsql.log
:: pg_ctl stop -m s -D data -l data\pgsql.log
:: pg_ctl stop -m f -D data -l data\pgsql.log
:: pg_ctl stop -m i -D data -l data\pgsql.log
@ping 192.0.2.2 -n 1 -w 3000 > nul
GOTO FORCE_STOP

:RUN
REM for /f "usebackq" %%A in (`tasklist /nh /fi "imagename eq Pendataan.exe"`) do if not %%A==%ignore_result% GOTO END
REM START /min Pendataan.exe 
GOTO END

:FORCE_STOP
::TaskKill /F /IM Postgres.exe
::TaskKill /F /IM Pendataan.exe
GOTO END

:OPEN
START "" "http://%host%:%port%/" 
GOTO END

:ABOUT
START "" "http://%host%:%port%/about.php" 
GOTO END

:END
exit /b
