pellepelster / solidblocks

Solidblocks is a library of reusable components for infrastructure operation, automation and developer experience
https://pellepelster.github.io/solidblocks/
MIT License
25 stars 5 forks source link

post_script never executed #28

Open christoph-buente opened 9 months ago

christoph-buente commented 9 months ago

https://github.com/pellepelster/solidblocks/blob/5444af56915a988fe0d5c4f55c89323f2533ac62/solidblocks-hetzner/modules/rds-postgresql/user_data.sh#L237-L239

Hey, i wanted to execute a restart of a service in the post_script part, but i felt it does not get executed. I made a simple test to check:

post_script = <<EOT
    echo "post_script executed" > /root/post_script.txt
EOT

Turns out that the file is never written. I guess some of the commands fail silently due to set -eu -o pipefail. Can we make sure the pre_script and post_script commands are executed regardless of the user data script having issues?

christoph-buente commented 9 months ago
Cloud-init v. 20.4.1 finished at Thu, 21 Dec 2023 22:12:57 +0000. Datasource DataSourceHetzner.  Up 117.15 seconds

Ok, I was just too impatient. The script was still running and eventually, the cloud-init finished including the post_script. But still, as pre_script, main_part, and post_script are executed in the context of one giant shell script which stops due to set -e at any point when a command fails.

pellepelster commented 9 months ago

so you are suggesting to disable -e for the before/after scripts?

christoph-buente commented 9 months ago

Well, each script should run with -e option to stop when something goes wrong. I'm suggesting running the scripts sequentially, but independently from each other.