Thread Type: Question

0

Bash set -euo pipefail: why does my deploy script ignore some failures and exit on others?

I'm hardening a small deploy script for a Linux VPS and I'm running into the classic "set -euo pipefail" surprises. The script pulls a release, runs a build, and restarts a service. I want it to fail fast, but a few things behave differently than I expect. Here's a trimmed version:

bash
#!/usr/bin/env bash
set -euo pipefail

RELEASE_DIR="/srv/app/releases/$(date +%Y%m%d%H%M%S)"
mkdir -p "$RELEASE_DIR"

# 1) grep returning 1 (no match) kills the script here
COUNT=$(grep -c "ERROR" /var/log/app/build.log | head -n 1)

# 2) this function fails inside an if, but the script keeps going
deploy_step() {
  cp -r ./build/. "$RELEASE_DIR"
  false   # simulated failure
  echo "should not print"
}

if deploy_step; then
  echo "deploy ok"
fi

systemctl restart app.service

What I'm trying to…

Join Discussion Unanswered
1

PHP API Request Times Out Even Though Endpoint Works

php

<?php if (is_user_logged_in());

?>

I am trying to make a PHP request to an external API, but the request periodically times out even though the API endpoint itself appears to be online and responding normally when I test it directly. The problem does not happen on every request. Some requests complete in less than a second, while others wait…

php
<?php

$url = 'https://api.example.com/products';

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTPHEADER => <span class="text-token-text-primary cursor-text rounded-sm" data-placeholder-token="true">[
        'Accept: application/json',
    ]</span>,
]);

$response = curl_exec($ch);

if ($response === false) {
    echo 'cURL Error: ' . curl_error($ch);
} else {
    $data = json_decode($response, true);

    echo '<pre>';
    print_r($data);
    echo '</pre>';
}

curl_close($ch);
Join Discussion Answered