[systemd-devel] Using path name in instantiated units

Anthony Messina amessina at messinet.com
Tue Aug 19 13:24:39 PDT 2014


On Tuesday, August 19, 2014 07:34:46 PM Florian Lindner wrote:
> Any ideas how I can change the working directory to the directory given by 
> the instance name?

I do something like this to rebuild Jekyll sites based on a git commit. Maybe 
this will help you.

1. A path unit watches for changes to refs/heads/master

[Unit]
Description=Jekyll Static Website Builder Watch for %i
ConditionPathExists=/var/lib/git/%i.git/refs/heads/master

[Path]
PathModified=/var/lib/git/%i.git/refs/heads/master

[Install]
Alias=jekyll-build@%i.path
WantedBy=multi-user.target

2. If the path unit is triggered, the corresponding service unit starts

[Unit]
Description=Jekyll Static Website Builder for %i

[Service]
Type=oneshot
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7
ExecStart=/usr/sbin/jekyll-build %i
PrivateTmp=true

3. In my case, the Bash script it executes, dumps all of the sites into one 
directory, but you could easily change the script to dump them in various 
places, but you'd probably need to change the instantiated units to something 
like "jekyll-build at my-sub-path-here" and replace "-" with "/" in the Bash 
script itself.

#!/usr/bin/bash

dest="/var/www/${1}"
repo="/var/git/${1}.git"
scratch="$(mktemp --directory)"

git clone "$repo" "$scratch"
jekyll build --verbose --trace --source "$scratch" --destination "$dest"
rm -fr "$scratch"
exit 0

-- 
Anthony - https://messinet.com/ - https://messinet.com/~amessina/gallery
8F89 5E72 8DF0 BCF0 10BE 9967 92DC 35DC B001 4A4E
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20140819/15a9764b/attachment.sig>


More information about the systemd-devel mailing list