147 lines
6.3 KiB
Batchfile
147 lines
6.3 KiB
Batchfile
@echo off
|
|
setlocal EnableDelayedExpansion
|
|
set "SCRIPTS=%~dp0"
|
|
set "SCRIPTS=!SCRIPTS:~0,-1!"
|
|
for %%F in ("!SCRIPTS!\..") do set "PROJECT_DIR=%%~fF"
|
|
set "WINSW=!SCRIPTS!\WinSW-x64.exe"
|
|
|
|
net session >nul 2>&1
|
|
if %errorlevel% neq 0 (
|
|
echo [ERROR] Run as Administrator!
|
|
pause & exit /b 1
|
|
)
|
|
|
|
echo =============================================
|
|
echo MatabPanel - Install Services
|
|
echo =============================================
|
|
echo.
|
|
echo Scripts : !SCRIPTS!
|
|
echo Project : !PROJECT_DIR!
|
|
echo.
|
|
|
|
if not exist "!WINSW!" (
|
|
echo [ERROR] WinSW-x64.exe not found in scripts folder.
|
|
pause & exit /b 1
|
|
)
|
|
|
|
if not exist "!SCRIPTS!\nginx\nginx.exe" (
|
|
echo [ERROR] nginx not found in scripts\nginx\
|
|
pause & exit /b 1
|
|
)
|
|
|
|
if not exist "!SCRIPTS!\php\php-cgi.exe" (
|
|
echo [ERROR] php-cgi.exe not found in scripts\php\
|
|
pause & exit /b 1
|
|
)
|
|
|
|
REM --- [1/7] Clear bootstrap cache + OPcache file cache ---
|
|
echo [1/7] Clearing bootstrap cache and OPcache...
|
|
cd /d "!PROJECT_DIR!"
|
|
if exist "bootstrap\cache\config.php" del /F /Q "bootstrap\cache\config.php" >nul 2>&1
|
|
if exist "bootstrap\cache\routes-v7.php" del /F /Q "bootstrap\cache\routes-v7.php" >nul 2>&1
|
|
if exist "bootstrap\cache\services.php" del /F /Q "bootstrap\cache\services.php" >nul 2>&1
|
|
if exist "bootstrap\cache\packages.php" del /F /Q "bootstrap\cache\packages.php" >nul 2>&1
|
|
if exist "bootstrap\cache\events.php" del /F /Q "bootstrap\cache\events.php" >nul 2>&1
|
|
if exist "bootstrap\cache\blade-icons.php" del /F /Q "bootstrap\cache\blade-icons.php" >nul 2>&1
|
|
if exist "bootstrap\cache\filament" rmdir /S /Q "bootstrap\cache\filament" >nul 2>&1
|
|
REM Clear compiled Blade views (storage/framework/views/*.php)
|
|
for %%f in ("storage\framework\views\*.php") do del /F /Q "%%f" >nul 2>&1
|
|
REM Clear OPcache file cache from disk (opcache.file_cache=C:/tmp/php-opcache in php.ini)
|
|
REM Without this, php-cgi reads stale bytecode after restart since validate_timestamps=0
|
|
if exist "C:\tmp\php-opcache" rmdir /S /Q "C:\tmp\php-opcache" >nul 2>&1
|
|
echo [OK] Done.
|
|
echo.
|
|
|
|
REM --- [2/7] storage:link ---
|
|
echo [2/7] Creating storage link...
|
|
"!SCRIPTS!\php\php.exe" artisan storage:link >nul 2>&1
|
|
echo [OK] Done.
|
|
echo.
|
|
|
|
REM --- [3/7] Optimize Laravel ---
|
|
echo [3/7] Optimizing Laravel...
|
|
"!SCRIPTS!\php\php.exe" artisan optimize:clear --quiet 2>nul
|
|
"!SCRIPTS!\php\php.exe" artisan optimize --quiet 2>nul
|
|
"!SCRIPTS!\php\php.exe" artisan filament:optimize --quiet 2>nul
|
|
echo [OK] Done.
|
|
echo.
|
|
|
|
REM --- [4/7] Configure OPcache ---
|
|
echo [4/7] Configuring OPcache...
|
|
if not exist "C:\tmp\php-opcache" mkdir "C:\tmp\php-opcache"
|
|
set "SCRIPTS_BAK=!SCRIPTS!"
|
|
powershell -NoProfile -Command ^
|
|
"$s='!SCRIPTS_BAK!'; $action=New-ScheduledTaskAction -Execute 'cmd.exe' -Argument ('/c \"\"' + $s + '\warmup.bat\"\"'); $trigger=New-ScheduledTaskTrigger -AtStartup; $settings=New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 5) -MultipleInstances IgnoreNew; Unregister-ScheduledTask -TaskName 'MatabWarmup' -Confirm:$false -ErrorAction SilentlyContinue; Register-ScheduledTask -TaskName 'MatabWarmup' -Action $action -Trigger $trigger -Settings $settings -RunLevel Highest -User 'SYSTEM' -Force | Out-Null; Write-Host ' Warmup task registered.'"
|
|
echo [OK] Done.
|
|
echo.
|
|
|
|
REM --- [5/7] Generate nginx.conf from template ---
|
|
echo [5/7] Writing nginx.conf...
|
|
set "PUBLIC_DIR=!PROJECT_DIR:\=/!/public"
|
|
if not exist "!SCRIPTS!\nginx\conf\nginx.conf.template" (
|
|
echo [ERROR] nginx.conf.template not found in scripts\nginx\conf\
|
|
pause & exit /b 1
|
|
)
|
|
powershell -NoProfile -Command ^
|
|
"(Get-Content '!SCRIPTS!\nginx\conf\nginx.conf.template') -replace '\{\{PUBLIC_DIR\}\}', '!PUBLIC_DIR!' | Set-Content '!SCRIPTS!\nginx\conf\nginx.conf'"
|
|
echo [OK] nginx.conf written.
|
|
echo.
|
|
|
|
REM --- [6/7] Firewall ---
|
|
echo [6/7] Firewall rules...
|
|
netsh advfirewall firewall delete rule name="Matab Web 8000" >nul 2>&1
|
|
netsh advfirewall firewall delete rule name="Matab FTP 2121" >nul 2>&1
|
|
netsh advfirewall firewall delete rule name="Matab FTP Passive" >nul 2>&1
|
|
netsh advfirewall firewall delete rule name="Matab Ping" >nul 2>&1
|
|
netsh advfirewall firewall add rule name="Matab Web 8000" dir=in action=allow protocol=TCP localport=8000 >nul
|
|
netsh advfirewall firewall add rule name="Matab FTP 2121" dir=in action=allow protocol=TCP localport=2121 >nul
|
|
netsh advfirewall firewall add rule name="Matab FTP Passive" dir=in action=allow protocol=TCP localport=60000-60020 >nul
|
|
netsh advfirewall firewall add rule name="Matab Ping" dir=in action=allow protocol=icmpv4:8,any >nul
|
|
echo [OK] Done.
|
|
echo.
|
|
|
|
REM --- [7/7] Windows Services ---
|
|
echo [7/7] Installing Windows services...
|
|
|
|
echo Stopping old services...
|
|
"!WINSW!" stop "!SCRIPTS!\matab-autostart.xml" >nul 2>&1
|
|
"!WINSW!" stop "!SCRIPTS!\matab-phpcgi.xml" >nul 2>&1
|
|
"!WINSW!" stop "!SCRIPTS!\matab-ftp.xml" >nul 2>&1
|
|
"!WINSW!" uninstall "!SCRIPTS!\matab-autostart.xml" >nul 2>&1
|
|
"!WINSW!" uninstall "!SCRIPTS!\matab-phpcgi.xml" >nul 2>&1
|
|
"!WINSW!" uninstall "!SCRIPTS!\matab-ftp.xml" >nul 2>&1
|
|
taskkill /f /im nginx.exe >nul 2>&1
|
|
taskkill /f /im php-cgi.exe >nul 2>&1
|
|
taskkill /f /im php.exe >nul 2>&1
|
|
|
|
echo Installing FTP service...
|
|
"!WINSW!" install "!SCRIPTS!\matab-ftp.xml"
|
|
"!WINSW!" start "!SCRIPTS!\matab-ftp.xml"
|
|
echo.
|
|
|
|
echo Installing PHP FastCGI service...
|
|
"!WINSW!" install "!SCRIPTS!\matab-phpcgi.xml"
|
|
"!WINSW!" start "!SCRIPTS!\matab-phpcgi.xml"
|
|
echo.
|
|
|
|
echo Installing nginx service...
|
|
"!WINSW!" install "!SCRIPTS!\matab-autostart.xml"
|
|
"!WINSW!" start "!SCRIPTS!\matab-autostart.xml"
|
|
echo.
|
|
|
|
echo Waiting for web server on port 8000...
|
|
powershell -NoProfile -Command ^
|
|
"$ok=0; for($i=0;$i -lt 60;$i++){try{$t=New-Object Net.Sockets.TcpClient;$t.Connect('127.0.0.1',8000);$t.Close();$ok=1;break}catch{Start-Sleep -Milliseconds 500}}; if($ok){Write-Host '[OK] Server is ready.'}else{Write-Host '[WARN] Server did not respond in 30s.'}"
|
|
|
|
echo.
|
|
echo =============================================
|
|
echo Services installed (auto-start with Windows):
|
|
echo MatabFTP - FTP server (port 2121)
|
|
echo MatabPHPCgi - PHP FastCGI (port 9001)
|
|
echo MatabAutostart - nginx (port 8000)
|
|
echo.
|
|
echo Web: http://localhost:8000
|
|
echo =============================================
|
|
echo.
|
|
pause
|