Release 0.8.0: Windows installer, twelve fixes from a real Server 2019 install, operator docs
This commit is contained in:
@@ -195,6 +195,8 @@ function Get-DbParts {
|
||||
|
||||
function Find-MysqlClient {
|
||||
$candidates = @(
|
||||
'C:\MySQL84\bin\mysql.exe',
|
||||
'C:\Program Files\MySQL\MySQL Server 8.4\bin\mysql.exe',
|
||||
'C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe',
|
||||
'C:\mysql56\bin\mysql.exe'
|
||||
) + @(Get-ChildItem 'C:\Program Files\MySQL' -Filter mysql.exe -Recurse -EA SilentlyContinue |
|
||||
@@ -312,10 +314,38 @@ function Stop-App {
|
||||
|
||||
function Restart-App {
|
||||
Head 'Restarting'
|
||||
# Recycle rather than stop/start: it drains existing requests instead of
|
||||
# cutting them off, and it is what a config change actually needs.
|
||||
& $AppCmd recycle apppool /apppool.name:$AppPool 2>&1 | ForEach-Object { Say " $_" }
|
||||
Start-Sleep -Seconds 2
|
||||
# A recycle CANNOT start something that is stopped - it is a no-op on a
|
||||
# stopped pool. Restarting after a failed upgrade, which is exactly when the
|
||||
# pool is stopped, therefore did nothing and then reported "did not respond"
|
||||
# in red, as though the application were broken. Start it first when needed.
|
||||
Import-Module WebAdministration -ErrorAction SilentlyContinue
|
||||
$started = $true
|
||||
try {
|
||||
if (Test-Path "IIS:\AppPools\$AppPool") {
|
||||
$started = ((Get-Item "IIS:\AppPools\$AppPool").State -eq 'Started')
|
||||
}
|
||||
} catch { }
|
||||
if (-not $started) {
|
||||
Say ' the application pool is stopped; starting it' 'Yellow'
|
||||
Start-WebAppPool -Name $AppPool -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 3
|
||||
} else {
|
||||
# Recycle rather than stop/start: it drains existing requests instead of
|
||||
# cutting them off, and it is what a config change actually needs.
|
||||
& $AppCmd recycle apppool /apppool.name:$AppPool 2>&1 | ForEach-Object { Say " $_" }
|
||||
if ($LASTEXITCODE -ne 0) { Say " recycle reported exit $LASTEXITCODE" 'Yellow' }
|
||||
Start-Sleep -Seconds 2
|
||||
}
|
||||
|
||||
# A stopped SITE answers nothing however healthy the pool is.
|
||||
try {
|
||||
$siteNow = Get-Website -Name $SiteName -ErrorAction SilentlyContinue
|
||||
if ($siteNow -and $siteNow.State -ne 'Started') {
|
||||
Say ' the site is stopped; starting it' 'Yellow'
|
||||
Start-Website -Name $SiteName -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 2
|
||||
}
|
||||
} catch { }
|
||||
try {
|
||||
$r = Invoke-WebRequest -Uri ((Get-Deployment).BaseUrl + '/') -UseBasicParsing -TimeoutSec 30
|
||||
Say (" back up (HTTP {0})" -f $r.StatusCode) 'Green'
|
||||
@@ -370,9 +400,28 @@ function Backup-Db {
|
||||
Head 'Database backup'
|
||||
$db = Get-DbParts
|
||||
if (-not $db) { Say ' no .env found - cannot determine the database' 'Red'; return }
|
||||
$usingDefault = -not $Dest
|
||||
if (-not $Dest) { $Dest = 'C:\ProgramData\ShopDB-Flask\backups' }
|
||||
if (-not (Test-Path $Dest)) { New-Item -ItemType Directory -Path $Dest -Force | Out-Null }
|
||||
|
||||
# A dump holds every row, including the users table and its password hashes.
|
||||
# A directory created under ProgramData INHERITS Users:RX, so those hashes
|
||||
# were readable by every authenticated user on the server whenever this
|
||||
# command created the directory rather than the installer.
|
||||
#
|
||||
# Re-applied on every backup, not only on creation, because this may be
|
||||
# repairing a directory made by an earlier version.
|
||||
#
|
||||
# Only for the default location. A path the operator named is theirs, and
|
||||
# silently rewriting its ACL is not this command's business - say so instead.
|
||||
if ($usingDefault) {
|
||||
& icacls.exe $Dest '/inheritance:r' `
|
||||
'/grant' 'BUILTIN\Administrators:(OI)(CI)(F)' `
|
||||
'/grant' 'NT AUTHORITY\SYSTEM:(OI)(CI)(F)' 2>&1 | Out-Null
|
||||
} else {
|
||||
Say ' note: this dump contains password hashes - check who can read that directory' 'Yellow'
|
||||
}
|
||||
|
||||
$mysql = Find-MysqlClient
|
||||
if (-not $mysql) { Say ' mysql client not found' 'Red'; return }
|
||||
$dump = Join-Path (Split-Path $mysql -Parent) 'mysqldump.exe'
|
||||
|
||||
Reference in New Issue
Block a user