I have a bash script that forwards down to a mixture of other shell scripts and python scripts. If any of those scripts fail or if the user cancels the script (CTRL+C) I want to perform some cleanup in all cases.
Many users can SSH into a linux box under the same OS user and initiate builds. This is our build server. The script needs to write a "build.lock" file or something, that will be cleaned up whenever the script exits in anyway (error, user exit, etc). If the script is run again before the first one was done executing, it should check for the "build.lock" file and refuse to proceed.
I'm assuming this is the best way to prevent parallel execution of the script. We're using Bash on Ubuntu. Below is the script itself:
#!/bin/bash -e
pushd build-server-scripts > /dev/null
./build.sh "$@"
popd > /dev/null
Is my idea a good solution to this problem? If so, what is the way to implement it? If not, what other ideas would everyone recommend? I'm inexperienced with Bash scripting so I learn as I go.