You are not logged in.
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@.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 as 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@-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@-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!
Last edited by Osiris (2014-08-19 17:01:34)
Offline
This seems pretty good; unfortunately systemd replaces all slashes with '-' but that is by design. I think you'll need a minor wrapper to handle `chdir ${i/-/\/}`
Offline
I've brought that to the systemd mailing list and learned a lot. Indeed it's possible without a wrapper.
Offline
With the summary from the response on that post being; %I works fine
Offline
Well, I had some problems using %I with enabling timer units. I think the canonical way is using %f is properly escaped path, as outlined by Lennart. systemd-escape is not in the Repos yet though escaping could be done by hand easily.
Offline