1
votes

I mentioned on my last question that I found out all the relevant log file locations and commands here: https://cloud.google.com/compute/docs/startupscript#rerunthescript

My situation:

Startup script literally starts with "exit 69" for testing purposes.

Commands I run:

sudo google_metadata_script_runner --script-type startup
echo $?

Output:

0

Relevant contents of /var/log/daemon.log (repeating):

Sep 19 15:15:32 api-0 startup-script: INFO Starting startup scripts.
Sep 19 15:15:32 api-0 startup-script: INFO Found startup-script in metadata.
Sep 19 15:15:32 api-0 startup-script: INFO startup-script: Return code 69.
Sep 19 15:15:32 api-0 startup-script: INFO Finished running startup scripts.

Is there a good way to get the return code in my script without parsing /var/log/daemon.log and hoping that it actually ended up there and that I won't grab the wrong one?

1

1 Answers

1
votes

Hmm, I have no experience with the script_runner thing but I kinda have a solution for you.

Implement an Exit() function in your script with the following content:

function Exit(code) {
    echo $code > /tmp/runner_code
    exit $code    
}

und just cat /tmp/runner_code after executing the script. Does that solve your problem?