10

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

[Unit]
Description=My Service

[Service]
Type=simple
WorkingDirectory=/home/cobra/my\x20service/
ExecStart=/home/cobra/my\x20service/start.sh

[Install]
WantedBy=multi-user.target

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

Failed at step CHDIR spawning /home/cobra/my service/start.sh: 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/start.sh’
  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?

3 Answers3

12

The correct way to generate paths in systemd is to use systemd-escape.

i.e.

~$ systemd-escape --path "/home/cobra/my service/start.sh"
home-cobra-my\x20service-start.sh

Yes / gets replaced with -

hookenz
  • 14,848
4

The obvious thing to do is to use double quotes.

ExecStart="/home/cobra/my service/start.sh"

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

Michael Hampton
  • 252,907
1

For spaces in ExecStart, there is an open bug report.[1] The workaround is to use /usr/bin/env followed by the path in quotes. Example:

ExecStart=/usr/bin/env "/path/with spaces/executable"

The canonical —but not so nice— solution is to use systemd-escape.

systemd-escape --path "/path/with spaces/executable"

[1] https://github.com/systemd/systemd/issues/2132

goetz
  • 113