How to escape spaces in systemd unit files?

Cobra_Fast asked:

My unit file looks like this (already attempted to escape spaces as \x20 like the docs say):

Description=My Service



but when attempting to start it, it fails with the following message:

Failed at step CHDIR spawning /home/cobra/my service/ No such file or directory
myservice.service: main process exited, code=exited, status=200/CHDIR

Giving the path from this error message to stat returns:

  File: ‘/home/cobra/my service/’
  Size: 280             Blocks: 8          IO Block: 4096   regular file
Device: 903h/2307d      Inode: 4718912     Links: 1
Access: (0754/-rwxr-xr--)  Uid: ( 1000/   cobra)   Gid: ( 1000/   cobra)
Access: 2015-05-24 22:42:12.702657594 +0200
Modify: 2015-03-27 22:28:05.682531000 +0100
Change: 2015-05-24 22:40:58.830298787 +0200
 Birth: -

I cannot remove the spaces from the file name as the service I’m attempting to run requires them for some reason.

Where am I going wrong?

My answer:

The obvious thing to do is to use double quotes.

ExecStart="/home/cobra/my service/"

You also should get rid of the script and move any necessary logic into the unit.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.