Skip to content

Commit

Permalink
Make create-swapfile.sh more verbose
Browse files Browse the repository at this point in the history
Last time I've see it fail, it was:

  2022/10/02 04:08:05 create-swapfile.sh | sh: 1: /tmp/script/create-swapfile.sh: Cannot allocate memory

  2022/10/02 04:08:05 Action `Create a swap file` failed at stage Run, error: exit status 126

First line indicates that fallocate failed. Fine. But then the code
should have gone through the retry loop, and it should have either fail
again, or succeed. In any case, there should be some logs on stdout or
stderr.

Instead the script returned with 126. At a first glance, it means:

> If a command is found but is not executable, the return status is 126
> -- https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html

But, wait, wrong. This is bash. However the script create-swapfile.sh
runs with shebang /bin/sh, which is a symlink to dash. Looking into dash
source code, we see:

        /* Map to POSIX errors */
        switch (e) {
        default:
                exerrno = 126;
                break;
        case ELOOP:
        case ENAMETOOLONG:
        case ENOENT:
        case ENOTDIR:
                exerrno = 127;
                break;
        }
        exitstatus = exerrno;

Seems like any unexpected error gets mappe to 126, so we don't really
know what happens.

Let's just be more verbose and see if it can help to troubleshoot this
issue.
  • Loading branch information
elboulangero committed Oct 3, 2022
1 parent 762ccab commit 122f7e4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/create-swapfile.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

set -eu
set -eux

for i in $(seq 1 5); do
fallocate -v -l 1G /swapfile && break
Expand Down

0 comments on commit 122f7e4

Please sign in to comment.