[
    {
        "UpdateStageName": "Run PostgreSQL Server",
        "UpdateSourcePlatform": "Linux",
        "UpdateSource": "Executable",
        "UpdateSourceData": "/bin/bash",
        "UpdateSourceArgs": "-c \"cd postgresql && export PGPASSWORD={{AMPPassword}} && pgsql/bin/pg_isready --host=\\\"{{$FullBaseDir}}run\\\" --port={{$ServerPort}} --username=amp --dbname=postgres >/dev/null 2>&1 && exit 0 || pgsql/bin/postgres -D \\\"{{$FullBaseDir}}data\\\" -p {{$ServerPort}} -k \\\"{{$FullBaseDir}}run\\\" --external_pid_file=\\\"{{$FullBaseDir}}run/postgres.pid\\\" --listen_addresses=\\\"{{$ApplicationIPBinding}}\\\" &\"",
        "RunInBackground": true,
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Run PostgreSQL Server",
        "UpdateSourcePlatform": "Windows",
        "UpdateSource": "Executable",
        "UpdateSourceData": "powershell.exe",
        "UpdateSourceArgs": "-NoProfile -Command \"Set-Location -Path 'postgresql'; $env:PGPASSWORD = \\\"{{AMPPassword}}\\\"; & pgsql/bin/pg_isready.exe --host=127.0.0.1 --port={{$ServerPort}} --username=amp --dbname=postgres *> $null 2>&1; if ($LASTEXITCODE -eq 0) { exit 0 } else { & pgsql/bin/postgres.exe -D \\\"{{$FullBaseDir}}data\\\" -p {{$ServerPort}} --listen_addresses=0.0.0.0 }\"",
        "RunInBackground": true,
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Wait For Server Start",
        "UpdateSourcePlatform": "Linux",
        "UpdateSource": "Executable",
        "UpdateSourceData": "/bin/bash",
        "UpdateSourceArgs": "-c \"cd postgresql && export PGPASSWORD={{AMPPassword}} && timeout=60; while ((timeout--)); do pgsql/bin/pg_isready --host=\\\"{{$FullBaseDir}}run\\\" --port={{$ServerPort}} --username=amp --dbname=postgres >/dev/null 2>&1 && exit 0 || sleep 1; done; ((timeout<0)) && { echo \\\"PostgreSQL server failed to start. Aborting\\\"; exit 1; }\"",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Wait For Server Start",
        "UpdateSourcePlatform": "Windows",
        "UpdateSource": "Executable",
        "UpdateSourceData": "powershell.exe",
        "UpdateSourceArgs": "-NoProfile -Command \"Set-Location -Path 'postgresql'; for ($i=0; $i -lt 60; $i++) { $env:PGPASSWORD = \\\"{{AMPPassword}}\\\"; & pgsql/bin/pg_isready.exe --host=127.0.0.1 --port={{$ServerPort}} --username=amp --dbname=postgres *> $null 2>&1; if ($LASTEXITCODE -eq 0) { exit 0 }; Start-Sleep -Seconds 1 }; if ($i -eq 60) { Write-Output \\\"PostgreSQL server failed to start. Aborting\\\"; exit 1 }\"",
        "SkipOnFailure": false
    }
]