I have the following in my redis@.service
file:
...
ExecStop=/bin/bash -c \"/usr/local/bin/redis-cli -p $(echo %i | awk -F \'.\' \'{ print $2 }\') shutdown\"
...
Then when I run:
sudo systemctl stop redis@redis.6379.test-site.com.service
Followed by:
sudo systemctl status redis@redis.6379.test-site.com.service
I get:
...
Process: 10042 ExecStop=/bin/bash -c "/usr/local/bin/redis-cli -p $(echo redis.6379.test-site.com | awk -F '.' '{ print $2 }') shutdown" (code=exited, status=1/FAILURE)
...
Sep 10 17:36:53 hostname bash[10042]: -p: -c: line 0: unexpected EOF while looking for matching `"'
Sep 10 17:36:53 hostname bash[10042]: -p: -c: line 1: syntax error: unexpected end of file
Then if I run:
sudo systemctl start redis@redis.6379.test-site.com.service
Followed by (taken from the systemctl status
output):
/bin/bash -c "/usr/local/bin/redis-cli -p $(echo redis.6379.test-site.com | awk -F '.' '{ print $2 }') shutdown"
Then the command works as expected...
Can anyone shed some light as to what's happening here?
If Systemd is just running the command shown for ExecStop
, and that command works just fine when run manually, shouldn't it also work when systemd runs it?
I have a feeling it's something to do with the quoting, but I'm too much of a newb at bash to wrap my head around it.