I've built a docker container and I need to make changes to the service.nginx
file.
I have the following variables defined:
LINE=$(cat /usr/lib/systemd/system/nginx.service | grep -n "ExecStart=" | cut -d: -f1)
APPEND=$(cat /usr/lib/systemd/system/nginx.service | grep "ExecStart=")
CONFIG=" -e\ /nginx/nginx.conf"
FILE="/usr/lib/systemd/system/nginx.service"
Output of these are:
13
ExecStart=/usr/sbin/nginx
-e\ /nginx/nginx.conf
/usr/lib/systemd/system/nginx.service
I want to change line 13 in the service file from
ExecStart=/usr/sbin/nginx
to
ExecStart=/usr/sbin/nginx -e\ /nginx/nginx.conf
I tried several awk
commands with NR
and gsub
and for the life of me I can not generate the file.
I was thinking something along the lines of the following:
awk 'NR==$LINE{gsub("$APPEND", "$APPEND$CONFIG)};1' $FILE > tmp && mv tmp $FILE
It's just generating a new file without the changes.
awk
and step away from the package-supplied service unit file. Your actual task is that you want to override a setting for a service unit. Like the people at https://unix.stackexchange.com/q/398540/5132 and https://unix.stackexchange.com/q/298581/5132 and https://unix.stackexchange.com/q/66029/5132 did. – JdeBP Dec 13 '19 at 17:53