2

When I specify a working direcotry in a unit file I would like to refer to it from the ExecStart section via a specifier i.e.

[Unit]
Description=A test daemon that says hello
[Service]
Type=oneshot
WorkingDirectory=/home/foo/scipts
ExecStart="%<<WORKING_DIRECTORY_SPECIFIER>>/echo_hello.sh"
RemainAfterExit=yes

Is this possible with Systemd and if it is not are there any work-arounds?

1
  • For ExecStart you should still be using full paths, not 'relative' paths or substitution. Just a suggestion.
    – Thomas Ward
    Feb 14, 2019 at 15:21

2 Answers 2

5

You do not need to specify specifically the Working Directory in the ExecStart, since all commands will be launched as if you have already specified it. Thats the point of it.

You should NOT use ~, since this will use the $HOME of the $USER as which the service is running as. Instead, use relative paths.

If your WorkingDirectory is pointing to /home/foo/scripts/, then you just need to use ExecStart=./somescript.sh If you have subdirectories, its the same thing - ExecStart=subdir1/subdir2/somescript.sh. WorkingDirectory is basically a cd for the services.

0
1

No, you can use ~ or an absolute directory path. Careful though: ~ is likely to point to /root/ as the home of the user of the unit.

and WorkingDirectory itself understands specifiers but those are not user specific except for

"%g"    User group  
"%G"    User GID    
"%u"    User name   
"%U"    User UID    

but those tend to default to user root.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .