Erratic Google Cloud Function when running a shell script

Refresh

2 weeks ago

Views

6 time

0

I am trying to run a shell script on a Google Cloud Function.

I am using Node as the framework, and have tried different ways to run the script: execSync, execFileSync, spawnSync, etc:

try {
    const output = require('child_process').execSync(__dirname + '/run.sh', [], 
    {
        stdio: 'inherit',
        shell: '/bin/bash'
    });
}
catch (error) {
    process.exit(error.status);
}

The behavior I get is very erratic. Overall I think it worked once, but the rest of the time I either get a connection error and nothing happens, or the function terminates "successfully", but nothing from the shell script gets outputted, so I don't know whether it even ran or not.

I couldn't detect a pattern in when it fails and when it runs.

0 answers