[systemd-devel] Using path name in instantiated units

Florian Lindner mailinglists at xgm.de
Tue Aug 19 10:34:46 PDT 2014


Hello,
I have a systemd unit that should do a commit on a specific path. Since 
there are more then one path / repos, I want to use an instantiated unit for 
that (the stuff with @ in the unit name):


~/.config/systemd/user % cat git-commit at .service
[Unit]
Description=Auto commit for instance.

[Service]
Type = oneshot
Nice = 10

# git returns 1 if there is nothing to commit
SuccessExitStatus=1

WorkingDirectory = %I  # also tried %i
ExecStart = /usr/bin/sh -c 'echo %i > wd'
ExecStart = /usr/bin/sh -c 'echo %i >> wd'
ExecStart = /usr/bin/sh -c 'echo `pwd` >> wd'
ExecStart = /usr/bin/git add --all .
ExecStart = /usr/bin/git commit -a -m "Automatic commit."


It seems that using %i or %I to set the working directory does not work. 
When I do systemctl --user start git-commit@/home/florian/timer.test.service 
the journal prints:

Aug 19 18:43:01 asaru systemd[375]: Starting Auto commit for instance....
Aug 19 18:43:01 asaru git[4761]: fatal: Not a git repository (or any of the 
parent directories): .git
Aug 19 18:43:01 asaru systemd[375]: git-commit at -home-florian-
timer.test.service: main process exited, code=exited, status=128/n/a
Aug 19 18:43:01 asaru systemd[375]: Failed to start Auto commit for 
instance..
Aug 19 18:43:01 asaru systemd[375]: Unit git-commit at -home-florian-
timer.test.service entered failed state.


and wd (created in ~) contains
-home-florian-timer.test
-home-florian-timer.test
/home/florian

Any ideas how I can change the working directory to the directory given by 
the instance name?
Thx!




More information about the systemd-devel mailing list