Systemd ExecStart parameter is not accessible inside the script

Solution 1:

I found the issue, systemd is having its own rules for variables from EnvironmentFiles

https://fedoraproject.org/wiki/Packaging:Systemd#EnvironmentFiles_and_support_for_.2Fetc.2Fsysconfig_files

It says

You may then refer to variables set in the /etc/sysconfig/httpd file with ${FOOBAR} and $FOOBAR, in the ExecStart= lines (and related lines). (${FOOBAR} expands the variable into one word, $FOOBAR splits up the variable value at whitespace into multiple words)

After I changed my line to

ExecStart=/usr/local/bin/backup.sh -s ${SOURCE} -b ${BACKUP} -t ${TITLE} -l backup_%i.log

My problems went away, including one with TITLE that contained white spaces. Without the {} TITLE was expanded to 3 words and since the second and third one appear without '-' to getopts, it will stop further parameter processing and thus ignore the -l backup_%i.log part

getopts implements the standard option processing, which means that it stops looking for options when it either sees an argument that's not an option ...

courtesy of https://unix.stackexchange.com/a/666748/499351