I am writing an upstart configuration file. Within it, I have a pre-start script, a script, and a pre-stop script stanza. Each of these had a large amount of identical code. Thus, I attempted to refactor this code into a few bash functions. However, in so doing I discovered that "one does not simply write bash in an upstart configuration file". A bash function
keyword is not allowed as it is interpreted as a stanza, and it isn't a valid upstart stanza.
# Some header stanzas that are boring
...
env ONE_OF_A_FEW_VARIABLES
...
function an_illegal_function () {...}
pre-start script
function_call_A
function_call_B
end script
script
function_call_A
function_call_C
echo "I love pie."
end script
pre-stop script
function_call_B
function_call_C
end script
I would really like to avoid the kind of code duplication that will exist if I have to copy-paste the contents of each function into stanzas like those above. How can I get some bash commands DRY'd up into a common location and have each of my *script
stanzas reference them?