[systemd-devel] Using path name in instantiated units

Andrei Borzenkov arvidjaar at gmail.com
Tue Aug 19 19:21:41 PDT 2014


В Tue, 19 Aug 2014 22:54:04 +0200
Lennart Poettering <lennart at poettering.net> пишет:

> On Tue, 19.08.14 19:34, Florian Lindner (mailinglists at xgm.de) wrote:
> 
> > 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."
> 
> Use "%f" for unescaping paths.

Actually this will give incorrect result. If you call it
foo@/path/to/file, instance gets escaped into -path-to-file;
prepending "/" to unescaped instance results in //path/to/file. Not
fatal, but some programs may misinterpret initial "//".

%I works just fine here.



More information about the systemd-devel mailing list