0

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.

Jack_Hu
  • 857
  • 6
  • 17
  • why don't you put that command in an executable file and put `ExecStop=/path/to/file` in your redis@.service ? – oguz ismail Sep 10 '18 at 20:08
  • %i is only available in the .service file. – Jack_Hu Sep 10 '18 at 20:42
  • pass it as an argument then – oguz ismail Sep 10 '18 at 20:46
  • 1
    To be honest, I've already worked out a solution, using `EnvironmentFile`'s. That still doesn't solve the issue though. Workarounds are great, but the question still stands. It should work, and there's something wrong with the syntax, which I'd like to get to the bottom of. – Jack_Hu Sep 10 '18 at 20:50
  • The double quotes in the `ExecStop` directive in the service file should definitely *not* be escaped. I’m not sure if the single quotes should be, but try replacing the `\"`s with `"`s and see where that gets you :) – Lucas Werkmeister Sep 13 '18 at 14:46
  • What is the output of `echo $PAGER`? Set the pager environment variable to empty and see if the command works `PAGER="" systemctl status redis@redis.6379.test-site.com.service` – ASaylover3156 Jun 26 '20 at 04:51

0 Answers0